In this exploration session, S3 Innovate and Microsoft evaluate the feasibility of using an ESP8266 microcontroller-based IoT device gateway for remote monitoring of meeting rooms.

The ESP8266 is a microcontroller unit (MCU) manufactured by Espressif Systems with built-in Wi-Fi capabilities. Relatively low-cost with respect to computational capabilities, the ESP8266 MCU allows developers to build the device firmware using numerous SDKs and languages, notably the Arduino IDE.

In this session, we set up an IoT architecture loosely based on the Azure IoT Reference Architecture.


IoT Architecture Diagram


Key technologies used

Core team

  • Teo Say Leng – Founder, S3 Innovate
  • Nicholas Soon – Director, S3 Innovate
  • Hafiz Rohaidi – Lead Hardware Engineer, S3 Innovate
  • Tan Chun Siong – Senior Technical Evangelist, Microsoft

Customer profile

S3 Innovate, which recently completed the Microsoft BizSpark Plus program, is a Singapore-based startup with core competency around collecting and connecting building data from sensors to the cloud. S3 Innovate offers building owners an integrated view of their building health and operational efficiency, which helps them optimize the power consumption performance of buildings for greater environmental sustainability.

As a leading provider of green solutions in the market, S3 Innovate recently implemented a pilot solution for the Building and Construction Authority (BCA), connecting the chillers of their commercial buildings to the Microsoft cloud with the aim of maintaining chiller efficiency and preventing unnecessary waste of energy. When fully deployed across the island, this solution could help organizations reduce their energy consumption significantly, translating into tangible cost savings for organizations.

Problem statement

The granularity of S3 Innovate’s current sensor network is implemented at the meeting room level. In each room, the data collected includes telemetry such as motion, temperature, humidity, light luminosity, carbon monoxide, noise level, and volatile organic compounds. These parameters build up the fundamental blocks of data to evaluate the comfort and occupancy/usage of the meeting rooms.

Over time as the customer base and number of gateway devices grow, S3 Innovate is looking for ways to scale its ingestion pipeline to cater to this growth. Keeping capital cost low is the first area to address, because telemetry-collecting devices are an upfront investment cost. Optimization of storage costs is the second area to address.

While exploring new devices, services, and infrastructure strategy, S3 Innovate would like to further prove their system design, ensuring that the transition to data analytics projects in the near future will be as seamless as possible.

Core requirements for the device gateway:

  1. Ability to harden the system.
  2. Reduce maintenance needs.
  3. Resilient to data corruption.

Core requirements for historical telemetry data storage:

  1. Prepared in a state that is ready for ETL by popular data analytics systems.
  2. Relatively low in cost for long-term storage.
  3. Resilient to data corruption.

Here is the scope of exploration for this session with Microsoft and S3 Innovate:

  • Evaluate feasibility of NodeMCU (or compatible ESP8266-based gateway devices) for telemetry collection.
  • Demonstrate data ingestion based on best practices, optimizing for cost effectiveness, and preparation for future data analytics activities.
  • Mitigate the reliance on structured database resource use for historical data with Azure Blob storage.
  • Provision email alarms/alerts for telemetry values exceeding a specific threshold value.

“Keeping operational costs low and optimized is an important aspect of a business and should be a key part of the business’ organization strategy.” — Teo Say Leng, Founder, S3 Innovate


Solution and steps

After the deep-dive technical discussion with S3 Innovate, we understood that they are currently using an Azure Resource Manager-based device running RTOS (real time operating system) to send telemetry to a virtual machine with REST web services (hosted in the cloud or on-premises). The gateway device sends telemetry single-directionally to the endpoint only. We have proposed two areas for Microsoft and S3 Innovate to explore during this hackfest.

  1. Augment the existing infrastructure to use Azure Event Hubs or Azure IoT Hub for data ingestion instead of a REST endpoint running on a virtual machine.

    • Historical telemetry data will be stored on low-cost Azure Blob storage. If necessary, there is the option for Cool Storage. At the time of this writing, there is a preview feature called Azure Event Hubs Archive that can help you save telemetry directly into Blob storage in Avro format.
    • Data format in Blob will be stored in either CSV, JSON or Avro. Avro is preferred.
    • Stream Analytics will be used for threshold monitoring and streaming to a Power BI dashboard.

    The data ingestion will be using Azure Event Hubs, and Stream Analytics will be used for threshold monitoring and streaming to Power BI. Historical data will be stored in cost-effective Azure Blob storage in Hadoop Compatible format, and partitioned by year, month, and date to ensure compatibility with MapReduce parallel processing. We will be using a simple worker role to send triggers based on threshold to stakeholder via SendGrid email service.

  2. Choose to implement a version 2.0 of their hardware from the list below (non-exhaustive classification).

    • Linux/Windows-based, such as Avantech Devices, Intel Edison, or Raspberry Pi.
    • Microcontroller-based device with Wi-Fi capabilities such as NodeMCU, Arduino Yun, Arduino MKR1000, Arduino Zero, or Adafruit Feather.

    For a hardware device, the decision leans toward a microcontroller-based one with Wi-Fi capabilities, as it is a core operation efficiency to reduce the cost.

