If you followed instructions on how to connect One Wire DS18B20 to Raspberry pi gpio then next step would be how to take temperature readings from DS18B20 One Wire digital temperature sensor and store these readings to MySQL/MariaDB database. As you may know that each DS18B20  One Wire digital temperature sensor has a unique 64-bit serial number wonderful part that we can have more then one DS18B20 One Wire digital temperature sensor connected to same 1-Wire bus.

Check out PiHome Shop for all you need for your Smart Heating and Wireless Temperature Sensors.

"<yoastmark

MySQL/MariaDB Table Structure

In order to record temperature from DS18B20 1-Wire digital temperature sensor to MySQL/MariaDB database we need database and then one table inside this database, Lets name our database pihome and then 2 x table,first one for records of all DS18B20 sensors list and second where we record all temperature readings. You can create blank database and then run following MySQL script to crate create both tables in pihome database. All table columns are self explained.

Nodes Table for DS18B20 Sensors

Message In Table for Temperature Readings

Python Script for DS18B20 1-Wire Sensor

Once MySQL/MariaDB database and table is ready we can simple create python that can take reading and store these readings to temp_reading table. You can create cron job for this python script to run every 5 minuts or any frequency you like just keep in mind that minimum limit for cron job is 1 minute. if you want to run anything less then one minute then you can create loop and let it run.

Ref: if you want to read more about DS18B20 1-Wire Sensor then you can check out this datasheet.