我通过app inventor发送http消息 通过发送url像图片和下面的代码 我想知道MQTT是否可以接收相同类型的url或JSON 连接客户端并发送消息
from http.server import BaseHTTPRequestHandler, HTTPServer
class RequestHandler_httpd(BaseHTTPRequestHandler):
def do_GET(self):
global Request, test, data1, data2, state, case
messagetosend = bytes('test', "utf")
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.send_header('Content-Length', len(messagetosend))
self.end_headers()
self.wfile.write(messagetosend)
Request = self.requestline
Request = Request[5: int(len(Request)-9)]
return
server_address_httpd = ('192.168.66.19', 8080)
httpd = HTTPServer(server_address_httpd, RequestHandler_httpd)
httpd.serve_forever()
下面是我尝试使用的带有MQTT客户机的python代码
mqtt.Client(transport="websockets")
但我不确定这是否有效
import paho.mqtt.client as mqtt
from test1 import abc
import datetime
def on_connect(clien, userdata, flags, rc):
print("connected with" + str(rc))
client.subscribe("epaper/headphoto")
def on_message(client, userdata, msg):
print(msg.topic + "" + str(msg.payload))
if __name__ == '__main__':
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("loclhost", 1883, 60)
client.loop_forever()
问题来源StackOverflow 地址:/questions/59384586/using-app-inventor-sending-message-to-paho-mqtt-python-by-url
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。