If you are exploring your set of devices, do take a look at Azure Certified for IoT device catalog - Preview for the compatibility list with Azure IoT Hub and Azure Event Hubs.

Architecture diagrams

IoT Architecture Diagram


Because S3 Innovate has existing services and a custom dashboard incorporated into their current implementation, this architecture is based on additional service that could be easily linked to their existing infrastructure. The key components and requirements are to demonstrate the capability to:

  • Send telemetry to Azure.
  • Prepare data for future data analytics.
  • Send out alerts for threshold monitoring.

The NodeMCU (ESP8266) device (on the left) has been programmed to send telemetry into an event hub. For Azure Event Hubs, it supports AMQP or HTTPS protocol for ingestion. Before sending, a signature needs to be generated in the HTTP POST header. The device requires current date and time from a UDP Time Server, SHA256, and Base64 string conversation to sign the authentication key before telemetry is sent to the event hub. This is likewise the case if you want to use Azure IoT Hub.

When first ingested into the event hub, the Azure Event Hubs Archive service will save the historical data into Azure Blob storage at a fixed time interval or file size threshold. These files are saved on Azure Blob storage in Avro format, and the folder structure is partitioned by /YYYY /MM /DD /HH /MIN. Such a partition storage strategy allows services such as Azure HDInsight (Microsoft’s Hadoop implementation) to easily load and perform MapReduce functionalities.

If you want to further reduce your costs or historical archiving of messages, the icons in white illustrate an additional data workflow. Stream Analytics would first average out telemetry values for a specific unit of time (for example, 60 seconds). Assuming telemetry is sent from the device gateway every second, the averaging of data would help to save diskspace up to a factor of 60, but at the cost of lossy granularity of data.

Two stream analytic services are used in this architecture. The first (lower) is purely to stream data into a Power BI dashboard, and the second is to filter out telemetry that exceeds a specific threshold value, and output these records into an event hub for “Alerts.” A Web Role will monitor the “Alerts” event hub for messages and send email via SendGrid to the respective stakeholders.

If you are wondering when to use Event Hubs vs. IoT Hub, refer to Comparison of Azure IoT Hub and Azure Event Hubs.

Wiring


The sensors used by S3 Innovate are currently powered by an 5V onboard power supply. In comparison, the NodeMCU provides both 5V (Vin pin) and 3.3V power supply, but accepts only 3.3V input. Hence, care needs to be taken when wiring by either using a logic level converter or a voltage divider to ensure 5V is safely stepped down to 3.3V for input reading. The previous diagram is a sketch of the actual prototype. A photo of the actual prototype is shown next. The sensors used include a CO gas sensor, a PIR motion sensor, a light dependent resistor, and a temperature probe.

Note that these are maker/consumer-grade sensors that are used for prototyping purposes. You might want to use commercial-grade sensors when rolling out for production purposes.

Actual Device


The previous photo shows an effort to maximize the use of space, soldering the devices onto a perma-board.

The plan is to manufacture their own PCB board to further maximize the use of space, and removal of USB and FTDI ports to harden it from a physical security point of view.

The Arduino sketch/source code for the board can be found in the Code artifacts section of this article.

Technical delivery and considerations

The requirement to send HTTPS/AMQP has a number of considerations. With powerful RTOS, this typically does not pose an issue. For microcontroller-based devices, the considerations (and additional security considerations) are as follows:

  • Capability of Wi-Fi and HTTPS protocol
  • List of cipher suites supported on the client (taking into consideration the support cipher suite on Azure IoT Hub and/or Event Hubs), and contingency plans in case the cipher suite gets updated on Azure to deprecated unsecure protocols
  • Ability to connect to WPA2 Wi-Fi hotspot
  • Ability to provision/configure Wi-Fi SSID, password, ingestion endpoint, and authentication key without re-flashing the firmware
  • Interval throughput between HTTPS post-messages
  • Number of GPIO pins and support for existing sensors
  • Ability to custom manufacture the PCB board to remove IO peripherals for hardening purposes
  • Ability to flash “final” when programming the microcontroller

Security details

Azure Event Hubs and Azure IoT Hub support popular telemetry ingestion protocols ranging from AMQP and MQTT to HTTPS. Following is the list of protocols supported by the specific services:

  • Azure IoT Hub: MQTT, AMQP, HTTPS
  • Azure Event Hubs: AMQP, HTTPS

You can find a more detailed comparison between these two services at Comparison of Azure IoT Hub and Azure Event Hubs.

For this exploration session, we will be sending telemetry via HTTPS to Azure Event Hubs using the NodeMCU board.

As of the 6th of December 2016, the supported cipher to POST the message to Azure Event Hubs’ HTTPS REST requires the following cipher suite (ranked by strength).

