jit06 / RflinkToJsonMqtt

Arduino sketch to send RFlink output to JSON MQTT server
GNU General Public License v3.0
2 stars 1 forks source link

Code does not compile #3

Closed ajongen closed 6 months ago

ajongen commented 1 year ago

I have a problem with compiling the RflinkToJsonMqtt sketch. My Common.h looks like (only defined the MQTT_SERVER_IP): +++++++++ // MQTT Server IP

define MQTT_SERVER_IP (192, 168, 178, 2)

// MQTT Server name //#define MQTT_SERVER_NAME “mqtt.local.lan” // MQTT Server mode : comment out to use MQTT_SERVER_IP instead of MQTT_SERVER_NAME //#define MQTT_SERVER_MODE_DNS +++++++++

But when compiling I get an error that there are multiple definitions of ‘SERVER’ …. See the output below:

++++++++++ Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: “LOLIN(WEMOS) D1 R2 & mini, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600”

Multiple libraries were found for “PubSubClient.h” Used: C:\Users\arman\OneDrive\Documenten\Arduino\libraries\PubSubClient Not used: C:\Users\arman\OneDrive\Documenten\Arduino\libraries\ESP8266_Microgear

c:/users/arman/onedrive/documenten/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\RflinkToJsonMqtt.ino.cpp.o:C:\Users\arman\OneDrive\Documenten\Arduino\RFLinkMQTT\RflinkToJsonMqtt/Mqtt.h:15: multiple definition of `SERVER’; sketch\Mqtt.cpp.o:C:\Users\arman\OneDrive\Documenten\Arduino\RFLinkMQTT\RflinkToJsonMqtt/Mqtt.h:15: first defined here

collect2.exe: error: ld returned 1 exit status exit status 1 Error compiling for board LOLIN(WEMOS) D1 R2 & mini. ++++++++++++++++

Any ideas what could be wrong? Which versions of the ESP8266 Board library are you using?

Thanks for the help!

Armand

ajongen commented 1 year ago

I digged a little bit deeper and found this page:

https://community.platformio.org/t/why-error-multiple-definition/23069/2

where the same error (in different code) was described. Following the guidelines I moved the SERVER declaration code from Mqtt.h to Mqtt.cpp and now it compiles OK. Correct working is not yet tested.

+++++++++++++++ /*

jit06 commented 1 year ago

Thank you for your feeback. I have not yet re-tested the code, but did you commented out the definition of MQTT_SERVER_MODE_DNS in common.h ? I'm asking because I did not test the code without this definition since a long time now, because I always use my local DNS to connect to my mqtt server...

ajongen commented 1 year ago

Hi Julien,

Thanks for your reply. Yes I just used a direct (fixed) IP to connect to my MQTT server but that is not what was causing the compilation error. That was created by a duplicate declaration of SERVER, solved by putting:

ifdef MQTT_SERVER_MODE_DNS

const char SERVER[] = MQTT_SERVER_NAME;

else

IPAddress SERVER MQTT_SERVER_IP ;

endif

in Mqtt.cpp instead of Mqtt.h. I guess the multiple declaration error is induced by the fact that you include most of the .h files in all the .cpp files. It compiles OK now. Now I am trying to get the whole thing working in my domoticz environment. Fingers crossed ;-)

Greetings, Armand

Op ma 17 apr 2023 om 15:37 schreef Julien @.***>:

Thank you for your feeback. I have not yet re-tested the code, but did you commented out the definition of MQTT_SERVER_MODE_DNS in common.h ? I'm asking because I did not test the code without this definition since a long time now, because I always use my local DNS to connect to my mqtt server...

— Reply to this email directly, view it on GitHub https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1511365074, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXNMJ7DEFFRXA74MO6LSTVDXBVBSFANCNFSM6AAAAAAW77O34U . You are receiving this because you authored the thread.Message ID: @.***>

ajongen commented 1 year ago

Hi Julien,

In addition I posted something to your https://www.bluemind.org/rflink-mqtt-v2-enhanced-minimized website asking about wiring. Did you see that already? I have the code compiling OK now and able to install it on the WEMOS D1 mini but when I power the Wemos via the Mega and plug in the Mega, the Wemos seems to get stuck....

Any help would be appreciated.

Cheers, Armand

Op wo 19 apr 2023 om 11:26 schreef Armand Jongen @.***>:

Hi Julien,

Thanks for your reply. Yes I just used a direct (fixed) IP to connect to my MQTT server but that is not what was causing the compilation error. That was created by a duplicate declaration of SERVER, solved by putting:

ifdef MQTT_SERVER_MODE_DNS

const char SERVER[] = MQTT_SERVER_NAME;

else

IPAddress SERVER MQTT_SERVER_IP ;

endif

in Mqtt.cpp instead of Mqtt.h. I guess the multiple declaration error is induced by the fact that you include most of the .h files in all the .cpp files. It compiles OK now. Now I am trying to get the whole thing working in my domoticz environment. Fingers crossed ;-)

Greetings, Armand

Op ma 17 apr 2023 om 15:37 schreef Julien @.***>:

Thank you for your feeback. I have not yet re-tested the code, but did you commented out the definition of MQTT_SERVER_MODE_DNS in common.h ? I'm asking because I did not test the code without this definition since a long time now, because I always use my local DNS to connect to my mqtt server...

— Reply to this email directly, view it on GitHub https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1511365074, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXNMJ7DEFFRXA74MO6LSTVDXBVBSFANCNFSM6AAAAAAW77O34U . You are receiving this because you authored the thread.Message ID: @.***>

jit06 commented 1 year ago

Hmm, I need to check why it does not compile without modification when using direct IP connection. also, I juste saw you comment on my blog, you're right it seems that there is something inconsistent. Let me check physically before replying ;)

https://www.bluemind.org

https://www.pimyretro.org

https://www.youtube.com/user/jtiphaine1/playlists

On Thu, Apr 20, 2023 at 5:53 PM ajongen @.***> wrote:

Hi Julien,

In addition I posted something to your https://www.bluemind.org/rflink-mqtt-v2-enhanced-minimized website asking about wiring. Did you see that already? I have the code compiling OK now and able to install it on the WEMOS D1 mini but when I power the Wemos via the Mega and plug in the Mega, the Wemos seems to get stuck....

Any help would be appreciated.

Cheers, Armand

Op wo 19 apr 2023 om 11:26 schreef Armand Jongen @.***>:

Hi Julien,

Thanks for your reply. Yes I just used a direct (fixed) IP to connect to my MQTT server but that is not what was causing the compilation error. That was created by a duplicate declaration of SERVER, solved by putting:

ifdef MQTT_SERVER_MODE_DNS

const char SERVER[] = MQTT_SERVER_NAME;

else

IPAddress SERVER MQTT_SERVER_IP ;

endif

in Mqtt.cpp instead of Mqtt.h. I guess the multiple declaration error is induced by the fact that you include most of the .h files in all the .cpp files. It compiles OK now. Now I am trying to get the whole thing working in my domoticz environment. Fingers crossed ;-)

Greetings, Armand

Op ma 17 apr 2023 om 15:37 schreef Julien @.***>:

Thank you for your feeback. I have not yet re-tested the code, but did you commented out the definition of MQTT_SERVER_MODE_DNS in common.h ? I'm asking because I did not test the code without this definition since a long time now, because I always use my local DNS to connect to my mqtt server...

— Reply to this email directly, view it on GitHub < https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1511365074 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AXNMJ7DEFFRXA74MO6LSTVDXBVBSFANCNFSM6AAAAAAW77O34U

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1516572480, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACJ6L4X2A7NOX7ENNMEKNCDXCFLYVANCNFSM6AAAAAAW77O34U . You are receiving this because you commented.Message ID: @.***>

jit06 commented 1 year ago

I corrected the article, you're right the STX is powerered by D15 :) I still not tried to compile with the same option as you, I hope to be able to do so tomorow night

https://www.bluemind.org

https://www.pimyretro.org

https://www.youtube.com/user/jtiphaine1/playlists

On Thu, Apr 27, 2023 at 6:16 PM julien @.***> wrote:

Hmm, I need to check why it does not compile without modification when using direct IP connection. also, I juste saw you comment on my blog, you're right it seems that there is something inconsistent. Let me check physically before replying ;)

  • Julien -

https://www.bluemind.org

https://www.pimyretro.org

https://www.youtube.com/user/jtiphaine1/playlists

On Thu, Apr 20, 2023 at 5:53 PM ajongen @.***> wrote:

Hi Julien,

In addition I posted something to your https://www.bluemind.org/rflink-mqtt-v2-enhanced-minimized website asking about wiring. Did you see that already? I have the code compiling OK now and able to install it on the WEMOS D1 mini but when I power the Wemos via the Mega and plug in the Mega, the Wemos seems to get stuck....

Any help would be appreciated.

Cheers, Armand

Op wo 19 apr 2023 om 11:26 schreef Armand Jongen @.***>:

Hi Julien,

Thanks for your reply. Yes I just used a direct (fixed) IP to connect to my MQTT server but that is not what was causing the compilation error. That was created by a duplicate declaration of SERVER, solved by putting:

ifdef MQTT_SERVER_MODE_DNS

const char SERVER[] = MQTT_SERVER_NAME;

else

IPAddress SERVER MQTT_SERVER_IP ;

endif

in Mqtt.cpp instead of Mqtt.h. I guess the multiple declaration error is induced by the fact that you include most of the .h files in all the .cpp files. It compiles OK now. Now I am trying to get the whole thing working in my domoticz environment. Fingers crossed ;-)

Greetings, Armand

Op ma 17 apr 2023 om 15:37 schreef Julien @.***>:

Thank you for your feeback. I have not yet re-tested the code, but did you commented out the definition of MQTT_SERVER_MODE_DNS in common.h ? I'm asking because I did not test the code without this definition since a long time now, because I always use my local DNS to connect to my mqtt server...

— Reply to this email directly, view it on GitHub < https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1511365074 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AXNMJ7DEFFRXA74MO6LSTVDXBVBSFANCNFSM6AAAAAAW77O34U

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1516572480, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACJ6L4X2A7NOX7ENNMEKNCDXCFLYVANCNFSM6AAAAAAW77O34U . You are receiving this because you commented.Message ID: @.***>

ajongen commented 1 year ago

Hi Julien,

I managed to compile the code and it runs OK. However, when using the D7 and D8 on the Wemos as Serial and connect it to the Mega, the Wemos will no longer boot. That is due to the fact that D8 needs to be LOW on boot. See:

https://espeasy.readthedocs.io/en/latest/Reference/GPIO.html

So I needed to use D4 for TX and set the #define USE_SERIAL1_TX. That then worked.

But I am a bit confused why you do not just use the normal TX/RX pins for connection with the MEGA? Why wouldn't you do that? But for now all works well.

Cheers, Armand

Op zo 30 apr 2023 om 23:07 schreef Julien @.***>:

I corrected the article, you're right the STX is powerered by D15 :) I still not tried to compile with the same option as you, I hope to be able to do so tomorow night

  • Julien -

https://www.bluemind.org

https://www.pimyretro.org

https://www.youtube.com/user/jtiphaine1/playlists

On Thu, Apr 27, 2023 at 6:16 PM julien @.***> wrote:

Hmm, I need to check why it does not compile without modification when using direct IP connection. also, I juste saw you comment on my blog, you're right it seems that there is something inconsistent. Let me check physically before replying ;)

  • Julien -

https://www.bluemind.org

https://www.pimyretro.org

https://www.youtube.com/user/jtiphaine1/playlists

On Thu, Apr 20, 2023 at 5:53 PM ajongen @.***> wrote:

Hi Julien,

In addition I posted something to your https://www.bluemind.org/rflink-mqtt-v2-enhanced-minimized website asking about wiring. Did you see that already? I have the code compiling OK now and able to install it on the WEMOS D1 mini but when I power the Wemos via the Mega and plug in the Mega, the Wemos seems to get stuck....

Any help would be appreciated.

Cheers, Armand

Op wo 19 apr 2023 om 11:26 schreef Armand Jongen @.***>:

Hi Julien,

Thanks for your reply. Yes I just used a direct (fixed) IP to connect to my MQTT server but that is not what was causing the compilation error. That was created by a duplicate declaration of SERVER, solved by putting:

ifdef MQTT_SERVER_MODE_DNS

const char SERVER[] = MQTT_SERVER_NAME;

else

IPAddress SERVER MQTT_SERVER_IP ;

endif

in Mqtt.cpp instead of Mqtt.h. I guess the multiple declaration error is induced by the fact that you include most of the .h files in all the .cpp files. It compiles OK now. Now I am trying to get the whole thing working in my domoticz environment. Fingers crossed ;-)

Greetings, Armand

Op ma 17 apr 2023 om 15:37 schreef Julien @.***>:

Thank you for your feeback. I have not yet re-tested the code, but did you commented out the definition of MQTT_SERVER_MODE_DNS in common.h ? I'm asking because I did not test the code without this definition since a long time now, because I always use my local DNS to connect to my mqtt server...

— Reply to this email directly, view it on GitHub <

https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1511365074

,

or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AXNMJ7DEFFRXA74MO6LSTVDXBVBSFANCNFSM6AAAAAAW77O34U

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1516572480 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ACJ6L4X2A7NOX7ENNMEKNCDXCFLYVANCNFSM6AAAAAAW77O34U

. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/jit06/RflinkToJsonMqtt/issues/3#issuecomment-1529139515, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXNMJ7A32M3QR44YEBBEUUTXD3H73ANCNFSM6AAAAAAW77O34U . You are receiving this because you authored the thread.Message ID: @.***>

jit06 commented 1 year ago

Cool if you manage to get it working. You are absolutely right for d8, that exactly why I added a way to use D4 for Tx. It took me some time to understand what was wrong during my tests 😁

Regarding the normal TX/RX, I generally find it being a bad idea to use it for a project because it's the default port for debugging and sending various messages.