Wiznet makers

irina

Published August 27, 2025 ©

109 UCC

5 WCC

88 VAR

0 Contests

0 Followers

0 Following

Original Link

IRIV IO Controller IoT Gateway : MQTT

Read RS-485 Modbus temperature/humidity on IRIV IO Controller and publish to Adafruit IO via MQTT over Ethernet using WIZnet W5x00 in CircuitPython.

COMPONENTS
PROJECT DESCRIPTION

This tutorial shows how to use an IRIV IO Controller to read temperature and humidity from an RS-485 (Modbus RTU) sensor and publish both values to Adafruit IO over MQTT via Ethernet using a WIZnet W5x00 driver in CircuitPython. You’ll create an Adafruit IO account, collect your AIO Key, create two feeds (Temperature/Humidity), place credentials in settings.toml, then publish with adafruit_minimqtt—exactly as in the original Cytron guide.


🔧 Project Overview

Project Name: IRIV IO Controller IoT Gateway : MQTT
Author (Tutorial): Hussien Jawhar Sathik (Cytron)
Platform: IRIV IO Controller (CircuitPython)
Networking: WIZnet W5x00 (CircuitPython adafruit_wiznet5k)
Field Bus: RS-485 (Modbus RTU)
Cloud/App: Adafruit IO via MQTT (two feeds: Temperature, Humidity)
What You’ll See: Console prints for temp/humidity and MQTT publish logs; matching live values on Adafruit IO dashboards.

The tutorial uses Adafruit IO as the MQTT broker, obtaining the AIO Key, creating feeds, and wiring credentials through settings.toml


⚡ How the Project Works

1) Hardware Setup

IRIV IO Controller

RS-485 (Modbus RTU) temperature/humidity sensor (e.g., slave address 1)

Ethernet connection (DHCP recommended)

Initialize W5x00 via SPI (adafruit_wiznet5k), create socket/SSL context, then build an MQTT client session.

2) Protocols & Control

Modbus RTU: Read holding registers—example maps reg 1 → temperature and reg 0 → humidity, with a /10 scaling. 

MQTT (Adafruit IO): Use adafruit_minimqtt to connect to io.adafruit.com with username + AIO Key, then publish() to username/feeds/Temperature and username/feeds/Humidity.

3) Development Process

Create an Adafruit IO account; copy the AIO Key and put it in settings.toml (e.g., aio_username, aio_key).

Create two feeds: Temperature and Humidity; reference them in code.

Run on IRIV → verify console output and that both feeds update on Adafruit IO. 


💡 Key Features & Benefits

Features

IRIV + W5x00 Ethernet: Stable wired uplink for MQTT telemetry. 

Modbus RTU integration: Periodic RS-485 polling for T/RH with simple scaling.

MQTT to Adafruit IO: Straightforward publish to Temperature/Humidity feeds. 

CircuitPython stack: adafruit_wiznet5k, adafruit_minimqtt, adafruit_requests, uModbus—compact, readable code.

Applications

Building/Facility: Environmental monitoring (temperature/humidity)

Industrial Edge: RS-485 sensors bridged to cloud dashboards

Smart Home/Office: Robust IP backhaul for sensor data


Code Highlights (Essentials)

Below is the distilled flow from the tutorial—replace with your Adafruit IO credentials and feeds.

import os, time, board, busio
import adafruit_connection_manager, adafruit_requests
from digitalio import DigitalInOut
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
from umodbus.serial import Serial as ModbusRTUMaster
import adafruit_minimqtt.adafruit_minimqtt as MQTT

# AIO credentials (from settings.toml)
AIO_USER = os.getenv("aio_username")
AIO_KEY  = os.getenv("aio_key")

# Ethernet (DHCP)
cs  = DigitalInOut(board.W5500_CS)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
eth = WIZNET5K(spi, cs)

# Socket pool for MQTT
pool = adafruit_connection_manager.get_radio_socketpool(eth)

# MQTT client (non-SSL shown for brevity)
mqtt = MQTT.MQTT(broker="io.adafruit.com",
                 username=AIO_USER, password=AIO_KEY,
                 is_ssl=False, socket_pool=pool, ssl_context=None)

# Modbus master
host = ModbusRTUMaster(tx_pin=board.TX, rx_pin=board.RX)

mqtt.connect()
while True:
    # Example: reg1=temp(°C*10), reg0=humidity(%*10)
    temperature = host.read_holding_registers(1, 1, 1)[0] / 10.0
    humidity    = host.read_holding_registers(1, 0, 1)[0] / 10.0
    mqtt.loop()
    mqtt.publish(f"{AIO_USER}/feeds/Temperature", temperature)
    mqtt.publish(f"{AIO_USER}/feeds/Humidity",    humidity)
    time.sleep(5)

The original sample shows the same broker/feeds, credential handling via settings.toml, and adafruit_minimqtt usage.

 


Troubleshooting Tips

No feed updates? Check AIO username/key, feed names, and network reachability to io.adafruit.com.

Bad readings? Confirm Modbus slave address, register indices (1 and 0), baud/parity/stop bits, and scaling factor.

DHCP issues: Try a static IP on the W5x00 to rule out local network conflicts.

Documents
Comments Write