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

Implementing HTTP Connectivity for IIoT Edge Devices: A Raspberry Pi DHT-12 Tutorial

Implementing HTTP Connectivity for IIoT Edge Devices: A Raspberry Pi DHT-12 Tutorial Editor’s Note: The Industrial Internet of Things (IIoT) delivers deep insight into industrial operations, boosting the efficiency of connected machines and systems. Large‑scale IIoT solutions rely on layered architectures to collect data from diverse sensors, transport it securely to the cloud, and execute the analytics that turn raw data into actionable intelligence. In Industrial Internet Application Development, the authors dissect the IIoT architecture and outline strategies to satisfy these demanding requirements.

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

Below is a hands‑on example that demonstrates how to transmit data from a DHT‑12 temperature and humidity sensor to a remote server using a Raspberry Pi hub and the HTTP protocol.

Implementing HTTP Connectivity for IIoT Edge Devices: A Raspberry Pi DHT-12 Tutorial
Data flow from a DHT‑12 sensor to a receiver

HTTP remains the most widely adopted protocol on the web, underpinning virtually every website and mobile application you use. The table below summarizes its key characteristics to help you determine if it fits your IIoT scenario.

KeyValue
Open sourceYes
OSI layerApplication
Data typesText, HTML, script, style, font, JSON, XML, stream, binary
LimitationsNot suitable for large binary payloads
Possible operationsSend/receive data
LatencyLow
UsageOn‑demand requests
SecurityYes (TLS/SSL)
CompressionYes (e.g., gzip)

To build the example application you’ll need the following software and hardware components.

Required software:

Required hardware:

Assembling the Device

Connect the DHT‑12 sensor to the Raspberry Pi using a breadboard, following the wiring diagram below.

Preparing an SD Card

  1. Download the latest Raspbian Lite image from Raspberry Pi OS.
  2. Insert the SD card into your computer and flash the image with Etcher (https://www.balena.io/etcher/).
  3. Enable SSH by creating an empty file named ssh in the /boot partition:
    cd /Volumes/boot
    touch ssh
  4. To enable Wi‑Fi, create wpa_supplicant.conf in /boot with the following content:
    network={
        ssid="YOUR_SSID"
        psk="YOUR_WIFI_PASSWORD"
    }
  5. Insert the SD card back into the Raspberry Pi and power it on.

After the Pi boots, you can log in via SSH (default credentials: pi/raspberry) and start configuring the sensor application.

Setting Up the Node.js Project

  1. Create a project directory:
    mkdir -p ~/sensor
  2. In ~/sensor/package.json, add the following configuration:
    {
      "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"
      }
    }
  3. In ~/sensor/index.js, paste the following code, replacing REMOTE-SERVER-ADDRESS.com with your server’s URL:
    var rpiDhtSensor = require('rpi-dht-sensor');
    var request = require('request');
    var receiver = 'https://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();
  4. Optional: create a Dockerfile for containerized deployment:
    FROM hypriot/rpi-node:boron-onbuild

Run npm install in the project directory, then start the application with npm start. The sensor will begin sending temperature and humidity readings to the specified HTTP endpoint every second.

For a complete end‑to‑end solution—including cloud ingestion, analytics, and dashboards—refer to the broader IIoT architecture guidelines in the original text.

Internet of Things Technology

  1. Industrial‑Grade Connectivity Architecture for the IoT
  2. IoT Edge Computing: Bridging Devices and Cloud for Real‑Time Insights
  3. Connectivity by Design: Unlocking Unified Data for Digital Twins and Real‑Time Decision‑Making
  4. Prototyping IIoT Edge Devices: A Practical Guide
  5. Enhancing IIoT Edge Development with WebSockets: Secure, Real‑Time Connectivity
  6. IIoT Edge Development with Modbus: Building a Secure Sensor Data Flow on Raspberry Pi
  7. Leveraging OPC UA for Robust IIoT Edge Development
  8. IXrouter: Seamless Edge‑to‑Cloud Connectivity for Industrial IoT
  9. 3 Keys to Successful Industrial IoT Deployment
  10. Future Outlook: Advancing Industrial IoT for Production Excellence