Raspberry Pi Fermentation Temp Controller III: Server APIs
This is the optional part of the Raspberry Pi Fermentation Controller, but it’s the part that I used to roll into the Brewery IoT page.
There are three PHP scripts that run on the server:
- Index.php – collects data
- getRows.php – lists data from the database
- getLast.php – gets the last temperature entered in the database
There are also two prerequisites:
- A pre-shared .pem key on the server. This should match the one on the Raspberry Pi.
- A MySQL table (I’ve called it FermChamber, but if you know SQL, you can change it) with two columns: TimeStamp (datetime) and Temp (float).
With that out of the way…
Index.php – Data Collection
The data collection script is below. It expects post form data with a JSON formatted file. If you’ve followed the first post in this series, you’re good.
Note that you will need to change the code to use your correct server, username, password, and database.
getRows.php – List of Data (for the bar graph)
This script gets the temperatures in the database for the line chart.
getLast.php – Get Last Temperature Reading
This is just a simple script to get the last temperature in the database. This is for display on the dial gauge.
One of the next parts in this will be the code to display on the page.
Cheers!