Overview
Dual Ethernet SP2302 platform to publish data to Adafruit IO over MQTT, utilizing:
- eth1 (W5500 over SPI) to gather Modbus or sensor data
 - eth0 for Internet/cloud communication
 
field-to-cloud architecture where the data-collection interface and Internet interface are physically isolated — a common pattern in industrial IoT gateways.
What You’ll Need- SP2302 running dual-port firmware
 - WIZ850io module (W5500-based) properly connected to SP2302 SPI
 - Internet access via 
eth0 - Active Adafruit IO account
 - Feed name created (e.g., 
sensor1) - Your Adafruit username and AIO Key
 
bash
sudo apt update
sudo apt install python3-pip -y
pip3 install paho-mqttStep 2: Adafruit IO MQTT SetupRequired Settings:- MQTT Broker: 
io.adafruit.com - Port: 
1883(unencrypted) or8883(TLS) - Topic: 
username/feeds/feedname - Username: Your Adafruit IO username
 - Password: Your AIO Key
 
python
# sp2302_mqtt_to_adafruitio.py
import time
import paho.mqtt.client as mqtt
import random
# --- Adafruit IO MQTT Configuration ---
ADAFRUIT_IO_USERNAME = 'your_adafruit_username'
ADAFRUIT_IO_KEY = 'your_aio_key'
ADAFRUIT_IO_FEED = 'sensor1'
MQTT_BROKER = 'io.adafruit.com'
MQTT_PORT = 1883
MQTT_TOPIC = f"{ADAFRUIT_IO_USERNAME}/feeds/{ADAFRUIT_IO_FEED}"
# --- Bind MQTT client to eth0 explicitly (optional) ---
MQTT_LOCAL_BIND_IP = '192.168.1.100'  # eth0 IP (Internet-facing)
client = mqtt.Client()
client.username_pw_set(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
# Optional: bind to eth0 to ensure traffic doesn't go through eth1
client.bind_address = MQTT_LOCAL_BIND_IP
client.connect(MQTT_BROKER, MQTT_PORT, 60)
client.loop_start()
def main():    print(f"[✓] Publishing data to Adafruit IO topic: {MQTT_TOPIC}")    while True:        simulated_value = random.randint(0, 100)        client.publish(MQTT_TOPIC, simulated_value)        print(f"[>] Sent: {simulated_value}")        time.sleep(5)
if __name__ == "__main__":    main()Step 4: Run the Scriptbash
python3 sp2302_mqtt_to_adafruitio.pyCheck your Adafruit IO dashboard — your sensor1 feed will now update every 5 seconds with simulated values.
Ensure:
- W5500 (
eth1) is isolated for local/field communication (Modbus, sensors) - MQTT traffic to Adafruit goes through 
eth0(main NIC) 
You can confirm routing using:
bash
ip route
ip addr show eth0
ip addr show eth1ResultsChange port to 8883 and add:
python
client.tls_set()  # Uses default certsSummary- SP2302 uses dual Ethernet (eth0 and eth1)
 - MQTT publishes to Adafruit IO via 
eth0 - Sensor/modbus data (if any) flows in from 
eth1 - This creates an industrial-grade cloud-connected setup with physical and logical separation
 
40 projects • 5 followers
Secure Pi: Linux-based solution powered by Cortex A5 chipset, delivering advanced security, versatility, and performance.




Comments