I am working on a similar system to SuperHouse's Alarm IO Shield, as a proof of concept,
I know you can do the following in Arduino :
Code: Select all
client.publish("topic/1", "ALARM");
client.publish("topic/2", "ALARM");
I want to generate the topic number automatically based on the iteration i am in in a loop, so I am trying the following :
Code: Select all
for (int channelno = 0; channelno < 8; channelno++) {
--- Additional code ---
char pubstring = "alarm/"+channelno;
client.publish(pubstring, "ALARM");
eg : First Iteration : Topic = topic/1 Message = ALARM
Second Iteration : Topic = topic/2 Message = ALARM
etc
but I am getting stuck, it looks like the client.publish is looking for a const char for the topic and message,
it gives me the following error :
Code: Select all
In file included from C:\Users\User\Documents\Arduino\AlarmMonster1\AlarmMonster1.ino:7:0:
C:\Users\User\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:130:12: error: initializing argument 1 of 'boolean PubSubClient::publish(const char*, const char*)' [-fpermissive]
boolean publish(const char* topic, const char* payload);
^
exit status 1
invalid conversion from 'const char*' to 'char' [-fpermissive]
I am sure it is something simple, but I am stumped
Thanks