Log sensordata (BME280) directly to MySQL database
This is a proof-of-concept for logging sensor data directly to a database without the use of MQTT, PHP/Python, etc., but with the use of a direct TCP-connection to the MySQL database.
-
ESP8266 (D1 mini)
An ESP8266or ESP32 -
BME280 I2C
-
MySQL database
Any MySQL database. My database is a MariaDB 10 on a Synology with port 3307 linked to /run/mysqld/mysqld10.sock
I created a databasesensor
, a tableBME280
and an user with only 'Data' privileges for thesensor
database.
CREATE TABLE `BME280` (
`sensorid` int(11) DEFAULT NULL,
`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
`humidity` mediumint(6) NOT NULL,
`pressure` mediumint(6) NOT NULL,
`temperature` mediumint(6) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
Prepare the database
-
Connect a BME280 to an ESP8266 (D1 mini) using the standard I2C ports (D1=SCL, D2=SDA)
-
Upload the program
Please send any comments and suggestions.