Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import paho.mqtt.client as mqtt
- import netsnmp
- import time
- import sys
- import re
- mqttusername = "***"
- mqttpassword = "***"
- mqttserver = "***"
- mqttport = 1883
- subscribe = {'#'}
- def on_connect(client, userdata, flags, rc):
- print('MQTT CONNECTED!')
- for topic in subscribe:
- print('mqtt subscribe on "' + topic + '"')
- client.subscribe(topic, 0)
- def on_disconnect(client, userdata, rc):
- print("MQTT disconnected with code "+str(rc))
- sys.exit(1)
- def on_message(client, userdata, msg):
- print(msg.topic + ' ' + msg.payload.decode('utf-8'))
- # MQTT
- client = mqtt.Client(client_id="mqtt-to-snmp")
- client.on_connect = on_connect
- client.on_message = on_message
- client.on_disconnect = on_disconnect
- client.username_pw_set(mqttusername, mqttpassword)
- client.connect(mqttserver, mqttport, 60)
- # Update Loop
- client.loop_start()
- while True:
- print('...')
- time.sleep(5)
- client.loop_stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement