For now, I’ve web socket connection with iot.sinric.com from my esp8266, but how to add a device in the Google home app?
In the google home app, I see: [test] Sinric, and I tried to log in, it says: “successfully linked your [test] Sinric account”, but after that I still see [test] Sinric under “add new” section, and I don’t have “linked services” section in the app at all.
My code on esp8266 (websocket part)
void webSocketEvent2(WStype_t type, uint8_t * payload, size_t length) {
switch(type) {
case WStype_DISCONNECTED:
isConnected = false;
Serial.printf("[WSc] Webservice disconnected from sinric.com!\n");
break;
case WStype_CONNECTED: {
isConnected = true;
Serial.printf("[WSc] Service connected to sinric.com at url: %s\n", payload);
Serial.printf("Waiting for commands from sinric.com ...\n");
}
break;
case WStype_TEXT: {
Serial.printf("[WSc] get text: %s\n", payload);
// Example payloads
// For Switch types
// {"deviceId":"xxx","action":"action.devices.commands.OnOff","value":{"on":true}}
// https://developers.google.com/actions/smarthome/traits/onoff
// {"deviceId":"xxx","action":"action.devices.commands.OnOff","value":{"on":false}}
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.parseObject((char*)payload);
String deviceId = json ["deviceId"];
String action = json ["action"];
if(action == "action.devices.commands.OnOff") { // Switch
Serial.printf("Got command to control lights from sinric.com ...\n");
String value = json ["value"]["on"];
Serial.println(value);
// ====== Is it ok to call my functions here, like I did? and how to do it correctly ?
if(value == "true") {
changeMainLight(96, 200); // my function to control light, it means turn ON
} else {
changeMainLight(0, 200); // my function to control light, it means turn OFF
}
}
else if (action == "test") {
Serial.println("[WSc] received test command from sinric.com");
}
}
break;
case WStype_BIN:
Serial.printf("[WSc] get binary length: %u\n", length);
break;
}
It says “Waiting for commands from sinric.com” so I think it works, but I still don’t know how to control it.