Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only one out of three devices is online #241

Closed
nader54 opened this issue Jan 10, 2022 · 18 comments
Closed

Only one out of three devices is online #241

nader54 opened this issue Jan 10, 2022 · 18 comments

Comments

@nader54
Copy link

nader54 commented Jan 10, 2022

Sinricpro dashboard showing only one out of three devices is online. I have deleted and created three device ten times, still only one is online Screen Shot 2022-01-10 at 3.31.38 PM.png

@nader54 nader54 changed the title Jan 10, 2022
@nader54
Copy link
Author

nader54 commented Jan 10, 2022

Screen Shot 2022-01-10 at 3 31 38 PM

@nader54 nader54 changed the title Jan 10, 2022
@kakopappa
Copy link
Contributor

kakopappa commented Jan 11, 2022 via email

@kakopappa kakopappa transferred this issue from sinricpro/help-docs Jan 11, 2022
@kakopappa
Copy link
Contributor

kakopappa commented Jan 11, 2022

@nader54 here's the fixed code.

You have to add multiple devices, if you add a single device, only single device is online

// Uncomment the following line to enable serial debug output
//#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG
       #define DEBUG_ESP_PORT Serial
       #define NODEBUG_WEBSOCKETS
       #define NDEBUG
#endif 

#include <Arduino.h>
#ifdef ESP8266 
       #include <ESP8266WiFi.h>
#endif 
#ifdef ESP32   
       #include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProGarageDoor.h"

#define WIFI_SSID         ""    
#define WIFI_PASS         ""
#define APP_KEY           ""      
#define APP_SECRET        ""   

#define GARAGEDOOR_ID1    ""    // Toyota Garage
#define GARAGEDOOR_ID2    ""   // BMW Garage 
#define GARAGEDOOR_ID3    ""    // Lamborghini Garage


#define BAUD_RATE         9600                     // Change baudrate to your need


bool onDoorState(const String& deviceId, bool &doorState) {
  Serial.printf("Garagedoor is %s now.\r\n", doorState?"closed":"open");
  return true;
}

void setupWiFi() {
  Serial.printf("\r\n[Wifi]: Connecting");
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.printf(".");
    delay(250);
  }
  IPAddress localIP = WiFi.localIP();
  Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
}

void setupSinricPro() {
  SinricProGarageDoor &myGarageDoor1 = SinricPro[GARAGEDOOR_ID1];
  myGarageDoor1.onDoorState(onDoorState);

  SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID2];
  myGarageDoor2.onDoorState(onDoorState);

  SinricProGarageDoor &myGarageDoor3 = SinricPro[GARAGEDOOR_ID3];
  myGarageDoor3.onDoorState(onDoorState);

  // setup SinricPro
  SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); 
  SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
  SinricPro.begin(APP_KEY, APP_SECRET);
}

void setup() {
  Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
  setupWiFi();
  setupSinricPro();
}

void loop() {
  SinricPro.handle();
}

@kakopappa kakopappa changed the title Sinricpro dashboard showing only one out of three devices is online. I have deleted and created three device ten times, still only one is online. Only one out of three devices is online Jan 11, 2022
@nader54
Copy link
Author

nader54 commented Jan 11, 2022 via email

@nader54
Copy link
Author

nader54 commented Jan 12, 2022 via email

@sivar2311
Copy link
Collaborator

sivar2311 commented Jan 12, 2022

Hi @nader54!

It sounds like your devices are assigned to different AppKey / AppSecret pair.
If you're running mulitple devices on the same ESP module all devices must be assigned to the same AppKey / AppSecret.
Please check in devices tab (dashboard) that all your devices (which are running on the same ESP module) assigned to the correct AppKey.

Only use different AppKey / AppSecret pairs if your (logical) devices are running on different ESP modules (physical devices).

@nader54
Copy link
Author

nader54 commented Jan 12, 2022 via email

@sivar2311
Copy link
Collaborator

sivar2311 commented Jan 12, 2022

