Skip to content
Snippets Groups Projects
Select Git revision
  • a8976cc817f7f7a90060d6b3b64afe2d7d1dd9ad
  • main default protected
  • jw_sonar
  • v5.0
  • open_tool_for_self_hosting
  • jw_sonar_backup
  • move-to-esm-only
  • v4.2
  • v4.1
9 results

README.md

Blame
  • To learn more about this project, read the wiki.
    publisher.py 546 B
    import paho.mqtt.client as mqtt
    import os
    import time
    
    def on_connect(client, userdata, flags, rc):
        if rc==0:
            print("Connection Successful! Returned code =",rc)
        else:
            print("Unable to Connect. Returned code =", rc)
    
    def sender(client):
        while True:
            client.publish('comms', 'MQTT Secret Message')
            print('Published on topic comms')
            time.sleep(10)
    
    if __name__ == "__main__":
        client = mqtt.Client()
        client.on_connect = on_connect
    
        client.connect('broker', 1883, 60)
    
        sender(client)