SIoT Platform
SIoT is an open-source MQTT platform designed specifically for IoT education in primary and secondary schools. It features a simple interface, easy operation, and supports setting up a server within a local network, making it ideal for classroom IoT data acquisition and visualization teaching.
This example demonstrates how to connect mPython IoT to the SIoT platform, publish sensor data, and view it on the SIoT web interface.
SIoT Platform Overview
SIoT is based on the standard MQTT protocol and uses topics to distinguish different devices and data. When a device publishes a message to a topic, the data records and real-time curves can be viewed under the corresponding topic on the SIoT web interface.
Hint
SIoT can run on a classroom computer or Raspberry Pi. It only needs to be on the same local network as mPython IoT for communication. Note the server IP address and port (default 1883) when using it.
Connecting to SIoT and Publishing Data
First create a topic on the SIoT platform, for example classroom/temperature. Then write the mPython IoT code:
from umqtt.simple import MQTTClient
import network
import time
# Connect to Wi-Fi
sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.connect('your_ssid', 'your_password')
while not sta.isconnected():
time.sleep(0.5)
# SIoT server configuration
SERVER = "192.168.1.100" # SIoT server local IP address
PORT = 1883 # SIoT default port
CLIENT_ID = "mpython_iot_001" # Client ID
TOPIC = "classroom/temperature" # Topic created on SIoT
client = MQTTClient(CLIENT_ID, SERVER, PORT)
client.connect()
print("Connected to SIoT: %s" % SERVER)
# Periodically publish temperature data
value = 25
while True:
client.publish(TOPIC, str(value))
print("Reported temperature: %d" % value)
value += 1
time.sleep(5)
Viewing Data on the SIoT Web Interface
Open a browser and visit the SIoT server address (e.g.
http://192.168.1.100:8080).Find the topic
classroom/temperature.You can see the data records reported by mPython IoT and the automatically generated data curve charts.
Note
The default web port for SIoT differs from the MQTT port. Please refer to your actual deployment for the web access port.
Receiving Commands from SIoT
SIoT also supports sending messages to topics. mPython IoT can subscribe to a topic to receive control commands:
def sub_cb(topic, msg):
print("Received command: %s" % msg.decode())
client.set_callback(sub_cb)
client.subscribe(TOPIC)
while True:
client.wait_msg()