Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • The library could possibly store the addresses of the C strings and use them later, but your arguments do not live long enough. Please check what happens if you copy the C strings into some other variables. -- Or use C string variables as experiment before (in this comment just shorted: char url[] = "192.168.1.45"; /* ... */ mqtt.begin(url, ...);) Commented Sep 21, 2024 at 17:47
  • @thebusybee Interesting, it does seems to be memory related. I'll update the question with the modifications. Commented Sep 21, 2024 at 18:39
  • It does look like the begin() method expects the user to provide static storage for the char* arguments as said by @the busybee. The class retains only a copy of the pointer. See: github.com/dawidchyrzynski/arduino-home-assistant/blob/main/src/… and the corresponding .h file. Here is a similar case (see my comments). Unfortunately, you have to poke around in the source code to see if the method retains an expanded copy of the arguments or simply a pointer. arduino.stackexchange.com/questions/96796/… Commented Sep 21, 2024 at 18:44
  • @6v6gt Yeah, I just looked at the source code as well. It seems that the class doesn't create a copy of the credentials so I need to make the credentials a global variable... Commented Sep 21, 2024 at 18:50
  • You do not need global variables for the strings, just static variables. Commented Sep 21, 2024 at 19:15