As you know, the traditional way of creating a thinger client instance on ESP8266 is as follows:
#include <ThingerESP8266.h>
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#define USERNAME "your_user_name"
#define DEVICE_ID "your_device_id"
#define DEVICE_CREDENTIAL "your_device_credential"
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void setup() {
}
void loop() {
thing.handle();
}
What I am trying to do now is to dynamically input my device credentials by making a reference to WiFiManager and more specifically:
WiFiManagerParameter thinger_username_input("thinger_username", "Thinger.io username here", "", 50);
wm.addParameter(&thinger_username_input);
So, my code now looks more like this:
ThingerESP8266* thing;
void setup() {
// …
const char* buffer = thinger_username_input.getValue();
thing = new ThingerESP8266(buffer, DEVICE_ID, DEVICE_CREDENTIAL);
}
void loop() {
thing->handle();
}
But for some reason, when I try to create the Thinger client instance like this:
thing = new ThingerESP8266(buffer, DEVICE_ID, DEVICE_CREDENTIAL);
it doesn’t work. If I do it like this:
thing = new ThingerESP8266(“inline_version_of_my_username”, DEVICE_ID, DEVICE_CREDENTIAL);
it works
I really don’t understand why is this happening. Further, when I compare:
buffer == "inline_version_of_my_username" // False - 0
They are not the same obviously. When I print them out one after another during the runtime they seem to be exactly identical in the Serial monitor.
inline_version_of_my_username
inline_version_of_my_username
why is that?
EDIT:
Just tried the following approach (copy the actual value not just pointing it - I thought the value behind the pointer might disappear at certain point):
const char* buffer = thinger_username_input.getValue();
char *result = (char *)malloc(strlen(buffer)+1);
strcpy(result,buffer);
thing = new ThingerESP8266(result, DEVICE_ID, DEVICE_CREDENTIAL); // WORKS NOW