IIoT edge development – Implementing HTTP connectivity

Editor's Note: The Industrial Internet of Things (IIoT) promises to provide deep insight into industrial operations and enhance efficiency of connected machines and systems. Large-scale IIoT applications rely on layered architectures to collect data from a broad range of sensors, move data reliably and securely to the cloud, and perform analysis required to deliver that insight and efficiency. In Industrial Internet Application Development, the authors provide a detailed examination of the IIoT architecture and discuss approaches for meeting the broad requirements associated with these systems. 

Adapted from Industrial Internet Application Development, by Alena Traukina, Jayant Thomas, Prashant Tyagi, Kishore Reddipalli.


Chapter 3. IIoT Edge Development (Continued)
By Alena Traukina, Jayant Thomas, Prashant Tyagi, Kishore Reddipalli

Application-level protocols – HTTP

In this section, we will try to build a simple IoT application for sending data from a DHT-12 temperature and humidity sensor to a receiver device, using a Raspberry Pi hub and the HTTP protocol:


Data flow from a DHT-12 sensor to a receiver

Offering a variety of usage options, HTTP is one of most popular protocols on the web. Every time you open a website or run a mobile application, it is most likely the HTTP protocol you are using.

In the following table, you can find a more detailed description of the protocol to understand whether it is suitable for your needs:

Key Value
Open source Yes
OSI layer Application
Data types Text, HTML, script, style, font, JSON, XML, stream, binary
Limitations Not suitable for large amounts of binary data
Possible operations Send/receive data
Latency Low
Usage On-demand requests
Security Yes
Compression Yes

For building the application, we will need the following.

Required software:

Required hardware:

  • Raspberry Pi 3 (model B) A power adapter (2A/5V)
  • A microSD card (8 GB+) and an SD adapter
  • A DHT-12 temperature and humidity sensor module A breadboard and a set of dupont cables
  • An Ethernet cable for a wired network connection


Assembling a device

Before building an application, you need to connect a DHT-12 sensor to a Raspberry Pi via a breadboard.

Preparing an SD card

