kakopappa / sinric

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

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

Open bckslyr2003 opened 3 years ago

bckslyr2003 commented 3 years ago

hello i keep getting this error can you check if my public i.p is blocked ? says its offline at sinric pro 23.105.163.103 Waiting for commands from sinric.com ... [WSc] Webservice disconnected from sinric.com! [WSc] Service connected to sinric.com at url: / Waiting for commands from sinric.com ...

/ Version 0.1 - Feb 10 2018 /

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

ESP8266WiFiMulti WiFiMulti; WebSocketsClient webSocket; WiFiClient client;

define MyApiKey "3e73aa72---****-21a4c4fa40ee" // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard

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

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

define API_ENDPOINT "http://sinric.com"

define HEARTBEAT_INTERVAL 300000 // 5 Minutes

uint64_t heartbeatTimestamp = 0; bool isConnected = false;

void turnOn(String deviceId) { if (deviceId == "5axxxxxxxxxxxxxxxxxxx") // Device ID of first device {
Serial.print("Turn on device id: "); Serial.println(deviceId);
} else if (deviceId == "5axxxxxxxxxxxxxxxxxxx") // Device ID of second device { Serial.print("Turn on device id: "); Serial.println(deviceId); } else { Serial.print("Turn on for unknown device id: "); Serial.println(deviceId);
}
}

void turnOff(String deviceId) { if (deviceId == "5axxxxxxxxxxxxxxxxxxx") // Device ID of first device {
Serial.print("Turn off Device ID: "); Serial.println(deviceId);
} else if (deviceId == "5axxxxxxxxxxxxxxxxxxx") // Device ID of second device { Serial.print("Turn off Device ID: "); Serial.println(deviceId); } 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 Light device type
    // {"deviceId": xxxx, "action": "setPowerState", value: "ON"} // https://developer.amazon.com/docs/device-apis/alexa-powercontroller.html
    // {"deviceId": xxxx, "action": "AdjustBrightness", value: 3} // https://developer.amazon.com/docs/device-apis/alexa-brightnesscontroller.html
    // {"deviceId": xxxx, "action": "setBrightness", value: 42} // https://developer.amazon.com/docs/device-apis/alexa-brightnesscontroller.html
    // {"deviceId": xxxx, "action": "SetColor", value: {"hue": 350.5,  "saturation": 0.7138, "brightness": 0.6501}} // https://developer.amazon.com/docs/device-apis/alexa-colorcontroller.html
    // {"deviceId": xxxx, "action": "DecreaseColorTemperature"} // https://developer.amazon.com/docs/device-apis/alexa-colortemperaturecontroller.html
    // {"deviceId": xxxx, "action": "IncreaseColorTemperature"} // https://developer.amazon.com/docs/device-apis/alexa-colortemperaturecontroller.html
    // {"deviceId": xxxx, "action": "SetColorTemperature", value: 2200} // https://developer.amazon.com/docs/device-apis/alexa-colortemperaturecontroller.html

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 == "SetColor") {
        // Alexa, set the device name to red
        // get text: {"deviceId":"xxxx","action":"SetColor","value":{"hue":0,"saturation":1,"brightness":1}}
        String hue = json ["value"]["hue"];
        String saturation = json ["value"]["saturation"];
        String brightness = json ["value"]["brightness"];

        Serial.println("[WSc] hue: " + hue);
        Serial.println("[WSc] saturation: " + saturation);
        Serial.println("[WSc] brightness: " + brightness);
    }
    else if(action == "SetBrightness") {

    }
    else if(action == "AdjustBrightness") {

    }
    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;
default: break;

} }

void setup() { Serial.begin(115200);

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");          
  }

}
}

kakopappa commented 3 years ago

This ip is not blocked. Are you using Sinric.com or Sinric.pro?

bckslyr2003 commented 3 years ago

Sinric pro website .so I guess I need to change url?

kakopappa commented 3 years ago

This sketch doesn't work on pro.

You have to use the Sinric Pro SDK in Sinric Pro to connect your ESP devices https://github.com/sinricpro/esp8266-esp32-sdk

Use an example and modify the sample code https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples

On Tue, Dec 8, 2020 at 12:17 PM bckslyr2003 notifications@github.com wrote:

Sinric pro website .so I guess I need to change url?

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

bckslyr2003 commented 3 years ago

with the new examples this is all i get from my board lol ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d vac02aff5 ~ld

kakopappa commented 3 years ago

@bckslyr2003 try updating the ESP Core version

image

bckslyr2003 commented 3 years ago

that worked thankyou