id872 / devmon

Saving and presenting device data from encrypted POST data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

devmon

Saving and presenting device data from encrypted POST data.

What is it and what is for?

It is a web application for saving and presenting sensors/devices readouts received from encrypted JSON request. You can see this project: https://github.com/id872/data_logger for more details. Decrypted devices data readouts are inserted into DB. Charts are generated with using Chart.js library.

See demo app.

The application works with data from the following devices:

This is personal project. It has been implemented mainly for tracking a performance of my solar installation. Another devices were added in a further implementation. Feel free to fork and improve according to your needs.

Summary, features, general info

The application has two main goals – Save devices data in the DB and present devices data in graphical form (with using the Chart.js library).

The application decrypts encrypted JSON POST data and inserts devices data into MySQL DB. Charts are generated from data stored in the DB. Application structure was divided into two sections:

  1. Sql – containing SQL Request class definition for SQL query execution and device data getters.
  2. Chartgenerators – here are generators for devices data presentation in graphical form. The device data is taken from SQL tables. Chart data is prepared as JSON format for Chart.js library.

There is no need to refresh page to change data scope or type. It works with AJAX requests.

To handle new device data for saving/presentation, following need to be done:

  • (DeviceDataSaver.php) insert function for new device data has to be created and used
  • (SQL DB) new device must be added into “devices” table, new device data type must be added into “dev_data_type” table, readouts table for new device must be created
  • (1) device data getter implementation
  • (2) chart data generator implementation

For sure there is a room for improvement to simplify it, but for now it has to be done in that way.

SQL DB is defined to handle many devices from many users. See the sql_create.sql in the sql_db. SQL DB configuration sql_db.ini is in the sql_db. It is used by SqlRequest.php.

“users” table contains api_hash used to determine api_key for data decryption for particular user. At the logger side (which prepares encrypted JSON request) need to be the same pair defined in a configuration, otherwise the devices data will not be decrypted and stored in DB – please see the device logger project for details. There is also user_password_hash (bcrypt hash) for additional authentication – required only for inserting data into DB. You can see an authentication steps in the add.php file. Check also .htaccess where rewrite engine rules were defined.

Devices names defined in a logger configuration must be the same as those defined in the DB.

Data presentation - examples

Solar data

Solar power production statistics

DS18B20 temperature sensor data

Xiaomi AirPurifier data

Tasmota Plug data

About

Saving and presenting device data from encrypted POST data

License:MIT License


Languages

Language:PHP 92.7%Language:JavaScript 6.0%Language:CSS 1.3%