Haven’t used the Arduino IDE for awhile, and today I had the following errors:
/home/m/Arduino/libraries/Ubidots_MQTT_for_ESP8266/examples/publishToBusiness/publishToBusiness.ino:9:15: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
9 | #define TOKEN “…” // Your Ubidots TOKEN
“ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]” is a recurring error on most lines of the code.
This is using the Ubidots Publish example in the IDE. The same happened to my existing sketches.
Blink example compiles and uploads fine.
Same error on Linux IDE 1.8.19 and a new install of 2.2.1 on a different computer.
Can anyone shed some light on this? I’m puzzled!
Thank You,
John
Greetings @ardyjohn I hope this message finds you well,
I trust you’re well.
I’ve been attempting to replicate the behavior you described, but regrettably, I haven’t been successful in doing so.
I tried utilizing the example available on our GitHub repository:
#include <Arduino.h>
#include <cstdlib>
#include "UbidotsESPMQTT.h"
#define COMPILE
#define UBIDOTS_TOKEN "BBFF-xxyyzz" // Put here your Ubidots TOKEN
#define WIFI_SSID "ssid" // Put here your Wi-Fi SSID
#define WIFI_PASS "pass" // Put here your Wi-Fi password
char *DEVICE_LABEL = "device_label"; // Put here your Device label to which data will be published
char *VARIABLE_LABEL = "variable_label"; // Put here your Variable label to which data will be published
Ubidots client(UBIDOTS_TOKEN);
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
bool connected = false;
/****************************************
* Main Functions
****************************************/
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
client.setDebug(true); // Pass a true or false bool value to activate debug messages
client.wifiConnection(WIFI_SSID, WIFI_PASS);
client.begin(callback);
}
void loop() {
// put your main code here, to run repeatedly:
connected = client.connected();
if (!connected) {
Serial.println("Not connected, attempting to connect ...");
connected = client.connect();
}
// Publish values to 2 different data sources
if (connected) {
client.add("stuff", 10.2); // Insert your variable Labels and the value to be sent
client.ubidotsPublish("source1");
client.add("stuff", 10.2);
client.add("more-stuff", 120.2);
client.ubidotsPublish("source2");
client.loop();
}
delay(5000);
}
Remarkably, this example worked exactly as anticipated.
To assist you further, I would appreciate it if you could provide the following details:
- What ESP8266 firmware version are you currently using?
- Can you please confirm that you are using this library (master branch version)?
- Could you share the complete code snippet that you are running?
- Please provide the entire compilation output. It’s worth noting that the warning you mentioned, “ISO C++ forbids converting a string constant to ‘char*’,” is not the actual error but rather a warning.
Your cooperation in providing these details will enable us to better diagnose the issue.
Best regards
–Juan David
Hi Juan,
Here is the info you requested. It must be something with the IDE, but I’ve tried several, the same IDE works for other providers. It has always worked for Ubidots in the past. Code is copied from your example.
Thank You.
John
Arduino: 1.8.19 (Linux), Board: “Generic ESP8266 Module, 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200”
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:10:22: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
10 | char *DEVICE_LABEL = “device_label”; // Put here your Device label to which data will be published
| ^~~~~~~~~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:11:24: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
11 | char *VARIABLE_LABEL = “variable_label”; // Put here your Variable label to which data will be published
| ^~~~~~~~~~~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:7:23: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
7 | #define UBIDOTS_TOKEN “BBFF-xxyyzz” // Put here your Ubidots TOKEN
| ^~~~~~~~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:13:16: note: in expansion of macro ‘UBIDOTS_TOKEN’
13 | Ubidots client(UBIDOTS_TOKEN);
| ^~~~~~~~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino: In function ‘void setup()’:
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:8:19: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
8 | #define WIFI_SSID “ssid” // Put here your Wi-Fi SSID
| ^~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:35:25: note: in expansion of macro ‘WIFI_SSID’
35 | client.wifiConnection(WIFI_SSID, WIFI_PASS);
| ^~~~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:9:19: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
9 | #define WIFI_PASS “pass” // Put here your Wi-Fi password
| ^~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:35:36: note: in expansion of macro ‘WIFI_PASS’
35 | client.wifiConnection(WIFI_SSID, WIFI_PASS);
| ^~~~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino: In function ‘void loop()’:
sketch_jan20a:44:24: error: ‘class Ubidots’ has no member named ‘connect’; did you mean ‘connected’?
44 | connected = client.connect();
| ^~~~~~~
| connected
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:50:16: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
50 | client.add(“stuff”, 10.2); // Insert your variable Labels and the value to be sent
| ^~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:51:27: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
51 | client.ubidotsPublish(“source1”);
| ^~~~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:52:16: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
52 | client.add(“stuff”, 10.2);
| ^~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:53:16: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
53 | client.add(“more-stuff”, 120.2);
| ^~~~~~~~~~~~
/home/m/Arduino/sketch_jan20a/sketch_jan20a.ino:54:27: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
54 | client.ubidotsPublish(“source2”);
| ^~~~~~~~~
exit status 1
‘class Ubidots’ has no member named ‘connect’; did you mean ‘connected’?
This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.
Greetings @ardyjohn I hope you are doing great,
After taking a look at the compilation logs that you provided, it seems to me that in some part of your code, specifically within the loop
function, you have a declaration like:
connected =client.connect();
However, as the compiler tell us, there’s no such member within the Ubidots class, instead, the method that you are trying to use is connected
. So, by changing:
connected = ubidots.connect();
To
connected = ubidots.connected();
The problem will be solved. Please let us know if this solved your issue.
Best regards,
–Juan David–
Hi Juan,
As what you suggested did not work, and I was using the same code as in your example, I deleted the Ubidots libraries and reinstalled them and it now compiles without a failure.
Thank You!
John