kakopappa / sinric

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

Not working properly #372

Closed lsgdefault closed 4 years ago

lsgdefault commented 4 years ago

hey so first thing first i would like to thanks developers for making service like sinric for free it help me very much and working stable for past 2-3 months. but yesterday it stopped working i mean alexa was responding okay turned on light and all but it didn't turned on anything so i connected it with my laptop and it gives status like disconnected with sinric web services. for 5-6 hours it was disconnected. after some times i came back to home and checked it so it says connected to web services but now the problem is it gives delay to output and sometime it don't even gives output. i said turn off light and alexa said ok and after 48 seconds it turned off my light so it's not stable now. I want to know it you are closing service because of sinric pro or you are moving server or something. please help me.

kakopappa commented 4 years ago

Hi @lsgdefault

Disconnects are hard to pinpoint where it's coming from. It could be the bad code, ESP, or it could be the router / network provider/ the server. Normally WebSocket library reconnects afaik when disconnection was detected. (disconnection detection normally takes time as well). Make sure you have enabled setReconnectInterval https://github.com/Links2004/arduinoWebSockets/blob/master/examples/esp8266/WebSocketClient/WebSocketClient.ino#L94 and you should do some test on your own and fix these kinds of issues

Sinric is not shutting down soon... however, It's running on a cheap VPS server and resources are limited at the moment. If someone else is flooding the server with on/off requests it will slow down for the rest of the people. There are few issues like this, that's why I created Pro. The server needs to be rewritten with these problems in mind. Please consider moving to Pro. I will update your other question regarding Sinric vs pro

lsgdefault commented 4 years ago

As i said everything is perfect in my code and hardware and that code, hardware and home network worked perfectly for past few months so why it is being problem for me now? And second sinric pro don't give 8 device for free so that's something.

sivar2311 commented 4 years ago

I am running a light on Sinric (non Pro) and have no such issues. Voice commands are handled within 2 seconds without delay. So mabye there are some wifi problems that causing this issue!?

lsgdefault commented 4 years ago

i don't know i didn't change my broadband or something....!!

lsgdefault commented 4 years ago

