Avatar r50 a6ce93fe35b158fd29ba0e8681c918c22117160e9586a56eee4ffbc20df9bda1
Разработка PHP

Настройка сервера Sonoff

Добавлено 07 апр 2019 в 05:01
https://github.com/vponomarev/Sonoff-Server/

Установка и настройка сервера Sonoff, websocket, https, ssl сертификатов. Знание протокола обмена с устройствами Sonoff:

request register
{"userAgent":"device","apikey":"df6725f6-0b86-4415-9951-111111111111","deviceid":"1000021221","action":"register","version":2,"romVersion":"1.5.5","model":"ITA-GZ1-GL","ts":970}


answer
{"error":0,"deviceid":"1000021221","apikey":"df6725f6-0b86-4415-9951-9cf8900c7825","config":{"devConfig":{"storeAppsecret":"","bucketName":"","lengthOfVideo":0,"deleteAfterDays":0,"persistentPipeline":"",
"storeAppid":"","uploadLimit":0,"statusReportUrl":"","storetype":0,"callbackHost":"","persistentNotifyUrl":"",
"callbackUrl":"","persistentOps":"","captureNumber":0,"callbackBody":""}},"hb":1,"hbInterval":145}

request update
{"userAgent":"device","apikey":"df6725f6-0b86-4415-9951-111111111111","deviceid":"1000021221","action":"update"}

{"error":0,"deviceid":"1000021221","apikey":"df6725f6-0b86-4415-9951-111111111111"}

request update params
{
"userAgent":"device",
"apikey":"df6725f6-0b86-4415-9951-111111111111",
"deviceid":"1000021221",
"action":"update",
"params":{
"switch":"on",
"fwVersion":"1.5.5",
"rssi":-31,
"staMac":"5C:CF:7F:A6:FD:F6",
"startup":"on"
}
}

{"error":0,"deviceid":"1000021221","apikey":"df6725f6-0b86-4415-9951-111111111111"}


Когда нажимаю OFF в интерфейсе на устройство приходит такой запрос
RECEIVED: {"userAgent":"app","action":"update","deviceid":"1000021221","apikey":"df6725f6-0b86-4415-9951-9cf8900c7825","sequence":"1554574203","ts":0,"params":{"switch":"off"},"from":"app"}

В ответ нужно отправить
{"userAgent":"device","apikey":"df6725f6-0b86-4415-9951-111111111111","deviceid":"1000021221","action":"update", "sequence":"1554574203", "params": {"switch":"off"}}

В ответ на этот запрос придёт
{"error":0,"deviceid":"1000021221","apikey":"df6725f6-0b86-4415-9951-111111111111"}

если устройство сменило статус на ON:
{"userAgent":"device","apikey":"df6725f6-0b86-4415-9951-111111111111","deviceid":"1000021221","action":"update", "params": {"switch":"on"}}

2398378648