Advertisement

IIoT edge development - Implementing HTTP connectivity

Alena Traukina, Jayant Thomas, Prashant Tyagi, Kishore Reddipalli

January 02, 2019

Alena Traukina, Jayant Thomas, Prashant Tyagi, Kishore ReddipalliJanuary 02, 2019

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. 

This excerpt, Chapter 3 from the book, describes how developers can build prototype devices able to to collect and communicate data to higher level applications. Part 1 introduced IIoT edge development with a description of the key components of a typical IIoT edge system. This installment describes how developers can implement HTTP connectivity in an edge device based on a Raspberry Pi.

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

Continue reading on the next page, Running a sensor application on an RPi >>

 

 

< Previous
Page 1 of 2
Next >

Loading comments...