I have several Meross plugs configured to use local MQTT, and they work very nicely.
I use GitHub - bytespider/Meross: Investigating the Meross/Refoss MSS310 Smart Plug and getting these devices to communicate with our private MQTT brokers to configure them (it sets the wifi and MQTT server). However, there is a new requirement to ACK it’s first MQTT message: Setting MQTT and Wifi for MSS210 · Issue #57 · bytespider/Meross · GitHub
It’s only needs to be done once, and I’ve been doing it manually for now.
Is there a way to create an automated generic process for this. Basically it needs to
- listen for messages at /appliance/<device’s mac address>/publish. Where the Mac address is different for every device
- Sent the same message back to /appliance/<device’s mac address>/publish with one field changed to “SETACK”
I just need a point in the correct direction, I’m happy to do the work. I have java/javascipt experience.
I may have overlooked a requirement; I don’t want to configure each device separately; I want to handle any new devices added.
So most likely you’ll have to write a script that listens to /appliance/+/publish
(Are you sure about the leading slash? Common agreement is not to use leading slashes in MQTT topics)?
A simple python script (I did not test, but it should be something like that):
#!/usr/bin/python
from paho.mqtt import client as mqtt
# bare minimum settings
MQTT_SERVER = 'localhost'
MQTT_PORT = '1883'
MQTT_RECONNECT = 60
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
client.subscribe('/appliance/+/publish')
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
#get payload as json
data=json.loads(format(msg.payload.decode("utf-8")))
#change specific path to SETACK
data['the']['path']='SETACK'
#publish json
client.publish(msg.topic, payload=json.dumps(data), qos=0, retain=False)
# initialize client
client = mqtt.Client()
# Start connection
client.connect(MQTT_SERVER, MQTT_PORT, MQTT_RECONNECT)
# Wait for incomming messages
client.loop_forever()
1 Like
Looks good, thank you.
Yes; definitely a leading slash.