Closed arduino-nour closed 5 years ago
????
in the serial terminal pic, I can see the on/off commands coming in, looks like your Sinric integration si fine.
If the LED is not working, it's likely to do with the PIN mapping is wrong.
try the on.off on a new sketch with the same pins and check whether it's working
Thank you for your comment All connections are correct You changed the esp 8266 v3 It's working on ESP8266WebServer library Also on the WiFiManager.h library But does not work with Alexa Everything works successfully even if you log on Serial Monitor Gives the code On and OFF and it sends the status of keys on On the mobile, it also gives On and Off from within the Alexa program
Is the code correct?
if (deviceId == "lamp1") <-- wrong
this should be device id. device id is like 5xxxxxxxxxxxxxx
It worked like this
const int ligh1= 16;
void turnOn(String deviceId) {
if (deviceId == "lamp1") // Device ID of first device
{
Serial.print("Turn on device id: ");
Serial.println(deviceId);
digitalWrite (ligh1,HIGH);
}
void setup() {
Serial.begin(115200);
pinMode (ligh1,OUTPUT);
////////////////////////////////////////////////
Do you mean work?
oid turnOn(String deviceId) {
if (deviceId == "5xxxxxxxxxxxxxxxx") // Device ID of first device
{
Serial.print("Turn on device id: ");
Serial.println(deviceId);
digitalWrite (ligh1,HIGH);
}
//////////////////////////////////////////////// All thanks to you my friend
device id is not device name. I hope you got it to work now
kakopappa thank you very much I will work it out and give you the result
@kakopappa thank you my friend The problem has been resolved Now I can call Alexa
oid turnOn(String deviceId) { if (deviceId == "5xxxxxxxxxxxxxxxx") // Device ID of first device { Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite (16,HIGH); }
//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// arduinou.nour@gmai.com ////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
0.0.txt /////////////////////////////////////////////////////////////////
include //this needs to be first, or it all crashes and burns...
include
include
include
include
include // get it from https://github.com/Links2004/arduinoWebSockets/releases
include // get it from https://arduinojson.org/ or install via Arduino library manager
include "WiFiManager.h" //https://github.com/tzapu/WiFiManager
// Issue #18 https://github.com/kakopappa/sinric/issues/18 // If you receive an error like multi_nav_wifi:51: error: 'class WiFiManager' has no member named 'addAP' use // https://github.com/the-real-orca/WiFiManager
WebSocketsClient webSocket; WiFiClient client;
define MyApiKey "xxxxxxxxxxxxxxxxxxxxxxx" // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard
define HEARTBEAT_INTERVAL 300000 // 5 Minutes
define lamp1 "5d344e1b56393964a3c9ba0b"
uint64_t heartbeatTimestamp = 0; bool isConnected = false;
void load(WiFiManager &wifiManager) { //clean FS, for testing // SPIFFS.format();
//read configuration from FS json Serial.println("mounting FS...");
if (SPIFFS.begin()) { if (SPIFFS.exists("/config.json")) { //file exists, reading and loading Serial.println("reading config file"); File configFile = SPIFFS.open("/config.json", "r");
} else { Serial.println("failed to mount FS -> format"); SPIFFS.format(); } }
void save(WiFiManager &wifiManager) { //save the custom parameters to FS if (SPIFFS.begin()) { Serial.println("saving config..."); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); JsonArray& networks = json.createNestedArray("Networks");
} }
//flag for saving data bool shouldSaveConfig = false; //callback notifying us of the need to save config void saveConfigCallback () { shouldSaveConfig = true; }
void turnOn(String deviceId) { if (deviceId == "lamp1") // Device ID of first device {
Serial.print("Turn on device id: "); Serial.println(deviceId); digitalWrite (16,HIGH); } else if (deviceId == "5xxxxxxxxxxxxxxxxxxxxxxxx") // 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 == "lamp1") // Device ID of first device {
Serial.print("Turn off Device ID: "); Serial.println(deviceId); //digitalWrite (16,LOW);
} else if (deviceId == "5xxxxxxxxxxxxxxxxxxxxxxxx") // 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
} }
void setup() { Serial.begin(115200); pinMode (16,OUTPUT); //digitalWrite (16,HIGH);
//WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; //reset settings - for testing wifiManager.resetSettings();
// load known access points load(wifiManager);
//set config save notify callback wifiManager.setSaveConfigCallback(saveConfigCallback);
//fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration if(!wifiManager.autoConnect()) { Serial.println("failed to connect and hit timeout"); //reset and try again, or maybe put it to deep sleep ESP.reset(); delay(1000); }
// save known access points if ( shouldSaveConfig ) save(wifiManager);
//if you get here you have connected to the WiFi Serial.println(); Serial.print("connected to: "); Serial.println(WiFi.SSID()); Serial.print("local ip: "); 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();
}
}
//////////////////////////////////////////////////////////
Lod does not work Even the ESP 8266 V3 does not light up when you press the key What is the problem? Is it in the code? The connection is correct Thank you for your attention /////////////////////////////////////////