Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Issues with ABC = new Adafruit_MQTT_Subscribe(mqtt, MQTT_FEE
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Issues with ABC = new Adafruit_MQTT_Subscribe(mqtt, MQTT_FEE

by behmadi on Wed Jul 22, 2020 11:45 pm

OP1= new Adafruit_MQTT_Subscribe(mqtt, MQTT_FEED1);

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

behmadi
 
Posts: 2
Joined: Sat Jul 04, 2020 12:38 pm

Re: Issues with ABC = new Adafruit_MQTT_Subscribe(mqtt, MQTT

by behmadi on Sun Jul 26, 2020 9:12 am

All sorted
Code was a mess, pointers and buffers were all a big shamble
Adafriut_MQTT_Subscribe works perfectly

behmadi
 
Posts: 2
Joined: Sat Jul 04, 2020 12:38 pm

Please be positive and constructive with your questions and comments.