kakopappa / sinric

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

[WSc] Webservice disconnected from sinric.com! #380

Closed moza23499 closed 4 years ago

moza23499 commented 4 years ago

Cannot connect, getting this only. my code is controlling just a switch (relay) CODE:-

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 led = 5;

ESP8266WiFiMulti WiFiMulti; WebSocketsClient webSocket; WiFiClient client;

define MyApiKey "dd79d3e2-7507-4e59-80c2-d7877a35c48b" // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard

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

define MyWifiPassword "11111111" // 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 == "5df6cab3341b506fe7a2e5da") // Device ID of first device {
Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(led, HIGH); } else { Serial.print("Turn on for unknown device id: "); Serial.println(deviceId);
}
}

void turnOff(String deviceId) { if (deviceId == "5df6cab3341b506fe7a2e5da") // Device ID of first device {
Serial.print("Turn off Device ID: "); Serial.println(deviceId); digitalWrite(led, LOW); } 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);

if ARDUINOJSON_VERSION_MAJOR == 5

    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.parseObject((char*)payload);

endif

if ARDUINOJSON_VERSION_MAJOR == 6

    DynamicJsonDocument json(1024);
    deserializeJson(json, (char*) payload);      

endif

    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 (led, OUTPUT);

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(); if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) { heartbeatTimestamp = now; webSocket.sendTXT("H");
} }

kakopappa commented 4 years ago

Code looks fine. What’s your IP address?

On Mon, 16 Dec 2019 at 7:35 AM moza23499 notifications@github.com wrote:

Cannot connect, getting this only. my code is controlling just a switch (relay) CODE:-

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 led = 5;

ESP8266WiFiMulti WiFiMulti; WebSocketsClient webSocket; WiFiClient client;

define MyApiKey "dd79d3e2-7507-4e59-80c2-d7877a35c48b" // TODO: Change to

your sinric API Key. Your API Key is displayed on sinric.com dashboard

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

define MyWifiPassword "11111111" // 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 == "5df6cab3341b506fe7a2e5da") // Device ID of first device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite(led, HIGH); } else { Serial.print("Turn on for unknown device id: "); Serial.println(deviceId); } }

void turnOff(String deviceId) { if (deviceId == "5df6cab3341b506fe7a2e5da") // Device ID of first device { Serial.print("Turn off Device ID: "); Serial.println(deviceId); digitalWrite(led, LOW); } 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);

if ARDUINOJSON_VERSION_MAJOR == 5

DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.parseObject((char*)payload);

endif

if ARDUINOJSON_VERSION_MAJOR == 6

DynamicJsonDocument json(1024); deserializeJson(json, (char*) payload);

endif

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 (led, OUTPUT);

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(); if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) { heartbeatTimestamp = now; webSocket.sendTXT("H"); } }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kakopappa/sinric/issues/380?email_source=notifications&email_token=ABZAZZS3WNQACFFMD4UHKZTQY3EOLA5CNFSM4J3C4U2KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IATHQWQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZS2PRVSOZG4QHU4DYTQY3EOLANCNFSM4J3C4U2A .

moza23499 commented 4 years ago

my IP is 14.139.240.89

kakopappa commented 4 years ago

i just checked. Your IP is not blocked. Check the internet connection. Try starting a hotspot from your mobile and conneting to sinric via the hotspot

moza23499 commented 4 years ago

Ok Thanks a lot man !!

ab1567 commented 4 years ago

i have same problem keeps disconnecting please check my ip if its blocked please unblock i have used hotspot home wifi both please help 192.168.43.111 hotspot 192.168.1.209 home wifi please unblock if blocked and please help if not blocked i have presentation after 2 days

kakopappa commented 4 years ago

I haven’t blocked anyone for a long time.

Have you tried Sinric Pro? https://sinric.pro

On Sun, 14 Jun 2020 at 4:29 PM ab1567 notifications@github.com wrote:

i have same problem keeps disconnecting please check my ip if its blocked please unblock i have used hotspot home wifi both please help 192.168.43.111 hotspot 192.168.1.209 home wifi please unblock if blocked and please help if not blocked i have presentation after 2 days

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kakopappa/sinric/issues/380#issuecomment-643741695, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZRT3IAXLPSG2KY2453RWSKAJANCNFSM4J3C4U2A .