This is my code if you want to have a look.. ESP8266 with 8 switch relay `/ Version 0.4 - April 26 2019 /

include

include

include

include // https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries

include // https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries (use the correct version)

include

int device_1 = 5; int device_2 = 4; int device_3 = 0; int device_4 = 2; int device_5 = 14; int device_6 = 12; int device_7 = 13; int device_8 = 15;

ESP8266WiFiMulti WiFiMulti; WebSocketsClient webSocket; WiFiClient client;

define MyApiKey "" // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard

define MySSID "Deco Ash" // TODO: Change to your Wifi network SSID

define MyWifiPassword "123123123" // TODO: Change to your Wifi network password

define HEARTBEAT_INTERVAL 300000 // 5 Minutes

uint64_t heartbeatTimestamp = 0; bool isConnected = false;

// deviceId is the ID assgined to your smart-home-device in sinric.com dashboard. Copy it from dashboard and paste it here

void turnOn(String deviceId) { if (deviceId == "") // Device ID of first device {
Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(device_1, LOW); } else if (deviceId == "") // Device ID of second device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(device_2, LOW); } else if (deviceId == "") // Device ID of Third device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(device_3, LOW); } else if (deviceId == "") // Device ID of Fourth device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(device_4, LOW); } else if (deviceId == "") // Device ID of Fifth device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(device_5, LOW); } else if (deviceId == "") // Device ID of Sixth device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(device_6, LOW); } else if (deviceId == "") // Device ID of Seventh device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(device_7, LOW); } else if (deviceId == "") // Device ID of Eighth device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(device_8, LOW); } else { Serial.print("Turn on for unknown device id: "); Serial.println(deviceId);
}
}

void turnOff(String deviceId) { if (deviceId == "") // Device ID of first device {
Serial.print("Turn off device id: "); Serial.println(deviceId); digitalWrite(device_1, HIGH); } else if (deviceId == "") // Device ID of second device { Serial.print("Turn off device id: "); Serial.println(deviceId); digitalWrite(device_2, HIGH); } else if (deviceId == "") // Device ID of Third device { Serial.print("Turn off device id: "); Serial.println(deviceId); digitalWrite(device_3, HIGH); } else if (deviceId == "") // Device ID of Fourth device { Serial.print("Turn off device id: "); Serial.println(deviceId); digitalWrite(device_4, HIGH); } else if (deviceId == "") // Device ID of Fifth device { Serial.print("Turn off device id: "); Serial.println(deviceId); digitalWrite(device_5, HIGH); } else if (deviceId == "") // Device ID of Sixth device { Serial.print("Turn off device id: "); Serial.println(deviceId); digitalWrite(device_6, HIGH); } else if (deviceId == "") // Device ID of Seventh device { Serial.print("Turn off device id: "); Serial.println(deviceId); digitalWrite(device_7, HIGH); } else if (deviceId == "") // Device ID of Eighth device { Serial.print("Turn off device id: "); Serial.println(deviceId); digitalWrite(device_8, HIGH); } else { Serial.print("Turn off for unknown device id: "); Serial.println(deviceId);
}
}

void webSocketEvent(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 or Light device types
    // {"deviceId": xxxx, "action": "setPowerState", value: "ON"} // https://developer.amazon.com/docs/device-apis/alexa-powercontroller.html

    // For Light device type
    // Look at the light example in github

    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.parseObject((char*)payload); 
    String deviceId = json ["deviceId"];     
    String action = json ["action"];

    if(action == "setPowerState") { // Switch or Light
        String value = json ["value"];
        if(value == "ON") {
            turnOn(deviceId);
        } else {
            turnOff(deviceId);
        }
    }
    else if (action == "SetTargetTemperature") {
        String deviceId = json ["deviceId"];     
        String action = json ["action"];
        String value = json ["value"];
    }
    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;

} }

void setup() { Serial.begin(115200); pinMode(device_1, OUTPUT); pinMode(device_2, OUTPUT); pinMode(device_3, OUTPUT); pinMode(device_4, OUTPUT); pinMode(device_5, OUTPUT); pinMode(device_6, OUTPUT); pinMode(device_7, OUTPUT); pinMode(device_8, OUTPUT); digitalWrite(device_1, HIGH); digitalWrite(device_2, HIGH); digitalWrite(device_3, HIGH); digitalWrite(device_4, HIGH); digitalWrite(device_5, HIGH); digitalWrite(device_6, HIGH); digitalWrite(device_7, HIGH); digitalWrite(device_8, HIGH);

WiFiMulti.addAP(MySSID, MyWifiPassword); Serial.println(); Serial.print("Connecting to Wifi: "); Serial.println(MySSID);

// Waiting for Wifi connect while(WiFiMulti.run() != WL_CONNECTED) { delay(500); Serial.print("."); } if(WiFiMulti.run() == WL_CONNECTED) { Serial.println(""); Serial.print("WiFi connected. "); Serial.print("IP address: "); Serial.println(WiFi.localIP()); }

// server address, port and URL webSocket.begin("iot.sinric.com", 80, "/");

// event handler webSocket.onEvent(webSocketEvent); webSocket.setAuthorization("apikey", MyApiKey);

// try again every 5000ms if connection has failed webSocket.setReconnectInterval(5000); // If you see 'class WebSocketsClient' has no member named 'setReconnectInterval' error update arduinoWebSockets }

void loop() { webSocket.loop();

if(isConnected) { uint64_t now = millis();

  // Send heartbeat in order to avoid disconnections during ISP resetting IPs over night. Thanks @MacSass
  if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) {
      heartbeatTimestamp = now;
      webSocket.sendTXT("H");          
  }

}
} `

lsgdefault commented 4 years ago

Suddenly started working don't know what but now working perfectly thanks for your support