Maker Pro
Ubidots

Build your own homemade brew monitor with a Hydrometer, Raspberry PI, and Ubidots

March 16, 2018 by Agustin Pelaez
Share
banner

Hydrometer gravity and temperature monitoring for home brewing in just minutes.

Hydrometer gravity and temperature monitoring for home brewing in just minutes.

There is another more intelligent, quicker, and more accurate way to keep an eye on your brews during their most crucial period: fermentation. Thanks to the Internet of Things and both commercial and DIY hydrometers, home brewers now have the tools to ensure premium quality with real-time condition monitoring such as temperature and gravity — alleviating the guesswork and constant tampering during the vital fermentation hours and days of your most coveted drinks.

Requirements

  • Raspberry Pi 3 Model (Already set up)
  • Hydrometer
  • Ubidots account

Application Step-up

  • Hardware/Firmware Setup
  • Publishing data to Ubidots
  • Running the package uninterruptedly.

Hardware/Firmware Setup

Hydrometer Setup

For this tutorial, we are utilizing the Tilt Hydrometer. To set up your Tilt device, see their official guide for complete to do for hardware setup. Once your hydrometer is reporting data to the TILT Hydrometer app, you will see something similar to this:

Raspberry Pi Setup

Note: If you have been working with your Raspberry Pi and have installed some packages, it is recommend to re-burn the image on the SD Card to avoid any issues when executing this tutorial. See this quick start guide for a quick overview to setting up your Raspberry Pi.

1. Access the Raspberry Pi remotely with SSH and the command below:

ssh pi@{RaspPi_IP_Address}

2. Then, enter the Raspberry Pi password. If you, have not ever changed the password, the default password is raspberry.

3. Next, install the node and npm to manage the needed packages. You should follow this guide by following the commands provided in node-and-npm-in-30-seconds.sh gist. The installation of these packages might take several minutes. Please be patient.

3. To verify if the node and npm was properly installed, execute the following commands in the Raspberry Pi terminal:

node -v
node -v

If done correctly, the Terminal's respond: 

4. Next, connect the TILT Hydrometer and the Raspberry Pi via BLE. To do this, you will need to compile and install Bluez, the Linux Bluetooth classic and low energy system for Raspberry Pi.

5. Finally, install the Node.js utility to read the TILT Hydrometer and send data to Ubidots by using the command below:

npm install -g tilt-send-data

Publishing data to Ubidots

To send data from the Raspberry Pi to the Ubidots and visualize the data through an IoT dashboard, we are going to use the Nodejs command line utility previously installed.

The command requires the following arguments to be able to handle data data with Ubidots:

-T --token [token] -> Ubidots TOKEN
-t --timeout [timeout] -> Interval timeout to send the request (in minutes)
$ tilt-send-data -T "{Ubidots_TOKEN}" -t {timeout_in_minutes}

Here is a real example:

$ tilt-send-data -T "BBFF-KvcUDRGARBkUDR5bogMVuKVcKigvsYAMvVVr9H278H2u2M34Kv" -t 1

The command shown above will send temperature, gravity, and RSSI values every minute. To check if the command is properly set up, the terminal response will be as follows: 

{ 
  rssi: [ { status_code: 201 } ],
  temperature: [ { status_code: 201 } ],
  gravity: [ { status_code: 201 } ] 
}

FAQs and Troubleshooting: if you get a warning message like "adapter state unauthorized", you can simply try running the command without permissions. Also, check out this guide or follow these steps in the "Running without root/sudo" for additional troubleshooting.

2. With your Ubidots account open, go to Device Management -> Devices. Here, you will see a new device named by default with the color and the ID of your Tilt Hydrometer. If required, you can change the device's name in Ubidots for simple identification. 


If you click the device, you will see the 3 variables the Raspberry Pi is sending to Ubidots (i.e. temperature, gravity, and RSSI).

3. [OPTIONAL] The BLE connection lets you retrieve other types of data from your device. If you want to add more variables to your applications such as proximity or accuracy, check out this guide.

To handle the properties you have to assign them in the command as arguments:

-m, --measuredPower [measuredPower] -> add measured power reading to the request
-a, --accuracy [accuracy] -> add accuracy reading to the request
-p, --proximity [proximity] -> add reading to the request

4. Use this command as an example for your code's set-up: 

$ tilt-send-data -T "{Ubidots_TOKEN}" -t {timeout_in_minutes} -m "{variable_label_mesuredPower}" -a "{variable_label_accuracy}" -p "{variable_label_proximity}"

Once you have assigned your Ubidots account Token, variables, and timeout, your command should look like this: 

$ tilt-send-data -T "BBFF-KvcUDRGARBkUDR5bogMVuKVcKigvsYAMvVVr9H278H2u2M34KvSne8R" -t 1 -m "mesuredPower" -a "accuracy" -p "proximity"
By executing the commands shown above, you will receive temperature, gravity, RSSI, accuracy, and proximity data every minute.

If everything is well done, you should receive the following server response:

{ temperature: [ { status_code: 201 } ],
  proximity: [ { status_code: 201 } ],
  gravity: [ { status_code: 201 } ],
  rssi: [ { status_code: 201 } ],
  mesuredpower: [ { status_code: 201 } ],
  accuracy: [ { status_code: 201 } ] }

5. You can check in your Ubidots account if the new device now doesn't have 3 but 6 variables. 

6. The assigned host by default is industrial.api.ubidots.com Ubidots accounts. If you have a Ubidots for Education account, you should use the host things.ubidots.com . To replace it, you should assign it as an argument:

-u, --url [url] -> post to specified url

3. How to run the package uninterruptedly

Follow the steps below to run your Raspberry PI Packages:

Write cd in the Raspberry Pi's terminal and save the package in this location: /home/pi/local/bin/tilt-send-data. You can also verify the exact location where you should locate the package by executing this command: 

which tilt-send-data

This is an example of a location response:

3. Now, in the .bashrc to assign the desired command, you can edit the file by adding the command shown below:  

nano .bashrc

Then, at the end of the file, add the following command by using your parameters:

{location_of_tilt-send-data} tilt-send-data -T "{Ubidots_TOKEN}" -t {timeout_in_minutes} -m "{variable_label_mesuredPower}" -a "{variable_label_accuracy}" -p "{variable_label_proximity}" &

This is an example of the command you should execute:

/home/pi/local/bin/tilt-send-data -T "BBFF-KvcUDRGARBkUDR5bogMVuKVcKigvsYAMvVVr9H278H2u2M34KvSne8R" -t 1 -m "mesuredPower" -a "accuracy" -p "proximity" &

4. Now, we need to reboot your Raspberry Pi and check your data in Ubidots.

To reboot the Raspberry Pi access the device as root. To do this, please execute the below commands: 

sudo su

And to reboot:

reboot

Wait for a minute and you should start seeing that your Ubidots account is receiving data from the Raspberry Pi every minute. Once your data is being fed to Ubidots you can enhance the data to become insights by developing value-adding visualizations and alerts to make your brews even better.

Wait for a minute and you should start seeing that your Ubidots account is receiving data from the Raspberry Pi every minute. Once your data is being fed to Ubidots you can enhance the data to become insights by developing value-adding visualizations and alerts to make your brews even better.

Results

Want to get more out of your IoT application? Check out these helpful articles for inspiration:

How to build an IoT application in a day

IoT Dashboards – Attributes, Advantages, & Examples

Related Content

Comments


You May Also Like