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

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.

< Previous
Page 2 of 2
Next >

Loading comments...