Publishing MQTT messages from a Python script on a Raspberry Pi

后端 未结 1 815
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 12:09

I am trying to configure a Raspberry Pi (Raspbian, Jessie) to send temperature data from a DS18B20 sensor to my MQTT broker.

I have installed mosquitto, mosquitto-cl

1条回答
  •  北海茫月
    2021-01-15 13:01

    As mentioned in the comment, the code you posted does work, but for publishing a single message this form is better

    #!/usr/bin/env python
    import paho.mqtt.publish as publish
    
    publish.single("test/test", "Hello world!", hostname="192.168.0.21")
    

    0 讨论(0)
提交回复
热议问题