cubesensors-iot-azure

CubeSensors IoT Azure

  • 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.

Diagram

Azure Deployment

  1. Create ServiceBus
  2. Scale -> Basic
  3. Create Event Hub
    1. Configure -> Shared access policies

    • cube_sender (Permissions: send)
    • cube_receiver (Permissions: listen)
    • Update sender private key to keys.py
  4. Create SQL Database
  5. Create database
  6. Create Stream Analytics
  7. Add input
    * Event Hub Policy Name: cube_receiver
  8. Add output
  9. Add query
  10. Create WebApp
  11. Scale -> Basic
  12. Configuration -> Always on
  13. Add Python script (data_parser) as a new Web Job
    1. Add as a zip file. Pack whole module including env folder.

JSON

Sample files in sample_data folder.

Stream Analytics Query

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

Database creation scripts are in .\src\database folder. Some configurations in the beginning of the create script are required by SQL Server LocalDB.

IFTTT

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

Visit original content creator repository

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *