Skip to content
Learni
View all tutorials
IoT

How to Build an Industrial IoT Prototype in 2026

Lire en français

Introduction

Industrial IoT (IIoT) is revolutionizing Industry 4.0 by connecting machines, sensors, and systems for predictive maintenance, process optimization, and real-time traceability. Unlike consumer IoT, IIoT prioritizes reliability, security, and industrial protocols like MQTT or OPC-UA.

This beginner tutorial guides you through creating a complete IIoT prototype on Raspberry Pi: an MQTT broker simulates a factory network, a Python script emulates an industrial sensor (machine temperature and humidity), a receiver displays the data, and Node-RED provides a visual dashboard.

Why this project? It demonstrates typical edge-to-cloud data flows in factories, scalable to real PLCs. In 2026, with the rise of embedded AI, mastering IIoT is essential for engineers. Duration: 30-45 min. Result: an operational MQTT pub/sub system, ready to bookmark for your professional projects. (128 words)

Prerequisites

  • Raspberry Pi 4 or 5 with Raspberry Pi OS (64-bit) installed and updated.
  • SSH access or direct terminal (user pi, default password raspberry).
  • Basic Linux and Python knowledge (no prior IIoT experience required).
  • Internet connection for installations.
  • Ports 1883 (MQTT) and 1880 (Node-RED) open if using a firewall.

Update the System

terminal
sudo apt update && sudo apt upgrade -y
sudo apt install python3-pip git -y
sudo reboot

This command updates all Raspberry Pi OS packages, installs pip for Python, and reboots to apply changes. Avoid interruptions by running over a stable SSH connection; the reboot ensures a clean base for IIoT dependencies.

Install the MQTT Broker Mosquitto

terminal
sudo apt update
sudo apt install mosquitto mosquitto-clients -y
sudo systemctl enable mosquitto
sudo systemctl start mosquitto
mosquitto_pub -h localhost -t test -m "Hello IIoT"

Installs Mosquitto (lightweight MQTT broker, IIoT standard), enables it at boot, and starts the service. The mosquitto_pub test verifies port 1883. Pitfall: if 'address already in use' error, check sudo netstat -tuln | grep 1883 and kill if needed.

Configure Mosquitto for IIoT

/etc/mosquitto/mosquitto.conf
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
listener 1883
allow_anonymous true
max_queued_messages 1000
message_size_limit 0
max_inflight_messages 20
upgrade_outgoing_qos 0

Copy this content into /etc/mosquitto/mosquitto.conf (back up the original), then sudo systemctl restart mosquitto. Enables persistence for IIoT QoS (industrial reliability), logs for debugging, and limits for high-volume sensor data. Pitfall: allow_anonymous true is for prototypes; secure production with ACL/users.

Python Script: Industrial Sensor Publisher

sensor_publisher.py
import paho.mqtt.client as mqtt
import time
import random
import json

client = mqtt.Client(client_id="industrial_sensor_1", clean_session=False)
client.connect("localhost", 1883, 60)
client.loop_start()

print("Capteur IIoT démarré. Publie sur 'iiot/sensor1'.")

while True:
    temp = round(random.uniform(20.0, 80.0), 2)
    hum = round(random.uniform(30.0, 90.0), 2)
    payload = {
        "device_id": "machine_42",
        "temperature": temp,
        "humidity": hum,
        "timestamp": time.time(),
        "status": "nominal" if temp < 70 else "alerte"
    }
    client.publish("iiot/sensor1", json.dumps(payload), qos=1)
    print(f"Publié: {payload}")
    time.sleep(5)

client.loop_stop()
client.disconnect()

First install pip3 install paho-mqtt. This script simulates an industrial sensor (factory machine), publishing QoS=1 JSON to topic 'iiot/sensor1'. clean_session=False enables IIoT persistence. Run with python3 sensor_publisher.py. Pitfall: it's blocking; use nohup or systemd for production.

Python Script: Receiver and Console Dashboard

dashboard_subscriber.py
import paho.mqtt.client as mqtt
import json

latest_data = {}

def on_connect(client, userdata, flags, rc):
    print(f"Connecté au broker (code: {rc})")
    client.subscribe("iiot/sensor1", qos=1)

def on_message(client, userdata, msg):
    global latest_data
    data = json.loads(msg.payload.decode())
    latest_data = data
    status = "🟢 Nominal" if data["status"] == "nominal" else "🔴 Alerte"
    print(f"[{data['timestamp']}] {data['device_id']}: Temp={data['temperature']}°C, Hum={data['humidity']}% {status}")

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost", 1883, 60)
client.loop_forever()

Subscribe to the topic to receive and display data in real time. Callbacks handle connect/message events. Run in another terminal: python3 dashboard_subscriber.py. Perfect for IIoT console monitoring. Pitfall: loop_forever() is blocking; use multithreading for advanced UIs.

Install and Start Node-RED

terminal
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
node-red-start &
sleep 10
curl -X POST http://localhost:1880/api/v2/flows -H 'Content-Type: application/json' -d @flow.json || echo 'Importez manuellement via UI'

Installs Node-RED (low-code IIoT tool) and starts it in the background. Access at http://:1880. The curl imports a flow (see next step). Pitfall: Node.js required; if port conflict, run node-red-stop then restart.

Node-RED Flow for Visual Dashboard

flow.json
[{"id":"flow1","label":"IIoT Dashboard","nodes":[{"id":"mqtt_in","type":"mqtt in","name":"Capteur IIoT","topic":"iiot/sensor1","broker":"mqtt_broker","x":160,"y":100,"wires":[["gauge_temp","gauge_hum","debug"]]},{"id":"mqtt_broker","type":"mqtt-broker","name":"Local MQTT","broker":"localhost","port":"1883","clientid":"nodered_iiot","x":160,"y":200,"wires":[]},{"id":"gauge_temp","type":"ui_gauge","group":"default","name":"Température","label":"°C","format":"{{value}}","min":"0","max":"100","x":380,"y":60,"wires":[]},{"id":"gauge_hum","type":"ui_gauge","group":"default","name":"Humidité","label":"%","format":"{{value}}","min":"0","max":"100","x":380,"y":140,"wires":[]},{"id":"debug","type":"debug","name":"Données JSON","active":true,"x":380,"y":220,"wires":[]}],"configs":[]}]

Full JSON export of a Node-RED flow: MQTT in → UI gauges + debug. Import via UI (burger menu → Import) or previous curl. View dashboard at /ui. Add ui_base if needed. Pitfall: broker not predefined; deploy after import.

Best Practices

  • Secure MQTT: Switch to TLS/ACL in production (allow_anonymous false, CA certificates).
  • QoS and Retries: Use QoS=2 for high-criticality (IIoT safety).
  • Edge Computing: Process data locally on Pi before cloud (reduce latency).
  • Monitoring: Integrate Prometheus/Grafana for broker/sensor metrics.
  • Scalability: Cluster Mosquitto with bridges for multi-factory sites.

Common Errors to Avoid

  • Broker not accessible: Check sudo systemctl status mosquitto and firewall (sudo ufw allow 1883).
  • MQTT connection refused: Duplicate client ID; add clean_session=True or unique ID.
  • Node-RED flow empty: Deploy after import (red button → Deploy).
  • Lost data: Avoid QoS=0; enforce QoS=1+ for reliable IIoT.

Next Steps

  • Advanced protocols: OPC-UA with node-opcua (GitHub repo).
  • Real hardware: Connect DHT22/DS18B20 to Pi GPIO.
  • Cloud: Integrate AWS IoT Core or Azure IoT Hub.
  • Training: Check our Learni IoT industrial training courses for IIoT certifications.