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:

  1. Index.php – collects data
  2. getRows.php – lists data from the database
  3. getLast.php – gets the last temperature entered in the database

There are also two prerequisites:

  1. A pre-shared .pem key on the server.  This should match the one on the Raspberry Pi.
  2. 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.