itead / Sonoff_Devices_DIY_Tools

BSD 3-Clause "New" or "Revised" License
553 stars 167 forks source link

RFR3 doesn't respond to the request and the error was not returned #13

Open MaggieWong27 opened 5 years ago

MaggieWong27 commented 5 years ago
  1. When I try to send my own REST-request, the "data" field is filled in as an object (in accordance with your description of DIY protocol - https://github.com/itead/Sonoff_Devices_DIY_Tools/blob/master/other/SONOFF%20DIY%20MODE%20Protocol%20Doc.pdf). RFR3 does not respond to such request at all (it does not even return an error).

Your DIY tool fills the "data" field as a string, which contradicts your protocol documentation.

  1. Do you have a simple minimal step-by-step example on working with REST-requests? Would be perfect - using a browser.
cpuga commented 5 years ago

You are right. The documentation is wrong. The DIY tool not only fills the "data" field as a string, the string has is content escaped ( \" instead of only " ). https://github.com/itead/Sonoff_Devices_DIY_Tools/blob/a337e85aeda254e64018a60ce1dd439e75db2a0b/code/lan_ewlink_api.py#L226

Also sends one undocumented field: "selfApikey": "123" It can be any number or empty but the field has to be included. Otherwise the device doesn't respond.

This works in postman / curl : {"sequence": "1563473445", "deviceid": "100000140e", "encrypt": false, "selfApikey": "", "data": "{\"switch\": \"on\"}"}

I hope this helps

cpuga commented 5 years ago

Sorry, github has interpreted my escaped quotes.. :) This is the working json: {"sequence": "1563473445", "deviceid": "100000140e", "encrypt": false, "selfApikey": "", "data": "{\"switch\": \"on\"}"}

notenoughtech commented 5 years ago

I'm struggling to pass the values using HTTP POST in NodeRED (javascript) I have tried a couple of version of the payload but I'm missing something obvious (tool is working ok)

I tried the formatting the message your way and dropping the "/" to pass it as JSON object too without luck.

I get message Error: read ECONNRESET or Error: read ECONNRESET : http://192.168.1.28:8081/zeroconf/switch Any suggestions?

cpuga commented 5 years ago

I use NodeRED too. My function node is as simple as:

msg.payload = { "sequence": "1563473445", "deviceid": "100000140e", "encrypt": false, "selfApikey": "", "data": "{\"switch\": \"on\"}" } return msg;

It has to be formatted as the DIY tool does, not like the documentation says.

notenoughtech commented 5 years ago

After the update only device ID and the data has to be submitted. Finally works

On Fri, 2 Aug 2019, 08:14 cpuga, notifications@github.com wrote:

I use NodeRED too. My function node is as simple as:

msg.payload = { "sequence": "1563473445", "deviceid": "100000140e", "encrypt": false, "selfApikey": "", "data": "{\"switch\": \"on\"}" } return msg;

It has to be formatted as the DIY tool does, not like the documentation says.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/itead/Sonoff_Devices_DIY_Tools/issues/13?email_source=notifications&email_token=AKDRL27SSYG56RUX5DVD5ITQCPNFBA5CNFSM4H7KTUTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3M3U7Y#issuecomment-517585535, or mute the thread https://github.com/notifications/unsubscribe-auth/AKDRL22WNBS52JXAJIYA36LQCPNFBANCNFSM4H7KTUTA .