machielvisser / Climate_Measurement_Grid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Home climate analytics using multiple WeMos and Azure Notebooks

This solution is based on the solution of Dave Glover

The goal of this project is to measure the temperature and humidity in every room of my house and to analyse the data over time in relation to the intended temperature of the house. The expected results are:

  • Rooms where the temperature drops faster than average when the heater turns of -> isolation should be improved
  • Rooms where the temperature rises slower than average -> radiator configuation or placement could be improved

Device Platform

The ESP8266 is a great commodity priced Arduino compatible MCU with integrated WiFi

This project is implemented and tested on the following ESP8266 based development boards:

  1. NodeMCU V2 (also known as V1.0),
  2. WeMos D1 Mini
  3. and SparkFun ESP8266 Thing

Firmware

Arduino core for ESP8266 WiFi chip V2.3.0 firmware adds HTTPS (TLS 1.0 and 1.1) support, making this a viable platform for secure IoT data streaming. See Security Discussion for more information.

IoT Hub Certificate Verification

This sample verifies your IoT Hub Server Certificate to mitigate against Man in the Middle Attacks.

The Server Certificate Fingerprint was generated as follows:-

  1. From Bash on Ubuntu on Windows (10) or Linux
  2. echo -n | openssl s_client -connect IoTCampAU.azure-devices.net:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > cert.pem
  3. openssl x509 -noout -in cert.pem -fingerprint
  4. See Certificate Pinning article for more information

Azure IoT Hub

IoT Hub is designed to "Securely connect, monitor, and control millions of IoT assets" and is designed for internet scale data ingestion.

Stream Analytics, Power Bi and preconfigured IoT Hub solutions such as Remote monitoring provide ways to visualise and unlock the value of your data in Azure.

For more background information read this "Stream Analytics & Power BI: A real-time analytics dashboard for streaming data" article.

Setup and Deployment Summary

  1. Setup your Azure IoT Hub. There is a free 8000 message a day subscription to get started.
  2. Register your device with Azure IoT Hub.
  3. Update the main AzureClient.ino sketch
  4. Deploy the solution to your ESP8266 based device.
  5. View data with Device Explorer
  6. Optionally: Visualise your data in real time with Azure Stream Analytics and Power BI.

Setting Up Azure IoT Hub

Follow lab Setting Up Azure IoT to provision an Azure IoT Hub and an IoT Hub device.

Solution Configuration

Open the Config.h file in the solution and configure the following:

#define WIFI_SSID "[Your WiFi SSID]"
#define WIFI_PWD "[Your WiFi Password]"

#define NTP_SERVER "[Your prefered time server, 'pool.ntp.org' chooses a default, 'nl.pool.ntp.org' gives a server in the Netherlands]"

#define DEVICE_LOCATION "[Your device location - eg Garage]"

#define DEEP_SLEEP_IN_SECONDS 0
#define PUBLISH_RATE_IN_SECONDS 60

#define IOTHUB_CONNECTION_STRING "[Your IoT Hub/Central Connection String eg HostName=saas-iothub-897898-f33a-4002-a44a-7ca5961b00b6.azure-devices.net;DeviceId=wemos-garage;SharedAccessKey=uRsr78d56s87878dd89d675g88H8+nRoiVgc3+epqlMHHg="

Select Sensor

The sample includes the following sensors in the main project: Fake Sensor, BME280, and the Sht30. The default sensor returns fake temperature, humidity, pressure and light telemetry. To switch to a real sensor comment out the Sensor sensor line and uncomment one of real sensors.

#define BME280
// or
#define Sht30

There are additional drivers in the drivers directory: BMP180, BMP280, DHT11, DHT22, LDR, OLED.

Viewing Data

From Device Explorer, head to the Data tab, select your device, enable consumer group then click Monitor.

IoT Hub Data

Visualising Data

Azure Stream Analytics

Azure Stream Analytics enables you to gain real-time insights in to your device, sensor, infrastructure, and application data.

