Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial Internet of Things >> Internet of Things Technology

Enhancing IIoT Edge Development with WebSockets: Secure, Real‑Time Connectivity

Enhancing IIoT Edge Development with WebSockets: Secure, Real‑Time 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 – WebSocket

In this section, we will try to build a simple IoT app for sending data from an XD-80 light sensor module to a receiver device, using a Raspberry Pi hub and the WebSocket protocol:

Enhancing IIoT Edge Development with WebSockets: Secure, Real‑Time Connectivity
Data flow from an XD-80 sensor to a receiver device

WebSocket is most widely used in the case that one needs to enable fast transfer of real-time data. The protocol allows for two-way interaction between a client and a server, and for streaming multiple messages using the same TCP connection, which lowers the communications overhead.

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 The OSI layer Application Data types String Limitations Not suitable for large amounts of binary data Possible operations Send/receive data Latency Very low Usage Real-time communication Security Yes Compression Yes

Table 3: WebSocket protocol specifications

For building the application, we will need the following.

Required software:

Required hardware:


Assembling a device

Before building an application, you need to connect an XD-80 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 using the following command:


      cd /Volumes/boot
      touch ssh

  1. To enable Wi-Fi, create conf with the following content:


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

Enhancing IIoT Edge Development with WebSockets: Secure, Real‑Time Connectivity 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
  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”: { “rpio”: “^0.9.16”,
         “ws”: “^2.3.1”
      }
   }

  1. Create the /home/pi/sensor/index.js file with the following content, replacing REMOTE-SERVER-ADDRESS.com with a real value:


      var WebSocket = require('ws');
      var rpio = require('rpio');
   
      var ws;
      var receiver = 'ws://REMOTE-SERVER-ADDRESS.com:8080';
      rpio.open(11, rpio.INPUT);
   
      var establishConnection = function () {
         ws = new WebSocket(receiver);
         ws.on('close', establishConnection);
         ws.on('error', establishConnection);
      };
      establishConnection();
   
      var sendStatus = function () {
         var status = rpio.read(11) === 0;
         console.log('light status: ' + status);
         var data = JSON.stringify({
            device: 'raspberry',
            timestamp: Date.now(),
            light: status
         });
   
         try { ws.send(data); }
         catch (e) {console.log('failed to send data to ' + receiver);}
   
         setTimeout(sendStatus, 1000);
      };
      sendStatus();

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


      FROM hypriot/rpi-node:boron-onbuild


Internet of Things Technology

  1. DocBox CEO on Building Data‑Centric, Interoperable Healthcare IoT Solutions
  2. IoT Edge Computing: Bridging Devices and Cloud for Real‑Time Insights
  3. Prototyping IIoT Edge Devices: A Practical Guide
  4. Implementing HTTP Connectivity for IIoT Edge Devices: A Raspberry Pi DHT-12 Tutorial
  5. IIoT Edge Development with Modbus: Building a Secure Sensor Data Flow on Raspberry Pi
  6. Leveraging OPC UA for Robust IIoT Edge Development
  7. Step‑by‑Step Guide: Extracting PLC Data with IIoT for Real‑Time Insights
  8. Future Outlook: Advancing Industrial IoT for Production Excellence
  9. Revolutionizing MRO with Voice-Enabled IIoT
  10. Unlocking Actionable Edge Insights with AI & ML