0

MQTT Publish topic path variable
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MQTT Publish topic path variable

by davieswa123 on Mon Jul 08, 2019 5:30 am

Hello;

Is there a way to create a topic path to include a variable? It seems to only accept fixed #define values.

// Notice MQTT paths for Adafruit AIO follow the form: <username>/feeds/<feedname>
Adafruit_MQTT_Publish pubmessage = Adafruit_MQTT_Publish(&mqtt, MQTT_TOPIC_Variable "Gateway/"NodeID);

Any help or an example much appreciated.

W

davieswa123
 
Posts: 2
Joined: Sat Jan 20, 2018 11:58 pm

Re: MQTT Publish topic path variable

by brubell on Mon Jul 08, 2019 10:20 am

The function signature for the Publish method follows the format:

Code: Select all | TOGGLE FULL SIZE
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen, uint8_t qos) {
via https://github.com/adafruit/Adafruit_MQ ... T.cpp#L304

Since topic is a const char, it is immutable and therefore not able to be changed or set to a variable.

brubell
 
Posts: 431
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.