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
228 stars 121 forks source link

Abrupt compiling issue after update with PlatformIO #265

Closed Arief-AK closed 2 years ago

Arief-AK commented 2 years ago

Hello,

I have been working with SinricPro library for a while now. Initially it was working fine until I recently updated my PlatformIO. When compiling I receive the errors below.

.pio/libdeps/ttgo-t1/SinricPro/src/SinricPro.h:189:3: error: passing 'const SINRICPRO_2_9_17::SinricProSwitch' as 'this' argument discards qualifiers [-fpermissive]

.pio/libdeps/ttgo-t1/SinricPro/src/SinricPro.h:191:3: error: no matching function for call to 'push_back(const SINRICPRO_2_9_17::SinricProSwitch*&)'

.pio/libdeps/ttgo-t1/SinricPro/src/SinricPro.h:191:21: error: invalid conversion from 'const SINRICPRO_2_9_17::SinricProDeviceInterface*' to 'std::vector<SINRICPRO_2_9_17::SinricProDeviceInterface*>::value_type' {aka 'SINRICPRO_2_9_17::SinricProDeviceInterface*'} [-fpermissive]

.pio/libdeps/ttgo-t1/SinricPro/src/SinricPro.h:191:21: error: invalid conversion from 'const SINRICPRO_2_9_17::SinricProDeviceInterface*' to ``'std::vector<SINRICPRO_2_9_17::SinricProDeviceInterface*>::value_type' {aka 'SINRICPRO_2_9_17::SinricProDeviceInterface*'} [-fpermissive]

image

I am not sure what I did in the background for this occur.

Have any ideas to why this could be?

Thanks. Arief.

sivar2311 commented 2 years ago

Did you clean the build directory (PIO CLEAN) after updating PlatformIO ?

Arief-AK commented 2 years ago

Did you clean the build directory (PIO CLEAN) after updating PlatformIO ?

Yes I did perform a PIO CLEAN. Still the same results.

sivar2311 commented 2 years ago

I also updated platformIO to the latest arduino core. No issues here.

Do you have the issues also when using one of the (unmodified) examples?

Arief-AK commented 2 years ago

No issues when compiling the unmodified examples from the repository.

Below is the problems output window from the SinricPro.h file.

image

Below is my PlatformIO configuration file PlatformIO.ini

image

sivar2311 commented 2 years ago

No issues when compiling the unmodified examples from the repository.

So there must be a bug in your code. Hard to say without knowing your code. But it seems to me to be a reference / pointer problem.

Please note that you are working with references to devices! SinricProSwitch& mySwitch = SinricPro[DEVICE_ID]; mySwitch is a reference to an object created and managed by SinricPro.

sivar2311 commented 2 years ago

Taken from your first post: const SINRICPRO_2_9_17::SinricProSwitch

Where does this come from? Are you using const SinricProSwitch somewhere?

Arief-AK commented 2 years ago

No I have not used a const SinricProSwitch in my source code.

The error itself originates from the SinricPro.h that is part of my project library dependencies.

In my source code, I have made a single global instance of the SinricProSwitch using: SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];

I assign a callback function to the appropiate events onConnected() and onDisconnect() similar to the given examples. Then, in multiple stages of my program, I use the sendPowerStateEvent() function from myswitch instance to send the state of my switch. mySwitch.sendPowerStateEvent(myPowerState);

sivar2311 commented 2 years ago

The error itself originates from the SinricPro.h that is part of my project library dependencies.

No, but at this point the error is noticed and the compiler issues a corresponding message.

If the error were in SinricPro.h, the error would also occur in the examples.

Without seeing your code and being able to check it, I cannot help you. The compiler messages alone do not help.

sivar2311 commented 2 years ago

Can you provide your code for analysis?

sivar2311 commented 2 years ago

Great! (I found your repository).

Arief-AK commented 2 years ago

Yeah, here's the link https://github.com/Arief-AK/WakeUpAlarm/blob/main/WakeUpAlarm/src/main.cpp

sivar2311 commented 2 years ago

I found the issue(s) Remove line 114 and 144. You're trying to reassing a reference. This is not possible / not allowed.

Arief-AK commented 2 years ago

Ahh of course!

Trivial mistake, my appologies.

I appreciate your effort and time. Thank you!

sivar2311 commented 2 years ago

No problem. You're welcome :) I'm glad I could help you and the problem is solved.

sivar2311 commented 2 years ago

I think you can also remove line 59 (sendPowerStateEvent). If you want to change the state within a callback, e.g. the device is requested to turn on but it cannot turn on and you want to tell the server that the device is still off, just set the state variable to false. The state variable is a reference (so it can be altered) The the value is passed back to the server after the callback function returns.

Arief-AK commented 2 years ago

I see, I will implement this. Thanks for the feedback!