See the Visualizing IoT Data lab. Replace the query in that lab with the following and be sure to change the time zone to your local time zone offset. Australia (AEDST) is currently +11 hours.

SELECT
    iothub.connectiondeviceid deviceid,
    Geo AS GeoLocation,
    Max(DateAdd(Hour, 10, EventEnqueuedUtcTime)) AS TimeCreated, -- AU EST UTC + 10
    Avg(Celsius) AS Temperature,
    AVG(Humidity) AS Humidity,
    AVG(Light) AS Light,
    AVG(HPa) AS AirPressure
INTO
    [PowerBI]
FROM
    [TelemetryHUB] TIMESTAMP BY EventEnqueuedUtcTime
GROUP BY
    iothub.connectiondeviceid, Geo,
    TumblingWindow(minute, 30)

Power BI

Microsoft Power BI makes it easy to visualise, organize and better understand your data.

Follow the notes in the See the Visualizing IoT Data lab and modify the real time report as per this image.

Power BI Designer Setup

Power BI Designer Setup

Power BI Report Viewer

View on the web or with the Power BI apps available on iOS, Android and Windows.

Power BI Report Viewer

Data Schema

The AzureClient sketch streams data in the following JSON format, of course you can change this:)

{"Utc":"2017-01-12T08:00:38","Celsius":25.00,"Humidity":50.00,"hPa":1000,"Light":0,"Geo":"sydney","Schema":1,"Mem":21368,"Id":2}

ESP8266 Based Development Boards

There are a number of ESP8266 based development boards available so be sure to check out this great article "Comparison of ESP8266 NodeMCU development boards".

NodeMCU V2 with BMP180 Sensor

  1. NodeMCU v2
  2. BMP180 Barometric Pressure Sensor
  3. 1 x 400 Tie Point Interlocking Solderless Breadboard
  4. Wires

schematic

WeMos D1 Mini MCU

WeMos D1 Mini with BMP180 Sensor

  1. WeMos D1 Mini
  2. BMP180 Barometric Pressure Sensor
  3. 1 x Mini Breadboard
  4. Wires

WeMos D1 Mini BMP180

WeMos D1 Mini with BME280 Sensor

  1. WeMos D1 Mini
  2. BME280 Barometric Pressure Sensor
  3. 1 x Breadboard, Protoboard or PCB

WeMos D1 Mini BME280 Custom PCB

WeMos D1 Mini with DHT Shield Sensor

No wiring required, just solder the supplied header pins for the WeMos and the DHT Sensor shield.

  1. WeMos D1 Mini
  2. DHT Shield or the DHT Pro Shield.

WeMos D1 Mini

Software Requirements

Drivers

  1. NodeMCU - On Windows, Mac and Linux you will need to install the latest CP210x USB to UART Bridge VCP Drivers.
  2. WeMos - On Windows and Mac install the latest Ch340G drivers. No drivers required for Linux.
  3. ESP8266 Thing Development Board Hookup Guide

Arduino IDE

As at November Jan 2018 use:-

  1. Arduino IDE 1.8.7.
  2. ESP8266 Board Manager 2.3.0 for HTTPS/TLS Secure Client support.

Arduino Boards Manager ESP8266 Support

Arduino version 1.6.4 and above allows installation of third-party platform packages using Boards Manager.

  1. Install Arduino 1.8.7 from the Arduino website.
  2. Start Arduino and open Preferences window.
  3. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
  4. Open Boards Manager from Tools > Board menu and install esp8266 platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).
  5. Select NodeMCU or WeMos D1 Mini Board: Tools -> Board -> NodeMCU 1.0 (ESP-12E module) or WeMos D1 Mini
  6. Set Port and Upload Speed: Tools. Note, you may need to try different port speeds to successfully flash the device. Faster is better as each time you upload the code to your device you are re-flashing the complete ROM not just your code.

ESP8266 Arduino Core Documentation

Be sure to read the ESP8266 Arduino Core Documentation - there are some minor gotchas.