I'm new MQTT. I'm looking at an example MQTT sketch from the PubSubClient library. It looks like this:
void callback(char* topic, byte* payload, unsigned int length) {
// handle message arrived
}EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);void setup()
{
Ethernet.begin(mac, ip);
if (client.connect("arduinoClient")) {
client.publish("outTopic","hello world");
client.subscribe("inTopic");
}
}
I'd like to publish ints, bools, and floats instead of the string "hello world" to the topic, but trying this gives me a "invalid conversion from int to char" error:
void setup()
{
int mydata = 4;
Ethernet.begin(mac, ip);
if (client.connect("arduinoClient")) {
client.publish("outTopic", mydata);
client.subscribe("inTopic");
}
}
Does the protocol only take in character strings? I have a feeling I have to do some kind of conversion involving the "&" operator...but I'm not sure.