- src/python_parser
- Python Parser
- Gets data from CubeSensorsAPI, parses data to selected format and sends it to Event Hub or straight to database
- src/python_checker
- Check sensor status from database
- Trigger IFTTT actions
- src/CubeSensorsRestApi
- F# REST API (Suave)
- Gets data from database. Simple authentication.
- Azure
- Stream Analytics fetches data from Event Hub and sends it to SQL Server.
- Create ServiceBus
- Scale -> Basic
- Create Event Hub
1. Configure -> Shared access policies- cube_sender (Permissions: send)
- cube_receiver (Permissions: listen)
- Update sender private key to keys.py
- Create SQL Database
- Create database
- Create Stream Analytics
- Add input
* Event Hub Policy Name: cube_receiver - Add output
- Add query
- Create WebApp
- Scale -> Basic
- Configuration -> Always on
- Add Python script (data_parser) as a new Web Job
1. Add as a zip file. Pack whole module including env folder.
Sample files in sample_data folder.
Input: cubesensors-event-hub
Output: cubesensors-sql-data (SQL), cubesensors-alert-blob (BLOB)
WITH data_query AS (
SELECT
id AS sensorid,
[time] AS measurementtime,
temp AS temperature,
pressure,
humidity,
voc,
light,
noisedba AS noise,
battery,
cable,
voc_resistance AS vocresistance,
rssi
FROM
[cubesensors-event-hub]
)
-- Addl all data to database
SELECT * INTO [cubesensors-sql-data] FROM data_query
-- Add alert data when battery is running low and cube is not plugged in
SELECT sensorid, measurementtime, battery INTO [cubesensors-alert-blob]
FROM data_query
WHERE cable = false AND battery < 10
Database creation scripts are in .\src\database folder. Some configurations in the beginning of the create script are required by SQL Server LocalDB.
Start charging sensors automatically when battery level is down. IFTTT Maker channel is used to send messages to connected to smart plugs.
- Get latest measurement for each sensor from the db where it either requires charging or unplugging
- Requires charging if battery level under 15 and not plugged in. Start chargin only after 7PM (UTC).
- Unplug if battery level over 96 and plugged in
- Send on or off message to IFTTT with sensorId an action (_on or _off) as event
https://maker.ifttt.com/trigger/EVENT_NAME/with/key/API_KEY
e.g.
https://maker.ifttt.com/trigger/000D6F000449287A_on/with/key/copx80nTQbGdfsPEXptkdd8dN1KobKyZiBlZezpoRKDFSD

Leave a Reply