Customize variables

Good night. I am working with Arduino and ESP32, what I am trying to do is send the data of temperature, humidity and luminosity to the platform but with the names of the variables that the user wish, I understand that the type of data it supports is const char * but when converting the String variable to const char * compiles the program but does not allow me to connect with my device on the platform. If I manually enter the variable names it works fine.


i just tried that. With Arduino String variable it doesn’t work for me either. I don’t know exactly, why it behaves like this.
However with “normal” const char * it worked in my case, but you won’t be able to edit the name in runtime of the controller.

I just came across some documentation and i found that the Arduino String is not the same as std::string. Arduino String c_str() function returns const w_char* which probably can’t be handled by libraries.

Hi, something like this should work to have the three values in the same “thing” and personalized names

  thing["Variables"] >> [](pson & out) {
    out["Temp"] = tempVar;
    out["Hum"] = humVar;
    out["Lum"] = lumVar;

Hope this helps.

Sorry, I’m just reading again the post, and I missunderstood, what you want is to modify anytime the variable name from the platform?

Well… If it is the requirement, you can do it by the next way:

thing["StringTest"] << inputValue(stringVar);
thing[stringVar.c_str()] >> outputValue(millis());  

And of course you need to define stringVar as a global string variable, and initialize it with any value, after that you will be able to change by the StringTest resource the variable name of the millis() output.

Hope this helps.

Hi, the problem is when I convert the String variable to const char *, although it compiles correctly it does not work, it does not connect my device on the platform. This is my code.

thing[“Monitoreo”] >> [](pson& out)
out[Dato9.c_str()] = Lux;
out[Dato11.c_str()] = TempeHoja;
out[Dato13.c_str()] = TempAmb;
out[Dato15.c_str()] = HumHoja;
out[Dato17.c_str()] = HumAmb;

Hi, can you please enable the verbose output to check what is the device doing?

Just add the next line:
#define _DEBUG_
At the very first line of your sketch

So is the requirement to change the variable name with the board online?, if it is, this sketch worked perfectly for me to do it

#include <ThingerESP32.h>

#define USERNAME "myUser"
#define DEVICE_ID "myDevice"
#define DEVICE_CREDENTIAL "myDevicePw"

#define SSID "myWifi"
#define SSID_PASSWORD "myWifiPw"


String stringVar = "var1";

void setup() {
  thing.add_wifi(SSID, SSID_PASSWORD);
  thing[stringVar.c_str()] >> outputValue(millis());  
  thing["StringTest"] << inputValue(stringVar);
void loop() {

what is the content of the “Dato” variables at the begining? how are those variables initialized?