Sending commands to the dispenser via MQTT

Let's use the Mosquitto command-line tool to send the MQTT message to the MQTT server (shiftr.io), which will then forward it to our Arduino. Open a Terminal/PowerShell and run the following code:

mosquitto_pub -t "/tims-channel/feeder/feed" -m "Feeeed" -h broker.shiftr.io -u "try" -P "try"

We use the mosquitto_pub command to send the "Feeeed" message to the /tims-channel/feeder/feed channel using the broker.shiftr.io MQTT server with the try username and try password. At this point, we will ignore the message, in this case Feeeed, in our Arduino code and just check whether the topic matches /tims-channel/feeder/feed.

When you run the code, your feeder should open up and close again. Hooray!

You ...

Get Hands-On Internet of Things with MQTT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.