LILCMU / whitearrow

White -- Arrow >> 'An educational learning kits'
1 stars 0 forks source link

mqtt block publish #1

Closed universestu closed 7 years ago

universestu commented 7 years ago

https://github.com/micropython/micropython-lib/pull/91 New Update!!

import mqtt >> from mqtt import MQTTCLIENT retain=true >> retain=True

ADD.. from machine import unique_id import ubinascii

example: import time,math import ubinascii from mqtt import MQTTClient from machine import unique_id

def main(): CLIENT_ID = ubinascii.hexlify(unique_id()) mqtt = MQTTClient(CLIENT_ID,"broker.mqttdashboard.com") mqtt.connect() while True: mqtt.publish('eiei','Hello',retain=True) time.sleep(1) mqtt.disconnect()

universestu commented 7 years ago

import time,math import ubinascii from mqtt import MQTTClient from machine import unique_id

def sub_cb(topic, msg): print((topic, msg))

def main(): CLIENT_ID = ubinascii.hexlify(unique_id()) mqtt = MQTTClient(CLIENT_ID,"broker.mqttdashboard.com") mqtt.set_callback(sub_cb) mqtt.connect() mqtt.subscribe(b'eiei') time.sleep(1) while True: if True: mqtt.wait_msg() else: mqtt.check_msg() time.sleep(1)

mqtt.disconnect()