Raspberry Pi MQTT Setup

These pages describe how to setup a Raspberry Pi with MQTT

What is MQTT you ask ?

Its a simple mecahnism to send messages from small devices. Its a very simple python library, but there is binary clients, perl clients and lots more. Here is how I use it.

pip3 install paho-mqtt
import paho.mqtt.client as mqtt
from time import sleep
import os
import math


hostname = os.getenv("HOSTNAME", "weatherst")

# print(humidity, pressure, ambient_temperature)

broker_address="10.0.1.3"

client = mqtt.Client("P1")
client.connect(broker_address)

client.publish("/sensors/"+hostname+"/light", "{\"site\":\"Mogwai Test Sensor\",\"name\":\""+hostname+"\",\"use\":\"tenant\",\"lpp\":1,\"type\":\"sensor\",\"lumins\":\""+str(round(lightLevel,2))+"\"}")