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
228 stars 121 forks source link

My device is often busy and not responding at all! #239

Closed Bitcraze26 closed 2 years ago

Bitcraze26 commented 2 years ago

Hi guys! I'm new to Sinric and i have made a simple board with ESP8266 and 3 buttons for my living room lights.

Very often the board does not respond from alexa and sometimes even from the buttons. The commands seems freezed and then executed all togheter. My board is fixed at about 60cm from wifi router (and i have made many test far away from router with no problem of connection at all) and i have about 30 mbits of internet speed.

I have non-blocking functions inserted for controlling the LEDs and switches. What can it depend on?

OTA is disabled

My code is here: https://pastebin.com/ThFPYxaK

Thanks for your work, Simone

sivar2311 commented 2 years ago

Hi @Bitcraze26 !

The sketch works for me without issues - no response problems. Even the soft dimming of the LED works well - which looks quite nice! :)

The sketch looks a bit complicated and i spend a time to understand it correctly.

Here is what i got:

Bitcraze26 commented 2 years ago

Hi @sivar2311 !

I have changed the little things you suggested. Problems remains. With help of ssh (esp8266 connected on USB of raspberry pi) on my smartphone i can understand maybe what is the main problem of the system.

1° problem: When i press a LED or FARETTI (GU10 spotligths trough relay board) btn it works perfectly, but 3 seconds later my board send event message to sinric server and it takes up to 10 seconds for send the message with websocket and the program is stucked until the message was sended and also my physical buttons aren't been processed in the loop. This is very annoing because my physical button should been always reactive.

There a chance to send "non-blocking" event?

2° problem: Sending Alexa command takes up to 30 seconds (alexa app or alexa echo dot don't change). And randomly disconnection from Sinric.

My serial debug print: https://pastebin.com/j1WP3wUT

----- JUST FOR CLEARING MY DOUBT ------

Declaration of multiple Sinric device with same name (eg. &mySwitch) trough the loop, can affect the proper operation of the Sinric system??

Thanks!!

sivar2311 commented 2 years ago

SinricPro works with a messsage queue (for sending and receiving) - there is no blocking code inside. When a device is sending an event (like mySwitch.sendPowerState) the event is put into the send queue. The send & receive queue will be handled in the next call of SinricPro.handle() from the main loop() function. This usually takes only a few milliseconds.

So the 10 / 30 seconds delays you have must come from somewhere else. My test this morning with the sketch you provided worked perfectly - no delays here.

Declaration of multiple Sinric device with same name (eg. &mySwitch) trough the loop, can affect the proper operation of the Sinric system??

I am not sure if i undersand this question correctly.

&mySwitch is a reference to the device object handled by SinricPro SDK. The first call on SinricPro[DEVICE_ID] will create a new object with the deviceId in the SDK and return a reference to this object. You can see this in the log: "[SinricPro]: Device "61d67478fbac8a45fac8b590" does not exist. Creating new device". Any later call to SinricPro[DEVICE_ID] will return a reference to this device (without creating a new one - except the provided deviceId is a different one).

You can also use global devices like so:

SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID1];
SinricProSwitch& mySwitch2 = SinricPro[SWITCH_ID2];

...

void setupSinricPro() {
  mySwitch1.onPowerState(onPowerState1);
  mySwitch2.onPowerSTate(onPowerState2);
  ...
}

void handleButtons() {
...
  if (state_1 != lastState_1) {
    mySwitch1.sendPowerStateEvent(state_1);
    lastState_1 = state_1;
  }
...
}

Here are my suggestions:

Bitcraze26 commented 2 years ago

I've removed some libraries: WiFiUdp, Time, NTPClient and now the send event is much more faster, around 300/500 ms for sending.

Maybe WiFiUdp for ntp client was in conflict with the other code!

Sorry because this was the first thing i should to do! However in the next days i will test stability of the system.

Thanks Boris

sivar2311 commented 2 years ago

Ok, so i think the ntp client was the blocking one.

SinricPro provides a unix timestamp (when the connection to SinricPro server has been established):

unsigned long time = SinricPro.getTimestamp();
Bitcraze26 commented 2 years ago

Ok perfect!

But for now i have abandoned the project with esp8266 because i still have problem with connection to Sinric Server this time. It takes about 1 minute when board start. (I will look for this in the next days)

Another question:

I have made a nodejs software on raspberry with Sinric API. Auth works, i can get accessToken, made several request for setContactState for a contact sensor on my door (Xiaomi Aqara Zigbee with zigbee2mqtt and a dongle on my raspberry pi for capture radio signal) but alexa receive it only 1 time and after no more.

response from API request:

sensore porta {"battery":100,"contact":false,"linkquality":23,"temperature":24,"voltage":3015} [REQUEST]: {"success":true,"message":"OK. Il tuo messaggio è stato messo in coda per l'elaborazione."}

All response says that the message will be in queue but in Alexa app i can't get updates..

Thanks!

sivar2311 commented 2 years ago

It takes a few seconds on an esp8266 because of the SSL connection. The ESP8266 is terrible slow on SSL in comparison to an ESP32. But it shouldn't take a minute! For a test, you can disable SSL. For this you have to add #define SINRICPRO_NOSSL before including the library.

I cannot help you with node js questions. For this, please open a new issue in the node js repository.

stale[bot] commented 2 years ago

This issue has gone quiet. Spooky quiet. We currently close issues after 14 days of inactivity. It’s been at least 7 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks for being a part of the SinricPro community!

stale[bot] commented 2 years ago

Hey again! It’s been 14 days since anything happened on this issue, so our friendly robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks again for being a part of the SinricPro community!