mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-05-21 12:24:29 +02:00
23 lines
391 B
Python
Executable file
23 lines
391 B
Python
Executable file
#!/usr/bin/python -u
|
|
|
|
import mosquitto
|
|
import serial
|
|
|
|
usb = serial.Serial(port='/dev/ttyUSB0', baudrate=57600)
|
|
|
|
mosq = mosquitto.Mosquitto()
|
|
mosq.connect("localhost")
|
|
mosq.loop_start()
|
|
|
|
running = True
|
|
try:
|
|
while running:
|
|
line = usb.readline()
|
|
mosq.publish("sensors/cc128/raw", line)
|
|
except usb.SerialException, e:
|
|
running = False
|
|
|
|
mosq.disconnect()
|
|
mosq.loop_stop()
|
|
|