This project uses an ultrasonic sensor and a Raspberry Pi Zero to send sensor data through Soracom's Cellular Cloud to Azure's Anomaly Detector API.
Azure's Anomaly detector let's us offload logic to the cloud. Increase battery life and reduce the hardware requirements
Using cellular connectivity instead of Wi-Fi or ethernet allows this IoT device to go where it otherwise would have no internet connectivity. Soracom gives us the cellular connection and also access to several services which will help us remotely manage our IoT device, and also help streamline our API call to Azure's Anomaly Detector API.
Let's get started!
- Raspberry Pi Zero
- Huawei 3G USB Modem and USB OTG adapter cable (MS2131i)
- Soracom Global IoT SIM Card
- 8GB+ Class 10 SD Card and Micro-SD Card Reader
- USB-A to Micro-USB Cable
- Ultrasonic range finder (HC-SR04)
- Perma-Proto Breadboard and Color-coded Wires
- Red LED
- 330 ohm Resistor
All of the hardware used for this project is available in Soracom's IoT Starter Kit with Raspberry Pi and IoT Sim.
And the tutorial for setting up the kit: Soracom IoT Starter Kit with Raspberry Pi
- Create Anomaly Detector. They currently offer a free pricing tier woo hoo!
Anomaly Detector API Reference
Make note of our key and endpoint, which is listed under the "Quick start" section of the resource.
-
Soracom Beam - HTTP to HTTP translation. Prevents us from having to store our API Key on the IoT device. Frees us up to change to endpoint in the future without having to make any changes on the device.
-
Soracom Napter - Quick remote access to device over cellular. SSH. Don't have to install anything on the IoT device.
Here's a quick 1 minute video on how to accomplish this: IoT Remote Access with SORACOM Napter
From within your SSH session to the Raspberry Pi, download a zip of this repository to the current directory:
wget https://github.com/RoyCodes/Water-Level-Detector/archive/master.zip
Then unzip master.zip. You should now have a folder called "Water-Level-Detector-Master" which includes all of the Python scripts in this repository.
unzip master.zip
Finally we'll clean up by deleting the .zip file, as we've already extracted the contents:
rm master.zip
From within the "Water-Level-Detector-Master" folder:
python ultrasonic_beam.py 60
Adding 60 to the end let's the script know to take a sensor reading every 60 seconds. This is because we've got our Azure Anomaly Detector API granularity set to "minutely".
Once the count of readings hits 12, it will beging sending the readings to Anomaly Detector.
Pull requests are welcome!