Dynamic Feed Name

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.
Locked
User avatar
dobbz
 
Posts: 38
Joined: Wed Mar 12, 2008 11:06 am

Dynamic Feed Name

Post by dobbz »

Is there a preferred way to dynamically assign a feed name?

I'd like to set the feedname based on the device name and use the same code for multiple units. This way I don't need to have a separate code base for each unit.

Example:

3 Units - Inside, Outside, and Garage
Measuring Temperature

Feed Name:

Code: Select all

Adafruit_MQTT_Publish Temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/[UNIT_NAME].temp");  
I could use macros, but this would require building code differently for each unit.

Assuming I can easily uniquely self-identify each unit (Particle Photon with system.DeviceID), how can I get this in the MQTT Publish?

Is it acceptable to move the Publish routine from the start of the code into the setup() section?

Thanks!

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Dynamic Feed Name

Post by brubell »

Sure, the feed name passed in that call is a character string. You will need to create each DEVICE_ID feed name on the Adafruit.io website first, though. Declaring it in the code using the MQTT library does not perform the feed creation API action (the Adafruit_IO_Arduino library may do this, but I haven't looked at this action in a while).
Is it acceptable to move the Publish routine from the start of the code into the setup() section?
As long as it comes after the WiFi and broker connection, sure.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”