Monitoring a Hot Tub or Pool with Azure Monitor and Azure Log Analytics – Part 2 – Azure Setup

Part 1 – Hardware and Software Setup || Part 2 – Azure Setup || Part 3 – Dashboarding and Workbooks || Part 4 – Alerting || Part 5 – Tips and Tricks

In Part 2, we are going to hookup the hot tub / pool sensors into Azure using Azure Monitor and Log Analytics

Create a Log Analytics Workspace in Azure.

If you don’t already have a MSDN account you can create a free trial account with a $200 credit at https://azure.microsoft.com/en-us/free

Once you have an Azure account go to http://portal.azure.com and click Create a resource

Search for “Log Analytics Workspace

Click Create

Under Create Log Analytics workspace. Type in the following

Resource group: HotTub-RG

Name: HotTubLA

Under Pricing tier leave the default Pay-as-you-go (Per GB 2018)

Click Review + Create and then click Create.

Once Deployment is Complete. Select Go to resource

In the Log Analytics workspace we need the Workspace ID and Primary Key. Click Agents management. Copy this information to notepad for use later.

Log into your Raspberry PI device with Powershell and SSh.

Go to home directory

cd /home/pi

Type in this command to install the git repository

git clone https://github.com/timmcfadden/HotTubMonitoring

change directory to HotTubMonitoring

cd HotTubMonitoring

open up HotTubAzureMonitor.py in nano

sudo nano HotTubAzureMonitor.py

Copy and paste your Workspace ID from Azure to the customer_id. Copy and paste your Primary key to shared_key

Control-x to Exit

Y to Save modified buffer and click enter

Now lets test the python code. Type in:

python3 /home/pi/HotTubMonitoring/HotTubAzureMonitor.py

If everything is setup correctly you should see the values from the sensors and Accepted

It can take 5-10 minutes for the data to initially show up in Log Analytics.

Go back to Azure and your Log Analytics workspace an verify the data is making it to Azure.

Click on Logs, Expand Custom Logs, and Double click on HotTub_CL and click Run

As you can see we have the data flowing in to Log Analytics.

Now lets setup our Raspberry Pi to run the Python code at startup and run it as a background task so it runs all the time.

Control + C to exit out of the running python code.

Type in

sudo nano /etc/rc.local

Add the following text to the beginning of the rc.local file.

python3 /home/pi/HotTubMonitoring/HotTubAzureMonitor.py &

It should look like this.

Exit out Control + x and Y and Enter to save

Now Reboot the Raspberry Pi

sudo reboot

After it reboots log back into the Raspberry Pi

Now type in

ps -ef

You should see the process in the list that looks like this. This process will run in a loop collecting data. If it ever stops for whatever reason you can simply reboot the device (even just pull the power) and it will start back up at startup.

exit out of the raspberry pi by typing

exit

Now lets setup some Dashboards in Azure so we can see the data anytime.

Monitoring a Hot Tub or Pool with Azure Monitor and Azure Log Analytics Part 3 – Dashboarding with Azure Monitor workbooks

No comments yet.

Leave a Reply