adafruit / Adafruit_MQTT_Library

Arduino library for MQTT support
MIT License
572 stars 291 forks source link

I want to hand over the feed name as a variable not as string #121

Closed DoiChris closed 5 years ago

DoiChris commented 6 years ago

I want to use the mac-address as key for the feed name. Therfore I need to hand over the feed name as a variable, not as fix string.

This works fine: Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Test20180626_Temp");

But this does not compile: String feedNameTemp;

feedNameTemp += "/feeds/"; uint8_t mac[6]; WiFi.macAddress(mac); feedNameTemp += macToStr(mac); feedNameTemp += "-"; feedNameTemp += "Temp";

Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME, feedNameTemp);

Even if I try to use a string iteral like this it will not compile:

Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "{0}", feedNameTemp);

jjunimd commented 6 years ago

Looks like you are building feedNameTemp with a hyphen rather than an underscore.

brentru commented 5 years ago

Adafruit IO Feeds should be declared with feed keys, not feed names.

Try changing the feed from Test20180626_Temp to Test20180626-Temp

DoiChris commented 5 years ago

is there any restriction not to use underscore???

brentru commented 5 years ago

@DoiChris The restriction on underscores is specific to how Adafruit IO names feeds based on key identifiers https://learn.adafruit.com/naming-things-in-adafruit-io/introduction