1
votes

I’m currently running several MQTT IOT devices (mqtt hardware: raspberry pi 2, mqtt broker: Mosquitto, devices mostly ESP8266). As firmware I’m running a custom blend of the esp8266-homie firmware. This worked fine for months but now I’m facing an issue regarding the use of $ topics.

A simple example, my devices publish their online status to a topic: home/device/$online and the will message will make sure this goes to false when the device disconnects.

When running this command, I can see that topic (amongst the others):

mosquitto_sub -h <brokerIP> -u <username> -P <password>  -t home/device/# -v

output:

home/device/$online true

so the topic is there and does contain data, great! So logic dictates that running this one should return the true value:

mosquitto_sub -h <brokerIP> -u <username> -P <password>  -t home/device/$online -v

output: Nothing

but sadly, this isn’t returning anything since 2 days. Only thing I can think of that changed might be an update on my raspberry pi.

1

1 Answers

1
votes

$ is the char to signify a environment variable to the shell (most likely bash) so it will be trying to expand the $online with the value stored in the environment variable before executing the command.

As $online is most likely not set to anything, this means what's actually being executed is:

mosquitto_sub -h <brokerIP> -u <username> -P <password>  -t home/device/ -v

You can fix this by quoting the topic string as follows:

mosquitto_sub -h <brokerIP> -u <username> -P <password>  -t 'home/device/$online' -v