Enabling raw data storage
By default raw data storage is disabled (as it consumes disk space a lot).
When you enable it, every Blynk.virtualWrite command will be saved to
DB. You will need to install PostgreSQL Database (minimum required
version is 9.5) to enable this functionality:
1. Enabling raw data on server
Enable raw data in server.properties :
enable.db=true
enable.raw.db.data.store=true
2. Install PostgreSQL. Option A
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/
`lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - |
sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
2. Install PostgreSQL. Option B
sudo apt-get update
apt-get --no-install-recommends install postgresql-9.6 postgresql-
contrib-9.6
3. Download Blynk DB script
wget https://raw.githubusercontent.com/blynkkk/blynk-
server/master/server/core/src/main/resources/create_schema.sql
wget https://raw.githubusercontent.com/blynkkk/blynk-
server/master/server/core/src/main/resources/reporting_schema.sql
4. Move create_schema.sql and reporting_schema.sql to temp folder
(to avoid permission problems)
mv create_schema.sql /tmp
mv reporting_schema.sql /tmp
Result:
/tmp/create_schema.sql
/tmp/reporting_schema.sql
Copy it to clipboard from your console.
5. Connect to PostgreSQL
sudo su - postgres
psql
6. Create Blynk DB and Reporting DB, test user and tables
\i /tmp/create_schema.sql
\i /tmp/reporting_schema.sql
/tmp/create_schema.sql - is path from step 4.
You should see next output:
postgres=# \i /tmp/create_schema.sql
CREATE DATABASE
You are now connected to database "blynk" as user "postgres".
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE ROLE
GRANT
GRANT
Quit
\q
Now start your server and you should see next text in postgres.log file :
2017-03-02 16:17:18.367 - DB url :
jdbc:postgresql://localhost:5432/blynk?
tcpKeepAlive=true&socketTimeout=150
2017-03-02 16:17:18.367 - DB user : test
2017-03-02 16:17:18.367 - Connecting to DB...
2017-03-02 16:17:18.455 - Connected to database successfully.
WARNING: Raw data may consume your disk space very quickly!
CSV data format
Data format is:
value,timestamp,deviceId
For example:
10,1438022081332,0
Where 10 - value of pin. 1438022081332 - the difference, measured in
milliseconds, between the current time and midnight, January 1, 1970
UTC. To display the date/time in excel you may use formula:
=((COLUMN/(60*60*24)/1000+25569))
0 - device id