Monitoring Room Temperature with PowerShell IOT and Graylog
A few years ago my company was having issues with the air conditioning failing in our server room. We were dependent on our facilities department to inform us when this happened. I just happened to have a Raspberry Pi sitting on my desk, so I decided to use it to solve this problem. We had just started using Graylog as our log consolidation tool. So the project started there.
I chose TI’s TMP102 sensor because it was very cheap. I had originally hacked together a small python script. The script used another blog post for instructions on wiring and also had a code snippet for getting the temperature. I believe this was the blog post I used. I then used a GELF (the protocol used by Graylog to send logs) library to send the log data. After the script part of the project was finished, I added the temp to one of our dashboards in Graylog, then created alerts from there. I will write a post about using Graylog with PowerShell scripts later.
Fast forward a few years, the PowerShell team first released PowerShell 6 for Raspbian, then released the Microsoft PowerShell IOT module. When I saw this, I was itching to remove the only Python job/script running in our environment. Thus, the PowerShell module for the TMP102 sensor was created.
Prerequisites
- A Raspberry PI 2 or 3
- A TMP102 Sensor
- A way to wire the sensor
- A server that accepts GELF. Either a server running Graylog or Logstash
Getting Started
- Image Rasbian Stretch
- Install PowerShell 6
- Install PowerShell IOT
- Install PowerShell TMP102 Module
- Install PowerShell PSGELF Module ( or ‘Install-Module PSGELF’)
- Wire the sensor. I used this blog post to wire and test the sensor.
- Download the example script here
- Schedule the script to be ran with cron every X number of minutes.