/var/packages/mosquitto/var
目录是在这里
然后tail -f log
1718334159: New connection from 192.168.50.69:63007 on port 1883.
1718334159: New client connected from 192.168.50.69:63007 as myIphone73839 (p2, c1, k60).用iPhone的客户端链接,没问题
1718334237: Client myIphone73839 disconnected.import os, sys, io
import M5
from M5 import *
from umqtt import *
from hardware import *
from base import ATOMSocketBase
mqtt_client = None
atomsocket = None
rgb = None
onoff = None
def mqtt_lemon_switch_event(data):
global mqtt_client, atomsocket, rgb, onoff
onoff = (str(((data[1]).decode()))).strip()
print(onoff)
if onoff == 'on':
atomsocket.set_relay(True)
if onoff == 'off':
atomsocket.set_relay(False)
def setup():
global mqtt_client, atomsocket, rgb, onoff
M5.begin()
mqtt_client = MQTTClient('M5_switcher', '192.168.50.232', port=1883, user='', password='', keepalive=60)
mqtt_client.connect(clean_session=True)
mqtt_client.subscribe('lemon_switch', mqtt_lemon_switch_event, qos=0)
rgb = RGB()
atomsocket = ATOMSocketBase(1, port=(22, 33), relay=23)
atomsocket.set_relay(False)
onoff = ''
rgb.set_brightness(10)
rgb.fill_color(0xff0000)
print('hello M5')
def loop():
global mqtt_client, atomsocket, rgb, onoff
M5.update()
mqtt_client.wait_msg()
if __name__ == '__main__':
try:
setup()
while True:
loop()
except (Exception, KeyboardInterrupt) as e:
try:
from utility import print_error_msg
print("sososososososo")
print_error_msg(e)
except ImportError:
print("please update to latest firmware")
# main.py上面是M5的代码
1718334377: Client M5_switcher has exceeded timeout, disconnecting.
1718334377: New connection from 192.168.50.54:57190 on port 1883.
1718334377: New client connected from 192.168.50.54:57190 as M5_switcher (p2, c0, k60).
1718334473: Client M5_switcher has exceeded timeout, disconnecting.
1718334473: New connection from 192.168.50.54:57191 on port 1883.
1718334473: New client connected from 192.168.50.54:57191 as M5_switcher (p2, c0, k60).
1718334569: Client M5_switcher has exceeded timeout, disconnecting.
1718334569: New connection from 192.168.50.54:57192 on port 1883.
1718334569: New client connected from 192.168.50.54:57192 as M5_switcher (p2, c0, k60).

https://github.com/knolleary/pubsubclient/issues/810
暂时现在是把kp值设置到了65535,稳定多了