Menu

Raspberry Pi Device

A Pi is just another MQTT client. The same topic conventions and data types apply — here's the smallest Python publish to prove it.

This is the Pi as a device, publishing its own readings. For the Pi as a hub that reports for many downstream sensors, see Raspberry Pi Gateway.

Nothing special required

OhioIoT is an MQTT broker, so any standard client works — on a Pi, the usual choice is paho-mqtt. There's no Pi-specific SDK you need: connect with TLS on port 8883, authenticate with your MQTT credentials, and publish to the same five-segment topics you'd use anywhere.

pip install paho-mqtt

A minimal publish

import os, ssl
import paho.mqtt.client as mqtt

USER = os.environ["MQTT_USER"]      # e.g. "larry"
PASS = os.environ["MQTT_PASS"]

client = mqtt.Client()
client.username_pw_set(USER, PASS)
client.tls_set(cert_reqs=ssl.CERT_REQUIRED)   # verify the broker cert
client.connect("mqtt.ohioiot.com", 8883)
client.loop_start()

topic = f"{USER}/pi01/numb/temperature/celsius"
client.publish(topic, "23.5")
print("published 23.5 to", topic)

That value shows up under a pi01 device card with a temperature graph — exactly as an ESP32 publish would. The topic shape is the contract; the language and hardware are up to you.

Follow the same conventions from Platform Concepts and Data Types & Routing, and everything the dashboard does for an ESP32 — graphs, twins, rules — works for the Pi too.

Subscribing

Receiving messages is the mirror image: subscribe to the topic you care about and handle them in on_message. The wildcard rules and shared-topic behavior are the same as everywhere — see Subscribing.