The NORVI-IIOT, powered by the ESP32-WROOM32 microcontroller, connects to the ThingsBoard IoT platform using Wi-Fi and the MQTT protocol. It reads modbus readings(via RS485) and sends this data securely to ThingsBoard, where users can monitor real-time values through customizable dashboards. This setup allows remote access to sensor data, enabling easy monitoring and management without the need for physical device interaction.
System ArchitectureThe system architecture of the NORVI-IIOT device integrated with ThingsBoard is designed to enable seamless, real-time monitoring of Modbus readings using secure wireless communication.
ThingsBoard SetupTo successfully visualize Modbus readings from the NORVI-IIOT device, the ThingsBoard platform must be properly configured. This section outlines the key steps to set up ThingsBoard for device management and data visualization.
1. Create a ThingsBoard Account and Log In
- Register for a ThingsBoard cloud account at ThingsBoard or install a local ThingsBoard server.
- Log in to your ThingsBoard dashboard using your credentials.
2. Add a New Device
- Navigate to Devices and click + Add new device.
- Provide a meaningful name for your NORVI-IIOT device (e.g., “NORVI IIOT – Modbus RS485”).
- Save the device; this generates a unique Access Token used for MQTT authentication.
3. Configure Device Credentials
- Open the newly created device and go to the Manage credentials tab.
- Copy the Access Token; this token will be used in the ESP32 MQTT client to authenticate the device.
4. Set Up Telemetry Data
- ThingsBoard automatically accepts telemetry data sent via MQTT.
- Your device will publish Modbus readings as telemetry using JSON format (e.g., {“ANIN”: 66}).
5. Create a Dashboard for Visualization
- Go to the Dashboards section and click + Add new dashboard.
- Design a dashboard by adding widgets such as charts, gauges, or numeric displays.
- Link widgets to the NORVI-IIOT device telemetry keys (e.g., ANIN1) to visualize real-time Modbus data.
6. Set Alerts and Rules (Optional)
- Configure rules to trigger alerts or actions based on input thresholds or device status.
- Use ThingsBoard’s rule engine to automate notifications or device commands.
With ThingsBoard configured, the NORVI-IIOT device can securely send Modbus data over MQTT, enabling real-time monitoring and analysis through intuitive dashboards.
Software SetupA. Install the ESP32 board in Arduino IDE:
- Go to File > Preferences.
- Go to Tools > Boards > Boards Manager, search for “ESP32”, and install.
- NORVI-with-ThingsBoard
B. Install Required Libraries (Arduino):
Go to Sketch > Include Library > Manage Libraries and install:
- WiFi.h
- PubSubClient.h
- ModbusMaster.h
C. Configure the code:
Code Explanation - Find all codes from here for the flowing setups
1. Library Inclusions and Definitions
- WiFi.h – Connects ESP32 to Wi-Fi.
- PubSubClient.h – Handles MQTT communication with ThingsBoard.
- ModbusMaster.h – Reads data from Modbus RTU devices via RS485.
- RXD / TXD – Serial pins for RS485 communication.
- FC – Flow control pin for enabling/disabling RS485 driver.
2. Wi-Fi and ThingsBoard Credentials
- Wi-Fi SSID and password allow the ESP32 to connect to the local network.
- ThingsBoard server details, port (default MQTT port 1883), and the device token authenticate the device on ThingsBoard.
3. Modbus RS485 Setup
- ModbusMaster node – Modbus RTU communication object.
- preTransmission/postTransmission – Control RS485 transceiver direction (send/receive).
4. Wi-Fi Connection Function
5. MQTT Connection Function
6. Sending Telemetry Data
- Reads 3 holding registers starting at address 0x40001.
- Extracts each register value (IN1, IN2, IN3)
- Constructs a JSON string payload with modbus readings (ANIN1 to ANIN3).
- Publishes telemetry data to ThingsBoard MQTT topic “v1/devices/me/telemetry”.
7. Setup Function
- Initializes serial communication for debug output.
- Connects to Wi-Fi.
- Configures MQTT server.
- Initializes RS485 pins, and Modbus communication.
8. Main Loop
Keeps MQTT connection alive, reconnects if disconnected.
Calls client.loop() to maintain MQTT client state.
Sends telemetry every 5 seconds.
Testing Setup
1. Upload the Firmware
- Compile and upload the firmware to the ESP32 and check the serial monitor output and verify that device is connected to the Wifi and ThingsBoard MQTT.
2. Expected Outputs
- ESP32 logs network connection and update status.
- Check ThingsBoard dashboard to confirm it displays correct Modbus readings.
Issue > Possible Cause > Solution
- Wi-Fi not connecting > Incorrect SSID or password; weak signal > Verify credentials in code, ensure router is on and within range
- MQTT connection failure > Wrong server/port; invalid Access Token > Check ThingsBoard server address and port; confirm Access Token matches device in ThingsBoard
- No Modbus data received > Wrong slave ID or register address in code > Verify the Modbus slave ID and register addresses with your device’s documentation and update node.begin() and readHoldingRegisters() accordingly.
- Data updates delayed or missing > Long send interval; Wi-Fi dropouts > Reduce telemetry interval in code; check Wi-Fi stability
- All values show 0 > RS485 wiring reversed (A/B swapped) > Swap the A/B lines between NORVI-IIOT and Modbus device.
- No Modbus readings on dashboard > Widget keys don’t match telemetry keys > Ensure ThingsBoard widget keys match JSON keys (ANIN1, etc.) sent by device
NORVI
Comments