Open joykumarsen opened 3 years ago
I'm not able to see any bug in the above code since it looks very similar to my alexa_sinric.ino code.
Please test each section of code separately.
if(action == "setPowerState") { // Switch or Light
String value = json ["value"];
if(value == "ON") {
Serial.println("checking on");
turnOn(deviceId);
} else {
Serial.println("checking off");
turnOff(deviceId);
}
}
Add Serial.println("checking on"); and Serial.println("checking off"); and check if this line gets printed on serial monitor. If this is working, you have to check turnOn and turnOff functions. If this isn't working, Try to rewrite your code with sinric.pro (new version of Sinric) as you might face issue with older version (sinric.com )
Thank you for your quick reply and guidance.
After made the below changes, ON OFF part is working fine. But setBrightness part is stop working (Earlier the scenario was just reverse). you can check the attached Serial monitor screen shot as well for just reference.
As you told there might be issue with older version. Even in the sinric web site I have noticed that the service has been discontinued. let's hope it should work with Sinric Pro!
Hi,
First of all thank you for this tutorial.
can you please help me or guide me to make it work for ESP32 borad. I taken the reference of your code.
issues --- I am not able to turn ON and OFF the lights. lights are getting on only while setting the brightness using Alexa command or Brightness slider in the Alexa app. Once the lights are ON, not able to make the lights OFF.
Your quick reply will be highly appreciable.
Below is the code what i am using for ESP32 board.
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
include
WiFiMulti WiFiMulti; WebSocketsClient webSocket; WiFiClient client;
define MyApiKey "XXXX // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard
define MySSID "XXX" // TODO: Change to your Wifi network SSID
define MyWifiPassword "XXX" // 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;
const int Dev1 = 17; const int Dev2 = 16;
const int freq = 5000; const int ledChannel_0 = 0; const int ledChannel_1 = 1; const int resolution = 8;
void turnOn(String deviceId) { if (deviceId == "60430057c26766757ec0ccd4") // Device ID of first device {
Serial.print("Living Room light is turned on"); ledcWrite(ledChannel_0,HIGH); } else if (deviceId == "60437794c26766757ec0e2c9") // Device ID of second device { Serial.print("Drawing Room Light turned on"); ledcWrite(ledChannel_1,HIGH); }
}
void turnOff(String deviceId) { if (deviceId == "60430057c26766757ec0ccd4") // Device ID of first device {
Serial.print("Living Room Light is turned off"); ledcWrite(ledChannel_0,LOW); } else if (deviceId == "60437794c26766757ec0e2c9") // Device ID of second device { Serial.print("drawing Room Light is turned off"); ledcWrite(ledChannel_1,LOW); }
} void setIntensity(String deviceId,int intensity) { if (deviceId == "60430057c26766757ec0ccd4") // Device ID of redLight {
int mappedIntensity = map(intensity, 0, 100, 0, 255); ledcWrite(ledChannel_0,mappedIntensity); } else if (deviceId == "60437794c26766757ec0e2c9") // Device ID of greenLight { int mappedIntensity = map(intensity, 0, 100, 0, 255); ledcWrite(ledChannel_1,mappedIntensity); } }
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
if ARDUINOJSON_VERSION_MAJOR == 5
endif
if ARDUINOJSON_VERSION_MAJOR == 6
endif
} }
void setup() { Serial.begin(115200);
//pinMode(redlight,OUTPUT); //pinMode(greenlight,OUTPUT);
ledcSetup(ledChannel_0, freq, resolution); ledcSetup(ledChannel_1, freq, resolution); ledcAttachPin(Dev1, ledChannel_0); ledcAttachPin(Dev2, ledChannel_1);
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();
}
}