Azure does not publish the cipher suites on the documentation pages. Therefore, use SSL Labs to scan the Event Hubs and/or IoT Hub endpoints. Ensure that your IoT gateway devices support these cipher suites before deployment.

  1. TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
  2. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
  3. TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
  4. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
  5. TLS_RSA_WITH_AES_256_GCM_SHA384
  6. TLS_RSA_WITH_AES_128_GCM_SHA256
  7. TLS_RSA_WITH_AES_256_CBC_SHA256
  8. TLS_RSA_WITH_AES_128_CBC_SHA256
  9. TLS_RSA_WITH_AES_256_CBC_SHA
  10. TLS_RSA_WITH_AES_128_CBC_SHA
  11. TLS_RSA_WITH_3DES_EDE_CBC_SHA

If you are exploring the devices that are compatible with Azure IoT Hub/Azure Event Hubs, take a look at Azure Certified for IoT device catalog - Preview.

Device used

The NodeMCU is a microcontroller board based on the Expressif ESP8622 Wi-Fi SoC that allows developers to build their firmware using either Lua or C++. Read about NodeMCU on Wikipedia.

The sensors used in this exploration session include:

You might consider using a simple breadboard as an alternative to the Adafruit Permaboard when you are testing out your circuit. My choice of soldering on the perma-board is the ease of creating something relatively permanent, before creating your CAD file for PCB manufacturing.

When connecting via Wi-Fi, it is recommended to use the strongest security protocol supported. As of the 6th of December, 2016, the NodeMCU supports WEP, WPA, and WPA2.

Device messages sent

From our test, the NodeMCU can send an HTTPS POST message at a minimal interval of around 2-3 seconds. The payload is around 400-500 bytes per message. Depending on the business needs, the frequency will be reduced to 10 seconds (or more) per message.

The sample HTTPS POST Message looks like this

    POST https://s3innovatehackfest.servicebus.windows.net/eventhubdevices/messages HTTP/1.1
    Host: s3innovatehackfest.servicebus.windows.net 
    Authorization: SharedAccessSignature sr=https%3A%2F%2Fs3innovatehackfest.servicebus.windows.net%2Feventhubdevices%2Fmessages&sig=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%3D&se=1737504000&skn=xxxxx 
    Content-Type: application/atom+xml;type=entry;charset=utf-8 
    Content-Length: 139


    {"Dev":"sender","Utc":"2016-11-25T06:45:04","Celsius":24.75,"Lux":886,"Motion":0,"Gas":0,"Geo":"MS SG MIC","WiFi":1,"Mem":19016,"Id":1}


SDKs and languages used

The language and IDE used on Device Firmware development is Arduino IDE 1.6.5 and C++, and is based on Dave Grove’s Securely stream data from ESP8266 MCUs to Azure IoT Hub over HTTPS/REST GitHub project. This project has been forked and slightly modified to use Azure Event Hubs and the above sensors.

Refer to this guide to learn how to install Arduino IDE and the support for NodeMCU.

For the notification of threshold, we will be using a web role sample written using .NET. You will need Visual Studio for this project.

Code artifacts

Learnings from the Microsoft and S3 Innovate teams

Troubleshooting of hardware is a useful skill during a hackfest. It is good to understand:

During the hackfest we encountered some eccentric readings from the sensors, which were quickly diagnosed as a dry solder joint and resolved easily.

For production, testing is needed to determine real-life operating environments. This includes:

  • The expected lifespan of the device in a production environment, when exposed to extreme temperature and humidity.
  • Interferences from other components, and their effects on the device.
  • The Wi-Fi connectivity strength and acceptable range for a stable connection.
  • Case studies, best practices from other devices using the ESP8266 sold in the market.
  • Certification to ensure compliance with local laws.

Fabrication of PCB is a key process because the cost of designing and ease of manufacturing is at an all-time low. Knowledge of PCB design via EagleCAD or other software is an essential skill. Some companies (non-exhaustive) that allow online ordering via EagleCAD file are:

Conclusion

We see many IoT devices on the market today, ranging from popular branded devices to up-and-coming underdog brand names. The constant experimenting and tinkering with these new devices is part of the maker’s mentality that drives the IoT projects in the real-world environment. Nevertheless, it takes the early adopter or innovator’s mindset to implement these devices way before they are tested and proven in the field.

There are risks involved in adopting new technologies, which can be lessened if mitigated properly, implementing additional layers of control.

Measurable impact and benefits resulting from the implementation of the solution

  • The current device gateway alone cost over $100 per node. This hackfest demonstrated the feasibility of a low-cost gateway $10 device (NodeMCU V1.0 based on ESP8266) as an alternative.
  • Because there is less dependency on a structured SQL Server for cool/history data that is rarely accessed, the CPU cycles and RAM use are more efficiently used for data queries in the past 12 months.

General lessons

  • Periodical exploration of new IoT devices can often be a fruitful experience as devices get smaller and increasingly affordable.
  • For remote monitoring projects, the storage strategy is important for managing the initial operational cost. Data analytics typically require months and even years of historical data before qualitative analysis can be churned out from these raw telemetry data.

Next steps

The current prototype needs further work to be production- and deployment-ready. A way to move forward would be to start designing and creating a custom manufactured PCB board for testing in a real environment.

Additional resources

If you want to learn more about the capabilities of NodeMCU-based devices, see these resources: