You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to change the value of some const char* arguments of syslog() constructor during the application running.
The following is some parts of my code.
Inside loop(), I copied a string derived from the serial input to std::string object. If I create const char* variable "testapp" and put it to syslog.appName() like the following, it works.
However, If I put the copied std::string object with the same string "testapp" replacing with the commented out // line, the library sends other value than "testapp". Even if I put the same string "testapp" multiple times, it changes. It seems to refer the different memory address's value.
This may be c++ programing issue, but could you let me know how to solve this if possible?
std::string myOffset (String string, int offset) {
std::string para = "";
for (int i = offset; i < string.length(); i++) {
para += string[i];
}
return para;
}
The text was updated successfully, but these errors were encountered:
I want to change the value of some const char* arguments of syslog() constructor during the application running.
The following is some parts of my code.
Inside loop(), I copied a string derived from the serial input to std::string object. If I create const char* variable "testapp" and put it to syslog.appName() like the following, it works.
However, If I put the copied std::string object with the same string "testapp" replacing with the commented out // line, the library sends other value than "testapp". Even if I put the same string "testapp" multiple times, it changes. It seems to refer the different memory address's value.
This may be c++ programing issue, but could you let me know how to solve this if possible?
//global scope
Syslog syslog(udpClient, server, SYSLOG_PORT, "esp32", LOG_KERN);
void loop() {
...
if (Serial.available() > 0) {
String str = Serial.readStringUntil('\n');
if (str[0] == 'R') {
...
} else if (str[0] == 'A') {
std::string para = myOffset(str, 2);
const char* param = "testapp";
Serial.println(strcmp(para.c_str(), param));
// syslog.appName((const char*)(para.c_str()));
syslog.appName(param);
}
}
...
syslog.logf(LOG_INFO, "%s %d %f %f", d.getAddress().toString().c_str(), id, current, voltage);
}
std::string myOffset (String string, int offset) {
std::string para = "";
for (int i = offset; i < string.length(); i++) {
para += string[i];
}
return para;
}
The text was updated successfully, but these errors were encountered: