You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
#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
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
// 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");
}
}
}
The text was updated successfully, but these errors were encountered:
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 )
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 <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <WebSocketsClient.h> // https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries
#include <ArduinoJson.h> // https://github.com/kakopappa/sinric/wiki/How-to-add-dependency-libraries
#include <StreamString.h>
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
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"];
}
}
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();
}
}
The text was updated successfully, but these errors were encountered: