sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
236 stars 125 forks source link

Switch example not compiling #90

Closed akaith closed 4 years ago

akaith commented 4 years ago

Switch example is not compliling, it is throwing multiple errors

sivar2311 commented 4 years ago

It would be nice if you would include the error messages.

Since the last update there have been changes regarding the ID types. Unfortunately I missed to adjust the changes in the examples. I will update the examples as soon as i can (edit: fixing is done, see below).

For the Switch example only one line has to be adjusted: Delete or change line 84 as follows: Serial.printf("Device %s turned %s (manually via flashbutton)\r\n", mySwitch.getDeviceId().toString().c_str(), myPowerState? "on": "off");

Explanation: In the past, the ID's were stored as C strings. In the newer version the base class SinricProId is used. This class provides the efficient storage of ID numbers like AppKey, AppSecret and DeviceID's. To print these ID numbers by using printf, they must first be converted into a C-string. This is done by calling the method .toString().c_str().

DeviceId deviceId = "5f4fc146f8f3410558954b46";
printf("DeviceId is : %s", deviceId.toString().c_str());

Edit: This issue was only related to switch example. The example has been fixed. Please please see here

Thank you @akaith for pointing this out!

akaith commented 4 years ago

Thanks for the prompt response. That individual program is compiling properly. But when opening switch example in arduino IDE, all 5 switch examples open together and the following errors pop up while compiling:

Arduino: 1.8.13 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\Switch.ino: In function 'void setupSinricPro()':

Switch:108:37: error: no matching function for call to 'SinricProSwitch::onPowerState()'

mySwitch.onPowerState(onPowerState);

                                 ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\Switch.ino:108:37: note: candidate is:

In file included from C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProSwitch.h:11:0,

             from C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\Switch.ino:35:

C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProDevice.h:157:6: note: virtual void SinricProDevice::onPowerState(SinricProDevice::PowerStateCallback)

void SinricProDevice::onPowerState(PowerStateCallback cb) {

  ^

C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProDevice.h:157:6: note: no known conversion for argument 1 from '' to 'SinricProDevice::PowerStateCallback {aka std::function<bool(const String&, bool&)>}'

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_advance.ino: In function 'void setupWiFi()':

MultiSwitch_advance:146:6: error: redefinition of 'void setupWiFi()'

void setupWiFi()

  ^

Switch:91:6: error: 'void setupWiFi()' previously defined here

void setupWiFi() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_advance.ino: In function 'void setupSinricPro()':

MultiSwitch_advance:160:6: error: redefinition of 'void setupSinricPro()'

void setupSinricPro()

  ^

Switch:103:6: error: 'void setupSinricPro()' previously defined here

void setupSinricPro() {

  ^

MultiSwitch_advance:166:39: error: no matching function for call to 'SinricProSwitch::onPowerState()'

 mySwitch.onPowerState(onPowerState);

                                   ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_advance.ino:166:39: note: candidate is:

In file included from C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProSwitch.h:11:0,

             from C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\Switch.ino:35:

C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProDevice.h:157:6: note: virtual void SinricProDevice::onPowerState(SinricProDevice::PowerStateCallback)

void SinricProDevice::onPowerState(PowerStateCallback cb) {

  ^

C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProDevice.h:157:6: note: no known conversion for argument 1 from '' to 'SinricProDevice::PowerStateCallback {aka std::function<bool(const String&, bool&)>}'

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_advance.ino: In function 'void setup()':

MultiSwitch_advance:173:6: error: redefinition of 'void setup()'

void setup()

  ^

Switch:117:6: error: 'void setup()' previously defined here

void setup() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_advance.ino: In function 'void loop()':

MultiSwitch_advance:182:6: error: redefinition of 'void loop()'

void loop()

  ^

Switch:127:6: error: 'void loop()' previously defined here

void loop() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_beginner.ino: In function 'void setupWiFi()':

MultiSwitch_beginner:70:6: error: redefinition of 'void setupWiFi()'

void setupWiFi() {

  ^

Switch:91:6: error: 'void setupWiFi()' previously defined here

void setupWiFi() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_beginner.ino: In function 'void setupSinricPro()':

MultiSwitch_beginner:83:6: error: redefinition of 'void setupSinricPro()'

void setupSinricPro() {

  ^

Switch:103:6: error: 'void setupSinricPro()' previously defined here

void setupSinricPro() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_beginner.ino: In function 'void setup()':

MultiSwitch_beginner:104:6: error: redefinition of 'void setup()'

void setup() {

  ^

Switch:117:6: error: 'void setup()' previously defined here

void setup() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_beginner.ino: In function 'void loop()':

MultiSwitch_beginner:110:6: error: redefinition of 'void loop()'

void loop() {

  ^

Switch:127:6: error: 'void loop()' previously defined here

void loop() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_intermediate.ino: In function 'bool onPowerState(const String&, bool&)':

MultiSwitch_intermediate:50:6: error: redefinition of 'bool onPowerState(const String&, bool&)'

bool onPowerState(const String &deviceId, bool &state) {

  ^

Switch:63:6: error: 'bool onPowerState(const String&, bool&)' previously defined here

bool onPowerState(const String &deviceId, bool &state) {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_intermediate.ino: In function 'void setupWiFi()':

MultiSwitch_intermediate:60:6: error: redefinition of 'void setupWiFi()'

void setupWiFi() {

  ^

Switch:91:6: error: 'void setupWiFi()' previously defined here

void setupWiFi() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_intermediate.ino: In function 'void setupSinricPro()':

MultiSwitch_intermediate:73:6: error: redefinition of 'void setupSinricPro()'

void setupSinricPro() {

  ^

Switch:103:6: error: 'void setupSinricPro()' previously defined here

void setupSinricPro() {

  ^

MultiSwitch_intermediate:77:39: error: no matching function for call to 'SinricProSwitch::onPowerState()'

 mySwitch.onPowerState(onPowerState);

                                   ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_intermediate.ino:77:39: note: candidate is:

In file included from C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProSwitch.h:11:0,

             from C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\Switch.ino:35:

C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProDevice.h:157:6: note: virtual void SinricProDevice::onPowerState(SinricProDevice::PowerStateCallback)

void SinricProDevice::onPowerState(PowerStateCallback cb) {

  ^

C:\Users\akaith\OneDrive\Documents\Arduino\libraries\SinricPro\src/SinricProDevice.h:157:6: note: no known conversion for argument 1 from '' to 'SinricProDevice::PowerStateCallback {aka std::function<bool(const String&, bool&)>}'

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_intermediate.ino: In function 'void setup()':

MultiSwitch_intermediate:87:6: error: redefinition of 'void setup()'

void setup() {

  ^

Switch:117:6: error: 'void setup()' previously defined here

void setup() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\MultiSwitch_intermediate.ino: In function 'void loop()':

MultiSwitch_intermediate:93:6: error: redefinition of 'void loop()'

void loop() {

  ^

Switch:127:6: error: 'void loop()' previously defined here

void loop() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\WeMosD1_mini_relay_shield.ino: At global scope:

WeMosD1_mini_relay_shield:47:6: error: redefinition of 'bool myPowerState'

bool myPowerState = false;

  ^

Switch:47:6: error: 'bool myPowerState' previously defined here

bool myPowerState = false;

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\WeMosD1_mini_relay_shield.ino: In function 'bool onPowerState(const String&, bool&)':

WeMosD1_mini_relay_shield:62:6: error: redefinition of 'bool onPowerState(const String&, bool&)'

bool onPowerState(const String &deviceId, bool &state) {

  ^

Switch:63:6: error: 'bool onPowerState(const String&, bool&)' previously defined here

bool onPowerState(const String &deviceId, bool &state) {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\WeMosD1_mini_relay_shield.ino: In function 'void setupWiFi()':

WeMosD1_mini_relay_shield:70:6: error: redefinition of 'void setupWiFi()'

void setupWiFi() {

  ^

Switch:91:6: error: 'void setupWiFi()' previously defined here

void setupWiFi() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\WeMosD1_mini_relay_shield.ino: In function 'void setupSinricPro()':

WeMosD1_mini_relay_shield:82:6: error: redefinition of 'void setupSinricPro()'

void setupSinricPro() {

  ^

Switch:103:6: error: 'void setupSinricPro()' previously defined here

void setupSinricPro() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\WeMosD1_mini_relay_shield.ino: In function 'void setup()':

WeMosD1_mini_relay_shield:93:6: error: redefinition of 'void setup()'

void setup() {

  ^

Switch:117:6: error: 'void setup()' previously defined here

void setup() {

  ^

C:\Users\akaith\AppData\Local\Temp\arduino_modified_sketch_787134\WeMosD1_mini_relay_shield.ino: In function 'void loop()':

WeMosD1_mini_relay_shield:101:6: error: redefinition of 'void loop()'

void loop() {

  ^

Switch:127:6: error: 'void loop()' previously defined here

void loop() {

  ^

exit status 1

no matching function for call to 'SinricProSwitch::onPowerState()'

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

sivar2311 commented 4 years ago

Please open only one example at a time. Looks like the ArduinoIDE is trying to compile all examples at once, which will lead to compiling errors.

akaith commented 4 years ago

Screenshot (246) The IDE seems to open all of the switch examples together and there is no option to compile individually,nor close the other open examples.

sivar2311 commented 4 years ago

Create a new project, copy & paste the example code.