I have been trying to construct MQTT_FEED to include account name and feed
account name is uploaded from WiFiconfig in to string(0).
- Code: Select all | TOGGLE FULL SIZE
....
WiFiClient client;
Adafruit_MQTT_Client *mqtt;
Adafruit_MQTT_Subscribe *OP1;
....
void setup () {
.....
char *strings[2];
string[0] = "behmadi"
const char* MQTT_NAME = strings[0];
const char* feed1 = "/feeds/op1";
char MQTT_NAME_FEED1[20] = "\0";
strcat(MQTT_NAME_FEED1,MQTT_NAME);
strcat(MQTT_NAME_FEED1,feed1);
delay(200);
String s1((const __FlashStringHelper*) MQTT_NAME_FEED1);
const char* MQTT_FEED1 = s1.c_str();
Serial.println(MQTT_FEED1); //"prints -- behmadi/feeds/op1 ---- in serial monitor
......
mqtt = new Adafruit_MQTT_Client(&client, MQTT_SERV, MQTT_PORT, MQTT_NAME, MQTT_PASS);
OP1 = new Adafruit_MQTT_Subscribe(mqtt, MQTT_NAME_FEED1);
mqtt->subscribe(OP1);
....
}
I have tried many ways combining the two, all attempt resulted the combined "behmadi/feeds/op1" in my serial print.
My IO dashboard displays
"MQTT ERROR: rejected, not a valid topic format"
or
"MQTT ERROR: aedes_FNQbOxBN9C9T 60.240.148.110 PUBLISH to topic `` rejected, topic is not a recognized format"
if I change " const char* MQTT_FEED1 = s1.c_str(); " line in above code to "const char* MQTT_FEED1 = "behmadi/feeds/op1;"
it works perfectly
if I use "OP1= new Adafruit_MQTT_Subscribe(mqtt, MQTT_NAME "/feeds/op1"); it results in compile error "expected ')' before string constant"
anyone knows how to construct this to include username and feed
Many thanks