To prepare an SD card, follow the sequence of actions as described:

  1. Download the latest Raspbian LITE image (available at https:// raspberrypi.org/downloads/raspbian/).
  2. Connect your SD card to a computer and use Etcher (https://io/) to flash the Raspbian .img file to the SD card.
  3. Enable SSH:
    cd /Volumes/boot
    touch ssh
  1. To enable Wi-Fi, create the conf file with the following content:

    network={
       ssid=”YOUR_SSID”
       psk=”YOUR_WIFI_PASSWORD”
    }

To create a file in a Linux console, you can use the GNU nano editor. It is pre-installed in most Linux distributives. All you need is to run the nano FILE_NAME command and follow the displayed instructions.
  1. Create the /home/pi/sensor folder
  2. Create the /home/pi/sensor/package.json file with the following content:
    {
       “name”: “sensor”,
       “version”: “1.0.0”,
       “description”: “”,
       “main”: “index.js”,
       “scripts”: {
          “start”: “node index.js”,
          “test”: “echo “Error: no test specified” && exit 1″
       },
       “author”: “”,
       “license”: “ISC”,
       “dependencies”: {
          “request”: “^2.81.0”,
          “rpi-dht-sensor”: “^0.1.1”
       }
    }
  1. Create the /home/pi/sensor/index.js file, replacing REMOTE-SERVER- ADDRESS.com with a real value. The file should contain the following:

    var rpiDhtSensor = require('rpi-dht-sensor');
    var request = require('request');
    var receiver = 'http://REMOTE-SERVER-ADDRESS.com:8080';
    var dht = new rpiDhtSensor.DHT11(2);
    function read () {
       var readout = dht.read();
       var data = {
          temperature: readout.temperature.toFixed(2),
          humidity: readout.humidity.toFixed(2)
       };
       console.log(data);
       data.device = 'raspberry';
       request.post({url: receiver, form: data}, function(err) {
          if(err) console.log('Failed to send to ' + receiver);
       });
       setTimeout(read, 1000);
    }
    read();

  1. Create the /home/pi/sensor/Dockerfile file with the following content:

    FROM hypriot/rpi-node:boron-onbuild

Running a sensor application on an RPi

To run a sensor application on an RPi, proceed as the following steps stipulate:

  1. Insert an SD card into the RPi.
  2. Connect an Ethernet cable and open an SSH connection.
  3. Navigate to /home/pi/sensor .
  4. Build an image and run a Docker container:

    # Build an image from a Dockerfile
    docker build -t http-sensor .
    #
    # Run container in foreground
    docker run –privileged -it –rm –name http-sensor-container http-sensor
    #
    # Run container in background
    # docker run –privileged -d  –rm –name http-sensor-container http-sensor
    #
    # Fetch the logs of a container
    # docker logs -f http-sensor-container
    #
    # Stop running container
    # docker stop http-sensor-container


Console output when a sensor app is running

Running a receiver application on a PC

To run a receiver app on a PC, follow this sequence:

  1. Create the receiver folder
  2. Create the ./receiver/package.json file with the following content:

    {
       “name”: “receiver”,
       “version”: “1.0.0”,
       “description”: “”,
       “main”: “index.js”,
       “scripts”: {
          “start”: “node index.js”,
          “test”: “echo “Error: no test specified” && exit 1″
       },
       “author”: “”,
       “license”: “ISC”
    }
  1. Create the ./receiver/index.js file with the following content:

    var http = require('http');
    var querystring = require('querystring');
    http.createServer(function (req, res) {
       req.on('data', function (chunk) {
          var data = querystring.parse(chunk.toString());
          console.log(data);
       });
       req.on('end', function () {
          res.writeHead(200, 'OK', {'Content-Type': 'text/html'});
          res.end('Data received.')
       });
    }).listen(8080);

  1. Create the ./receiver/Dockerfile file with the following content:

    FROM node:boron-onbuild EXPOSE 8080

  1. Navigate to ./receiver .
  2. Build an image and run a Docker container:

    # Build an image from a Dockerfile
    docker build -t http-receiver .

    # Run container in foreground
    docker run -p 8080:8080 -it –rm –name http-receiver-container http-receiver

    # Run container in background
    # docker run -p 8080:8080 -d  –rm –name http-receiver-container http-receiver

    # Fetch the logs of a container
    # docker logs -f http-sensor-container

    # Stop running container
    # docker stop http-receiver-container


Console output when a receiver application is running

Reprinted with permission from Packt Publishing. Copyright © 2018 Packt Publishing


About the authors

Alena Traukina is IoT practice Lead at Altoros. She has over 12 years of experience in delivery and support of business-critical software applications and is one of the first GE's Predix Influencers.

Jayant Thomas (JT) is the director of software engineering for the IoT apps for GE Digital. He is responsible for building IoT SaaS applications using the Predix platform, and specializes in building microservices-based architecture, reactive, event-driven systems.

Prashant Tyagi is responsible for enabling the big data strategy at GE Digital for the Industrial Internet that leverages IT and Operational data for predictive analytics. He works with all the P&L verticals (such as oil and gas, power generation, aviation, healthcare, and so on) to enable their IoT use cases on the data and analytics platform.

Kishore Reddipalli is a software technical director and expert in building IIoT big data and cloud computing platform and products at ultra scale. He is passionate in building software for analytics and machine learning to make it simplified for authoring the algorithms from inception to production at scale.

2 thoughts on “IIoT edge development – Implementing HTTP connectivity

  1. “I think that it will take a fair amount of time to make sure that we've refined the IIOT network properly. And security will be one of the biggest issues here. Considering that everything is travelling over a network, we're going to have to make sure th

    Log in to Reply
  2. “We can see rapid progress in the sector of IoT and now that it has expanded towards the industry of IIoT, we know for sure just how much of an improvement is bound to be made visible. This is the upgrade we need to give us the assurance that this sector i

    Log in to Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.