Closed boar24 closed 1 year ago
Does this work for you? https://github.com/bytespider/Meross/issues/57#issuecomment-1416789185
Wow, in deed! I sent
mosquitto_pub -h 192.168.188.30 -p 8883 --cafile ssl/ca.crt -t "/appliance/2211XXXXXXXXXXXXXXXXXXXXXXXX7317/subscribe" -m "{""header"":{""messageId"":""2960cfeef370338255f669525209abca"",""namespace"":""Appliance.Control.Bind"",""timestamp"":""1690744475"",""method"":""SETACK"",""sign"":""a246aa1f28f1a1d7b4a4cdc46ba6ad40"",""from"":""/cloud/hook/subscribe""},""payload"":{}}"
where I reused the messageId, timestamp and sign of an incoming message. And I had to convert the quotes to double quotes - as I am on Windows.
And this stopped the blinking. Hooray! Thanks a lot for nudging me onto the solution!
Now, when I press the plug's button, I can see in the broker and the attached subscriber that an Appliance.Control.ToggleX message comes in:
{"header":{"messageId":"690a3f909feba1ef9852c0403024783f","namespace":"Appliance.Control.ToggleX","method":"PUSH","payloadVersion":1,"from":"/appliance/2211XXXXXXXXXXXXXXXXXXXXXXXX7317/publish","uuid":"2211XXXXXXXXXXXXXXXXXXXXXXXX7317","timestamp":1690752350,"timestampMs":967,"sign":"9ee7114ec23b648e3ac2f391a58fd3ed"},"payload":{"togglex":[{"channel":0,"onoff":1,"lmTime":1690752350}]}}
Looks good!
Now, for the other way around, i.e. controlling the plug, I tried to send a similar message towards the plug:
mosquitto_pub -h 192.168.188.30 -p 8883 --cafile ssl/ca.crt -t "/appliance/2211XXXXXXXXXXXXXXXXXXXXXXXX7317/subscribe" -m "{""header"":{""messageId"":""690a3f909feba1ef9852c0403024783f"",""namespace"":""Appliance.Control.ToggleX"",""method"":""SET"",""payloadVersion"":1,""from"":""mosquitto_pub"",""uuid"":""2211XXXXXXXXXXXXXXXXXXXXXXXX7317"",""timestamp"":1690752350,""sign"":""9ee7114ec23b648e3ac2f391a58fd3ed""},""payload"":{""togglex"":[{""channel"":0,""onoff"":0,""lmTime"":1690752350}]}}"
It has
The plug only reacts on the message
So far so good. I understand that to do it properly, I must use a random messageId, a correct timestamp, the correct key and a signing value equal to md5(messageId + key + timestamp). This should be doable without too much programming effort, analogue to the code fragment which is posted here for Symcon. However, I would assume that there is tool or library around to do this, just couldn't find something. Could you possibly point me into the right direction? I am looking for a simple plain command line tool, without an integration in HomeAssistant or the like.
If you want to do this with python 3, here are some tips:
To generate random messageId:
messageId = str(random.randbytes(16).hex())
To calculate the timestamp:
timestamp = int(datetime.now(timezone.utc).timestamp())
To calculate the sign:
key = "customkey"
stringToHash = messageId+ key + str(timestamp)
hash = hashlib.md5(stringToHash.encode())
sign = hash.hexdigest()
As an example here is how I generate the JSON for my use cases (unfortunately I don't use ToggleX, so I added a short section at the end that should help you):
def generateMqttMessage(uuid, key, messageType, namespace, messageId=None, onoff=1):
data={}
data["header"]={}
data["header"]["from"]="/app/0-"+uuid+"/subscribe"
if(messageId == None):
data["header"]["messageId"]=str(random.randbytes(16).hex())
else:
data["header"]["messageId"]=messageId
data["header"]["method"]=messageType
data["header"]["namespace"]=namespace
data["header"]["payloadVersion"]=1
data["header"]["sign"]="0"
data["header"]["timestamp"]=int(datetime.now(timezone.utc).timestamp())
stringToHash = data["header"]["messageId"] + key + str(data["header"]["timestamp"])
hash=hashlib.md5(stringToHash.encode())
data["header"]["sign"]=hash.hexdigest()
data["payload"]={}
if(namespace == "Appliance.System.Clock"):
data["payload"]["clock"]={}
data["payload"]["clock"]["timestamp"]=data["header"]["timestamp"]
elif(namespace == "Appliance.System.Time"):
data["payload"]["time"]={}
data["payload"]["time"]["timestamp"]=data["header"]["timestamp"]
data["payload"]["time"]["timezone"] = "Europe/Paris"
data["payload"]["time"]["timeRule"] = []
tm = tz.gettz(data["payload"]["time"]["timezone"])
now=datetime.now(tm)
# Previous end or debut of DST
if(datetime.dst(now) != timedelta()):
dst1 = now + relativedelta(month=3, day=31, weekday=SU(-1), second=0, minute=0, hour=3, microsecond=0)
dst2 = now + relativedelta(month=10, day=31, weekday=SU(-1), second=59, minute=59, hour=2, microsecond=0)
dst3 = now + relativedelta(years=1, month=3, day=31, weekday=SU(-1), second=0, minute=0, hour=3, microsecond=0)
dst1on = 1
dst2on = 0
dst3on = 1
else:
dst2 = now + relativedelta(month=3, day=31, weekday=SU(-1), second=0, minute=0, hour=3)
if(now < dst2):
dst1 = now + relativedelta(years=-1, month=10, day=31, weekday=SU(-1), second=59, minute=59, hour=2)
dst3 = now + relativedelta(month=10, day=31, weekday=SU(-1), second=59, minute=59, hour=2)
else:
dst1 = now + relativedelta(month=10, day=31, weekday=SU(-1), second=59, minute=59, hour=2, microsecond=0)
dst2 = now + relativedelta(years=1, month=3, day=31, weekday=SU(-1), second=0, minute=0, hour=3, microsecond=0)
dst3 = now + relativedelta(years=1, month=10, day=31, weekday=SU(-1), second=59, minute=59, hour=2, microsecond=0)
dst1on = 0
dst2on = 1
dst3on = 0
data["payload"]["time"]["timeRule"].append([int(dst1.timestamp()) + dst2on, 3600 + (dst1on*3600), dst1on])
data["payload"]["time"]["timeRule"].append([int(dst2.timestamp()) + dst1on, 3600 + (dst2on*3600), dst2on])
data["payload"]["time"]["timeRule"].append([int(dst3.timestamp()) + dst2on, 3600 + (dst3on*3600), dst3on])
elif(namespace == "Appliance.Control.Electricity"):
data["payload"]["channel"] = 0
elif(namespace == "Appliance.Control.ConsumptionX"):
pass
elif(namespace == "Appliance.Control.Bind"):
pass
elif(namespace == "Appliance.System.Report"):
pass
# Just added right now for @Traveler4 but not tested
elif(namespace == "Appliance.Control.ToggleX"):
item = {}
item["channel"] = 0
item["onoff"] = onoff
item["lmTime"] = data["header"]["timestamp"]
data["payload"]["togglex"] = []
data["payload"]["togglex"].append(item)
else:
return None
return(json.dumps(data))
Dear all,
after spending many hours I still have no success in connecting my new smart WiFi plugs Refoss MSS210W to Mosquitto. I am following the procedure by Rob Griffiths, but am stuck at where the meross-setup utility is used. After I try to bind the plug to my Mosquitto broker at 192.168.188.30 with the command
./meross-setup --gateway 10.10.10.1 --wifi-ssid assid162 --wifi-pass 3438XXXXXXXXXXXX7725 --mqtt mqtts://192.168.188.30 --mqtt mqtts://192.168.188.30
the plugThe plug remains in this state forever. I have no clue on how to proceed and would highly appreciate any suggestions. The plugs work correctly when connected to the Meross cloud / eHomeLife-App.
The Mosquitto server was installed from mosquitto-2.0.15-install-windows-x64.exe on a Windows10 machine with IP 192.168.188.30. The instance uses the following mosquitto.conf, which corresponds to that of Rob Griffiths:
The three certificate files have been created on WSL/Ubuntu with this script makeCerts.sh, based on the one from ElBobo:
Note that it does not use the
-des3
option which Rob uses. I also made sure that the Organisational Names are not identical, as pointed out by sheran29.I have opened a second commandline window on the PC and successfully attached a subscriber to the running Mosquitto broker:
mosquitto_sub -h 192.168.188.30 -t "#" -t "/#" --cafile ssl/ca.crt
It successfully receives messages that I send from a third commandline window, e.g.:
mosquitto_pub -h 192.168.188.30 -p 8883 -t "test7" -m "message7" --cafile ssl/ca.crt
Here is a screenshot of the broker with three blocks:
From this I would say that Mosquitto and the certificates are OK.
Now, as I said in the beginning, after the plug is reconfigured with
./meross-setup --gateway 10.10.10.1 --wifi-ssid assid162 --wifi-pass 3438XXXXXXXXXXXX7725 --mqtt mqtts://192.168.188.30 --mqtt mqtts://192.168.188.30
it behaves as stated above. The Mosquitto broker and hence the subscriber see messages of types Appliance.Control.Bind and Appliance.System.Report, and this continues forever. What can I do?Output from the broker:
Output from the subscriber:
The same in prettyfied form:
What can I do?