标签:read nec txt while exit publish pre __name__ window
Two client:
import paho.mqtt.client as mqtt import time import sys import random def on_connect(client, userdata, flags, rc): print("connected with result code "+str(rc)) def on_publish(client, userdata, mid): print("Publish au/csie/5/9/5912/temperture", ) client = mqtt.Client() client.on_connect = on_connect client.on_publish = on_publish client.connect("iot.eclipse.org", 1883, 60) while True: try: with open("C:\\Users\\86390\\Desktop\\test_s.txt", "r") as f: data = f.readlines() # data = random.randint(24, 28) # client.publish("au/csie/5/9/5912/tempeture", str(data)+"C") print(len(str(data))) time.sleep(2) except KeyboardInterrupt: print("EXIT") client.disconnect() sys.exit(0)
import paho.mqtt.client as mqtt import time import sys import random def on_connect(client, userdata, flags, rc): print("Connected with result code"+str(rc)) client.subscribe("/inode/mychannel") def on_message(client, userdata, msg): print(len(str(msg.payload))/1024/1024) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect("127.0.0.1", 1883, 60) client.loop_forever()
Publisher and Client:
import paho.mqtt.publish as publish import time def transmitMQTT(strMsg): strMqttBroker = "localhost" # strBroker = "127.0.0.1" strMqttChannel = "/inode/mychannel" print(len(str(strMsg))) publish.single(strMqttChannel, strMsg, hostname=strMqttBroker) if __name__ == ‘__main__‘: while True: transmitMQTT("a"*1024*1024*40) time.sleep(0.1) print (time.time())
import paho.mqtt.client as mqtt import time import sys import random def on_connect(client, userdata, flags, rc): print("Connected with result code"+str(rc)) client.subscribe("/inode/mychannel") def on_message(client, userdata, msg): print(len(str(msg.payload))/1024/1024) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect("127.0.0.1", 1883, 60) client.loop_forever()
坑:
标签:read nec txt while exit publish pre __name__ window
原文地址:https://www.cnblogs.com/ryu-manager/p/9347867.html