Skip to content

Instantly share code, notes, and snippets.

@sat0ken
Created December 4, 2017 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sat0ken/b8215e6c2c404d3726d98ba0ad1fdb1c to your computer and use it in GitHub Desktop.
Save sat0ken/b8215e6c2c404d3726d98ba0ad1fdb1c to your computer and use it in GitHub Desktop.
from mqtt import MQTTClient
import time
def pub(server, topic, messaage):
client = MQTTClient("ESP32_Client", server)
client.connect()
client.publish(bytearray(topic), bytearray(messaage))
time.sleep(1)
client.disconnect()
def read_msg(tpc, msg):
print(tpc, msg)
def sub(server, topic):
client = MQTTClient("ESP32_Client", server)
client.set_callback(read_msg)
client.connect()
client.subscribe(bytearray(topic))
while True:
if True:
client.wait_msg()
else:
client.chech_msg()
time.sleep(1)
client.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment