kakopappa / sinric

Amazon Alexa Smart home skill / Google Home Action for ESP8266 / ESP32 / Arduino
https://sinric.com
285 stars 166 forks source link

the device 'online' field always true with google problem #91

Open mrmojtabaa opened 6 years ago

mrmojtabaa commented 6 years ago

when i get status of my device from google , google request's 'action.devices.QUERY' intent from iot.sinrice.com , the response is something like this

{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "payload": { "devices": { "123456789...": { "online": true, "on": true, "brightness": 100 } } } }

but always the 'online' field is true , even the device not connected to power.

kakopappa commented 6 years ago

sorry about the late response. it's fixed now

mrmojtabaa commented 6 years ago

thanks a lot, but it has a little problem yet ! the 'online' and 'on' fields , have same result ! for example if device is online but i turned off it , the values should be 'online' : true , 'on' : false

but now the result is 'online' : false , 'on' : false

kakopappa commented 6 years ago

You are right. now online status = on/off status which is wrong. I misunderstood earlier. sorry about that

Now there is a new problem. Problem is

  1. ESP devices connect to sinric.com using the API key.
  2. The server knows to which user account this ESP belongs to (api key to account id mapping).
  3. Since the client does not send the device id when connecting, the server cannot check whether the device is connected or not.

We have to send the device id when connecting. Have to look at WebSocket connection headers in ESP whether we can pass the device id and how to pass it.

mrmojtabaa commented 6 years ago

oh yes! you are right i searched in arduinoWebSockets in the WebSocketsClient.h there is a method void setExtraHeaders(const char * extraHeaders = NULL); and there is a sample for it, webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not");

i think we can use it like this , webSocket.setExtraHeaders("deviceId: 123456...");

it is from device , but i don't now how to fetch this data in server side ... !

DonKracho commented 6 years ago

just an idea: You implemented the function void setPowerStateOnServer(String deviceId, String value) in your example.

When the ESP device boots up it has to tell the status of each device id handled by the ESP to keep the Sinric server in sync. Can't we use this functon as heartbeat the ESP has to send in a time intervall of lets say about 15 minutes? And If the Sinric server does not get this 'heartbeat' it handles the device as offline.

Then you will have to specify the heatbeat time in order to keep the Sinric server in an acceptable traffic load.

mrmojtabaa commented 5 years ago

Whats up @kakopappa ? is there any way ?