sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
230 stars 124 forks source link

SinricP Doorbell - websockets problem?? #17

Closed steve8266 closed 4 years ago

steve8266 commented 4 years ago

Hi, I'm still trying hard to get the doorbell working. I'm using all the latest libraries (note: vs 2.2.6 was same) and the original code etc, using platformio on a nodemcu. Sometimes when I compile it works absolutely fine, press the button and alexa does what she should. Other times and most often it fails to start properly - please see terminal output below (debug on). I dont think its my router because everything I've got on original sinric is still working 100%. It looks to me (non expert eye) that its some kind of websockets timeout issue. That's the only explanation I've got, but why does it work sometimes and not others...

I would really appreciate your help please. Terminal output as follows: SDK:2.2.2-dev(38a443e)/Core:2.6.3=20603000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-16-ge23a07e/BearSSL:89454af

state: 0 -> 2 (b0) state: 2 -> 3 (0) state: 3 -> 5 (10) add 0 aid 6 cnt

connected with BTHub6-xxxxx, channel 11 dhcp client start... ....ip:192.168.x.xxx,mask:255.255.255.0,gw:192.168.x.xxx connected! WiFi: IP-Address is 192.168.x.xxx [SinricPro:add()]: Adding device with id "5de3974a5xxxxxxxxxxxxxxxx". SinricPro:Websocket: Connecting to WebSocket Server (ws.sinric.pro)

appkey:f5dd293a-8ad0-xxxx-xxxx-xxxxxxxxxxxx deviceids:5de3974a553xxxxxxxxxxxxx restoredevicestates:false platform:ESP8266 version:2.2.7 [WS-Client] connect ws... [WS-Client] connected to ws.sinric.pro:80. [WS-Client][sendHeader] sending header... [WS-Client][sendHeader] handshake GET / HTTP/1.1 Host: ws.sinric.pro:80 Connection: Upgrade Upgrade: websocket Sec-WebSocket-Version: 13 Sec-WebSocket-Key: woG190jRBoTZcY4NwXar6Q== Sec-WebSocket-Protocol: arduino appkey:f5dd293a-8ad0-xxxx-xxxx-xxxxxxxxxxxx deviceids:5de3974axxxxxxxxxxxxxxxx restoredevicestates:false platform:ESP8266 version:2.2.7 User-Agent: arduino-WebSocket-Client

[write] n: 367 t: 7126 [WS-Client][sendHeader] sending header... Done (33927us). [WS-Client][handleHeader] RX: HTTP/1.1 101 Switching Protocols [WS-Client][handleHeader] RX: Server: nginx [WS-Client][handleHeader] RX: Date: Tue, 17 Dec 2019 20:56:39 GMT [WS-Client][handleHeader] RX: Connection: upgrade [WS-Client][handleHeader] RX: Upgrade: websocket [WS-Client][handleHeader] RX: Sec-WebSocket-Accept: bCCnndFQKswdSP7/ex9TKFqCDYk= [WS-Client][handleHeader] RX: Sec-WebSocket-Protocol: arduino [WS-Client][handleHeader] Header read fin. [WS-Client][handleHeader] Client settings: [WS-Client][handleHeader] - cURL: / [WS-Client][handleHeader] - cKey: woG190jRBoTZcY4NwXar6Q== [WS-Client][handleHeader] Server header: [WS-Client][handleHeader] - cCode: 101 [WS-Client][handleHeader] - cIsUpgrade: 1 [WS-Client][handleHeader] - cIsWebsocket: 1 [WS-Client][handleHeader] - cAccept: bCCnndFQKswdSP7/ex9TKFqCDYk= [WS-Client][handleHeader] - cProtocol: arduino [WS-Client][handleHeader] - cExtensions: [WS-Client][handleHeader] - cVersion: 0 [WS-Client][handleHeader] - cSessionId: [WS-Client][handleHeader] Websocket connection init done. [WS][0][headerDone] Header Handling Done.