Please see my code.

Your current sketch is missing. The latest code i can see is the one Aruna posted.
I suggest not to reply via email. Instead post directly on git issues

You have two options

  • Option1: Implement different onDoorState functions (onDoorState1, onDoorState2, onDoorState3) and assign them to the different devices.
    Short example how this works:
bool onDoorState1(const String& deviceId, bool& state) {
  // do whatever when door 1 state changes
  return true;
}

bool onDoorState2(const String& deviceId, bool& state) {
  // do whatever when door 2 state changes
  return true;
}

bool onDoorState3(const String& deviceId, bool& state) {
  // do whatever when door 3 state changes
  return true;
}

void setupSinricPro() {
...
  SinricProGarageDoor &myGarageDoor1 = SinricPro[GARAGEDOOR_ID1];
  myGarageDoor1.onDoorState(onDoorState1);

  SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID2];
  myGarageDoor2.onDoorState(onDoorState2);

  SinricProGarageDoor &myGarageDoor3 = SinricPro[GARAGEDOOR_ID3];
  myGarageDoor3.onDoorState(onDoorState3);
...
}
  • Option 2: Implement one onDoorState function that checks the used deviceId.
bool onDoorState(const String& deviceId, bool& state) {

  if (deviceId == GARAGEDOOR_ID1 {
    // do whatever when door 1 state changes
   return true;
  }

  if (deviceId == GARAGEDOOR_ID2 {
    // do whatever when door 1 state changes
   return true;
  }

  if (deviceId == GARAGEDOOR_ID3 {
    // do whatever when door 1 state changes
   return true;
  }

  return false; // none of the deviceId's matched -> error!
}

void setupSinricPro() {
...
  SinricProGarageDoor &myGarageDoor1 = SinricPro[GARAGEDOOR_ID1];
  myGarageDoor1.onDoorState(onDoorState);

  SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID2];
  myGarageDoor2.onDoorState(onDoorState);

  SinricProGarageDoor &myGarageDoor3 = SinricPro[GARAGEDOOR_ID3];
  myGarageDoor3.onDoorState(onDoorState);
...
}

Updatet: fixed copy & paste bug in option2

@sivar2311
Copy link
Collaborator

Sorry, i had a copy & paste bug in option 2.
I updated my previous post.

@nader54
Copy link
Author

nader54 commented Jan 12, 2022

Hi.
Your option one did not work, and option two is giving me an error.
Arduino: 1.8.13 (Mac OS X), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Alexa_Garage_New_Code:68:6: error: ambiguating new declaration of 'void onDoorState(const String&, bool&)'
68 | void onDoorState(const String& deviceId, bool& state) {
| ^~~~~~~~~~~

@nader54
Copy link
Author

nader54 commented Jan 12, 2022

Both options are giving me an error.

Alexa_Garage_New_Code:68:6: error: ambiguating new declaration of 'void onDoorState(const String&, bool&)'
68 | void onDoorState(const String& deviceId, bool& state) {

@sivar2311
Copy link
Collaborator

sivar2311 commented Jan 12, 2022

Have a closer look at the numbers behind the functions! There are 3 different functions in option 1:

bool onDoorState1(...
bool onDoorState2(...
bool onDoorState3(...

You cannot have 3 functions with the same name like
bool onDoorState(...
bool onDoorState(...
bool onDoorState(...
This is what the compiler complains about.

@kakopappa
Copy link
Contributor

kakopappa commented Jan 12, 2022

// Uncomment the following line to enable serial debug output
//#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG
       #define DEBUG_ESP_PORT Serial
       #define NODEBUG_WEBSOCKETS
       #define NDEBUG
#endif 

#include <Arduino.h>
#ifdef ESP8266 
       #include <ESP8266WiFi.h>
#endif 
#ifdef ESP32   
       #include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProGarageDoor.h"

#define WIFI_SSID         ""    
#define WIFI_PASS         ""
#define APP_KEY           ""      
#define APP_SECRET        ""   

#define GARAGEDOOR_ID1    ""    // Toyota Garage
#define GARAGEDOOR_ID2    ""   // BMW Garage 
#define GARAGEDOOR_ID3    ""    // Lamborghini Garage


#define BAUD_RATE         9600                     // Change baudrate to your need


bool onDoorState1(const String& deviceId, bool& state) {
  // do whatever when door 1 state changes
  return true;
}

bool onDoorState2(const String& deviceId, bool& state) {
  // do whatever when door 2 state changes
  return true;
}

bool onDoorState3(const String& deviceId, bool& state) {
  // do whatever when door 3 state changes
  return true;
}

void setupWiFi() {
  Serial.print("[WiFi]: Connecting");
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(250);
  }

  Serial.println("connected!");
  Serial.printf("[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
}

void setupSinricPro() {
  SinricProGarageDoor& myGarageDoor1 = SinricPro[GARAGEDOOR_ID1];
  myGarageDoor1.onDoorState(onDoorState1);

  SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID2];
  myGarageDoor2.onDoorState(onDoorState2);

  SinricProGarageDoor &myGarageDoor3 = SinricPro[GARAGEDOOR_ID3];
  myGarageDoor3.onDoorState(onDoorState3);

  // setup SinricPro
  SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); 
  SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
  SinricPro.begin(APP_KEY, APP_SECRET);
}

void setup() {
  Serial.begin(BAUD_RATE); 
  Serial.println();
  setupWiFi();
  setupSinricPro();
}

void loop() {
  SinricPro.handle();
}

@nader54
Copy link
Author

nader54 commented Jan 12, 2022

I tested your code this morning and I got these error messages
<img width="1382" alt="Screen Shot 2022-01-12 at 1 15 03 PM" src="https://user-images.githubusercontent.com/3778135/149222675-6333b806-6747-469a-8fc5
Screen Shot 2022-01-12 at 1 17 17 PM
-015e3faed8ec.png">
.

@sivar2311
Copy link
Collaborator

sivar2311 commented Jan 12, 2022

The return type of the callback functions must be bool not void - sorry for this confusion.

Here is the correct sketch:

// Uncomment the following line to enable serial debug output
//#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG
       #define DEBUG_ESP_PORT Serial
       #define NODEBUG_WEBSOCKETS
       #define NDEBUG
#endif 

#include <Arduino.h>
#ifdef ESP8266 
       #include <ESP8266WiFi.h>
#endif 
#ifdef ESP32   
       #include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProGarageDoor.h"

#define WIFI_SSID         ""    
#define WIFI_PASS         ""
#define APP_KEY           ""      
#define APP_SECRET        ""   

#define GARAGEDOOR_ID1    ""    // Toyota Garage
#define GARAGEDOOR_ID2    ""   // BMW Garage 
#define GARAGEDOOR_ID3    ""    // Lamborghini Garage


#define BAUD_RATE         9600                     // Change baudrate to your need


bool onDoorState1(const String& deviceId, bool& state) {
  // do whatever when door 1 state changes
  return true;
}

bool onDoorState2(const String& deviceId, bool& state) {
  // do whatever when door 2 state changes
  return true;
}

bool onDoorState3(const String& deviceId, bool& state) {
  // do whatever when door 3 state changes
  return true;
}

void setupWiFi() {
  Serial.print("[WiFi]: Connecting");
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(250);
  }

  Serial.println("connected!");
  Serial.printf("[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
}

void setupSinricPro() {
  SinricProGarageDoor& myGarageDoor1 = SinricPro[GARAGEDOOR_ID1];
  myGarageDoor1.onDoorState(onDoorState1);

  SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID2];
  myGarageDoor2.onDoorState(onDoorState2);

  SinricProGarageDoor &myGarageDoor3 = SinricPro[GARAGEDOOR_ID3];
  myGarageDoor3.onDoorState(onDoorState3);

  // setup SinricPro
  SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); 
  SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
  SinricPro.begin(APP_KEY, APP_SECRET);
}

void setup() {
  Serial.begin(BAUD_RATE); 
  Serial.println();
  setupWiFi();
  setupSinricPro();
}

void loop() {
  SinricPro.handle();
}

Please not that this sketch has no function.

@nader54
Copy link
Author

nader54 commented Jan 12, 2022

it only work for myGarageDoor2, when I press other buttons nothing happens and i get this on my Serial monitor: load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v000653d0
~ld

WiFi: IP-Address is 10.0.1.6
Connected to SinricPro

@nader54
Copy link
Author

nader54 commented Jan 12, 2022

This is the code I am using.

#include <Arduino.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#endif
#ifdef ESP32
#include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProGarageDoor.h"

#define WIFI_SSID ""
#define WIFI_PASS ""
#define APP_KEY "
"
#define APP_SECRET "
***"

#define GARAGEDOOR_ID1 "61de71c37c2a5a7bcddbbc57" // Toyota Garage
#define GARAGEDOOR_ID2 "61de7189b484c17bc567d364" // BMW Garage
#define GARAGEDOOR_ID3 "61de6f4eb484c17bc567d323" // Lamborghini Garage

#define BAUD_RATE 115200

bool onDoorState1(const String& deviceId, bool &doorState) {
Serial.printf("Garagedoor is %s now.\r\n", doorState?"closed":"open");

if(GARAGEDOOR_ID1== "61de6f4eb484c17bc567d323" ){ // Lamborghini Garage
Serial.print("Lamborghini Garage is open");
Serial.println(GARAGEDOOR_ID1);
digitalWrite(D1,HIGH);
delay(1000);
digitalWrite(D1,LOW);
return true;
}

}
bool onDoorState2(const String& deviceId, bool &doorState) {
Serial.printf("Garagedoor is %s now.\r\n", doorState?"closed":"open");

if (GARAGEDOOR_ID2 == "61de7189b484c17bc567d364"){ // BMW Garage
Serial.print("BMW Garage is open");
Serial.println(GARAGEDOOR_ID2);
digitalWrite(D7,HIGH);
delay(1000);
digitalWrite(D7,LOW);
return true;
}

}
bool onDoorState3(const String& deviceId, bool &doorState) {
Serial.printf("Garagedoor is %s now.\r\n", doorState?"closed":"open");

if (GARAGEDOOR_ID3 == "61de71c37c2a5a7bcddbbc57"){ // Toyota Garage
Serial.print("Toyota Garage is open");
Serial.println(GARAGEDOOR_ID3);
digitalWrite(D2,HIGH);
delay(1000);
digitalWrite(D2,LOW);
return true;
}

}

void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);

while (WiFi.status() != WL_CONNECTED) {
Serial.printf(".");
delay(250);
}
IPAddress localIP = WiFi.localIP();
Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
}

void setupSinricPro() {
SinricProGarageDoor &myGarageDoor1 = SinricPro[GARAGEDOOR_ID1];
myGarageDoor1.onDoorState(onDoorState1);

SinricProGarageDoor &myGarageDoor2 = SinricPro[GARAGEDOOR_ID2];
myGarageDoor2.onDoorState(onDoorState2);

SinricProGarageDoor &myGarageDoor3 = SinricPro[GARAGEDOOR_ID3];
myGarageDoor3.onDoorState(onDoorState3);

SinricPro.onConnected({ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected({ Serial.printf("Disconnected from SinricPro\r\n"); });
SinricPro.begin(APP_KEY, APP_SECRET);
}

void setup() {
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
pinMode(D1,OUTPUT);
pinMode(D7,OUTPUT);
pinMode(D2,OUTPUT);

setupWiFi();
setupSinricPro();
}

void loop() {
SinricPro.handle();
}

@nader54
Copy link
Author

nader54 commented Jan 12, 2022

I figuer it out!!!
Thank you so much for your help!!!
Have great day!

@nader54 nader54 closed this as completed Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants