Culture / Edge / IoT

Tutorial: Prototyping a Sensor Node and IoT Gateway with Arduino and Raspberry Pi – Part 1

3 Jul 2015 9:22am, by

Part one of a two-part tutorial about using an open source software stack to aggregate, store and visualize sensor data in real-time for industrial environments. In part two, we will wire up the sensors and radios to configure an Arduino and Raspberry Pi.

Industrial IoT requires a robust infrastructure comprised of sensor nodes, energy-efficient communication networks, and gateways that connect to the Internet and cloud. The datasets generated by the sensors pass through many phases before becoming valuable for businesses. This article introduces the concept of sensor nodes, low-power networks, and IoT Gateways used in industrial scenarios. We will use Arduino, XBee, Raspberry Pi 2 and open source software for prototyping an end-to-end solution.

The latest Raspberry Pi 2 packs a lot more punch than its predecessor. Powered by a 900 MHz quad-core ARM Cortex-A7 processor and 1GB RAM, Raspberry Pi 2 Model B can be used for a variety of scenarios. We will use an open source software stack to aggregate, store and visualize sensor data in real-time.

What is an IoT Gateway?

In an industrial IoT scenario, there are many sensors and actuators that interact with the machinery. Each machine would typically have multiple sensors tracking its health and monitoring the key parameters related to the production. Each sensor and actuator is attached to a microcontroller that is responsible for acquiring the data or controlling a switch through a pre-defined instruction set. The microcontroller — along with the sensors, power and a radio — is called a sensor node. It is a self-contained, deployable unit that captures the data generated by sensors. The sensor node doesn’t have enough processing power, memory, and storage to deal with the data locally. It uses a low-energy radio communication network to send the data to a central location. The communication link between the sensors’ nodes and the central hub is based on ZigBee, Bluetooth Low Energy (BLE), or Power over Ethernet (PoE). The hub that acts as an aggregator of multiple raw datasets generated by the sensor nodes is called an IoT gateway.

An IoT gateway has multiple roles to play. One of the first jobs of the gateway is to transform and normalize the data. The datasets generated by the sensor nodes will be in disparate formats. Some of the legacy nodes use proprietary protocols, while the contemporary ones may rely on JSON or CSV. The gateway acquires heterogenous datasets from multiple sensor nodes and converts them to a standard format that is understood by the next stage of the data processing pipeline.

The second role of an IoT gateway is protocol transformation. Since the sensor nodes cannot use power hungry Wi-Fi or ethernet, they use low-powered communication networks. A gateway supports multiple communication protocols for accepting the inbound data sent by the sensor nodes. It uses a variety of protocols for the outbound communication, which typically connects the gateway to a process running in the cloud. Some of the popular outbound protocols used in the context of IoT are REST, MQTT, CoAP, STOMP and even SMS. In some scenarios, the gateway may also process the data and raise alerts in real time. But this is best left to the powerful stream processing pipelines running in the cloud.

The diagram below represents the deployment architecture of an IoT gateway.

Gateway

Gateways act as an edge device, obscuring the sensor nodes from the public internet. Though the sensor nodes can make outbound connections to the internet and cloud through the gateway, they cannot be accessed directly. Thus, gateways play the dual role of routers and firewall securing the sensor nodes and internal network.

Sensor nodes that are capable of connecting to the Internet still need a gateway for data aggregation and transformation. They connect to an appliance running in the cloud called a cloud gateway. The local edge device running on-premises is often referred to as a field gateway.

Node_Gateway

Arduino as a the Sensor Node and Raspberry Pi as the Gateway

Since the objective of this tutorial is to build a working prototype, we will keep the sensor node configuration simple. We will use an inexpensive DHT22 sensor that captures the ambient humidity and temperature and sends it to the gateway.

We use the following components:

Sensor Node

  • Arduino Uno R3
  • DHT 22 humidity / temperature sensor
  • XBee breakout board
  • XBee series 2

IoT Gateway

  • Raspberry Pi 2
  • XBee series 2
  • Wi-Fi Dongle

Arduino_Raspberry_Arch

A Short Introduction to XBee

XBee modules make it easy to create a wireless point-to-point or mesh network. They are configured with the standard AT commands. With built-in error correction, XBee modules offer a reliable wireless link. They come in multiple flavors, with support for protocols like ZigBee, Bluetooth, and even Wi-Fi. The XBee modules can be configured to operate either in a transparent data mode or in application programming interface (API) mode.

In the transparent mode, data coming into the Data IN (DIN) pin is directly transmitted over-the-air to the intended receiving radios without any modification. This feature is what makes XBee a drop-in replacement for an RS–232 cable. Incoming packets can either be directly addressed to one target (point-to-point) or broadcast to multiple targets (star). We will use XBees configured in transparent mode for connecting the sensor node to the gateway.

ZigBee is a specification for a high-level communication protocol mainly used for personal area networking based on small, low-power digital radios. ZigBee is based on an IEEE 802.15.4 standard. Its low power consumption confines the transmission range from 10 to 100 meters line-of-sight, depending on power output and environmental characteristics. ZigBee devices are capable of transmitting data over long distances by passing through a mesh network of intermediate devices to reach more distant ones.

ZigBee is typically used in low data rate applications that require long battery life and secure networking. ZigBee networks are secured by 128-bit symmetric encryption keys. Some of the use cases of ZigBee include wireless light switches, electrical meters with in-home-displays, traffic management systems, and other consumer and industrial equipment that requires short-range, low-rate wireless data transfer.

The technology defined by the ZigBee specification is intended to be simpler and less expensive than other wireless personal area networks (WPANs), such as Bluetooth or Wi-Fi. Philips Hue bulbs use ZigBee as the communication protocol between the hub and the lightbulbs. We will use ZigBee as the radio link between the sensor node and the IoT gateway.

The XBee radio connected to the sensor node will act as a router, while the one connected to the gateway will act as the coordinator. Multiple routers can talk to the coordinator. For advanced scenarios, it is recommended to use XBee in API configuration mode. For a detailed walkthrough of configuring the XBee radio modules in the router mode and coordinator mode, please refer to an excellent tutorial by SparkFun.

Feature image: “IMG_7890” by kamone is licensed under CC BY-SA 2.0.

A newsletter digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.