[WS][0][handleWebsocketWaitFor] size: 2 cWsRXsize: 0 [readCb] n: 2 t: 7313 [WS][0][handleWebsocketWaitFor][readCb] size: 2 ok: 1 [WS][0][handleWebsocket] ------- read massage frame ------- [WS][0][handleWebsocket] fin: 1 rsv1: 0 rsv2: 0 rsv3 0 opCode: 1 [WS][0][handleWebsocket] mask: 0 payloadLen: 24 [readCb] n: 24 t: 7335 [WS][0][handleWebsocket] text: {"timestamp":1576616199} SinricPro:Websocket: receiving data [SinricPro.handleReceiveQueue()]: 1 message(s) in receiveQueue [SinricPro.handleReceiveQueue()]: Signature is valid. Processing message... [SinricPro:extractTimestamp(): Got Timestamp 1576616199 [HBtimeout] pong TIMEOUT! lp=-290499 millis=10001 pi=10001 count=1 [WS-Client] sending HB ping [WS][0][sendFrame] ------- send message frame ------- [WS][0][sendFrame] fin: 1 opCode: 9 mask: 1 length: 0 headerToPayload: 0 [write] n: 6 t: 10009 [WS][0][sendFrame] sending Frame Done (3042us). bcn_timout,ap_probe_send_start pm open,type:2 0 ap_probe_send over, rest wifi status to disassoc state: 5 -> 0 (1) rm 0 pm close 7 [WS-Client] connection lost. [WS-Client] client disconnected.

[WS-Client] connect ws... [WS-Client] connection to ws.sinric.pro:80 Failed [WS-Client] client disconnected. [WS-Client] connect ws... [WS-Client] connection to ws.sinric.pro:80 Failed ................etc etc continuously..............

Your comments/advice please. Regards, Steve

sivar2311 commented 4 years ago

Hi Steve,

this looks like a weak wifi connection.

steve8266 commented 4 years ago

I’m 2m away from the router. And did a scan check. It’s strong.

steve8266 commented 4 years ago

Also tried with different nodemcu board

steve8266 commented 4 years ago

But you’ve set me thinking. Maybe the ip the router allocates or the channel it’s picking up. I’ll compare a good run with the bad runs to see if there’s a pattern. Also I have UDP packets buzzing around on my network cos of other home automation stuff. Could that interfere??

kakopappa commented 4 years ago

Try

void setup() { Serial.begin(9600); WiFi.setSleepMode(WIFI_NONE_SLEEP); [.....] }

From

https://github.com/esp8266/Arduino/issues/5083

On Wed, 18 Dec 2019 at 5:38 AM steve8266 notifications@github.com wrote:

But you’ve set me thinking. Maybe the ip the router allocates or the channel it’s picking up. I’ll compare a good run with the bad runs to see if there’s a pattern. Also I have UDP packets buzzing around on my network cos of other home automation stuff. Could that interfere??

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sinricpro/esp8266-esp32-sdk/issues/17?email_source=notifications&email_token=ABZAZZVPTA5AOUPAHI3KV5DQZFIGPA5CNFSM4J4BVFP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHEGJII#issuecomment-566781089, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZUSFB2Y4GQRBNGOAVLQZFIGPANCNFSM4J4BVFPQ .

sivar2311 commented 4 years ago

I compared the log with my own log. Problem starts here (i dont have this in my logs)

pm open,type:2 0
ap_probe_send over, rest wifi status to disassoc
state: 5 -> 0 (1)
rm 0
pm close 7

Your module seems to disconnect from wifi and set sleepmode (see here https://github.com/esp8266/Arduino/issues/4455#issuecomment-397884470) (Even Ivan Grokhotkov doesnt know the complete meaning, because there is no documentation about). I think the tip about setSleepMode could be the right way.

sivar2311 commented 4 years ago

While investigating about ESP wifi logs i can say this is a wifi issue! bcn_timout,ap_probe_send_start means: ESP didnt received AP beacon for a while and do a request to your access point ("Hey AP, are you still there?") ap_probe_send over, rest wifi status to disassoc means: ESP didnt get a response from AP -> ESP is closing wifi connection.

Are your other ESP's connected to the same Access Point? Try to use another Acccess Point -> Use your phone to open an Access Point and connect your ESP to this one

steve8266 commented 4 years ago

Gents, Many thanks indeed for your time and advice. I’ll try the nosleep straightaway but also follow the AP route separately at same time. Regards, Steve