Formatting Error with MQTT

Hi, Ive been using node-red for a little while now, but I want one of my puzzles to tell me when a specific wire is cut, for this in a serial print, I just use (i) as per the example below. Trying to publish (i) as a MQTT message, its not liking it. What format should I be using (and why if possible to help me understand)?

This is the snippet of code Im having the issue with
if(digitalRead(wirePins[i]) == HIGH && lastState[i] == LOW) {
Serial.print("Wire ");
Serial.print(i);
Serial.println(" cut");
pc.publish("ToHost/Alarm/Wires", "Wire Cut");
pc.publish("ToHost/Alarm/Wires", (i)); // ERROR LINE
lastState[i] = HIGH;

and this is the error:

invalid conversion from 'int' to 'const char*' [-fpermissive]

Thanks

Apparently, your publish function expects a C string. You will need to convert the integer to a string - look at itoa.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.