Publishing Commands to MQTT Using Ardulink

Hello. I’m helping setup a low-power FM radio station on a very tight budget. Right now I’m working on a curse delay system. I found changeling and got it running on Ubuntu 16.04. I really like it and I want to make it more user-friendly for the DJs. changeling uses MQTT (Mosquitto, specifically) to receive published commands. changeling has three commands:

# To enter delay, which creates a several second buffer of audio from the PC mic jack and 
plays it out through the speaker jack on a delay.

mosquitto_pub -t changeling-commands -m ENTER

# To exit delay, which eliminates the buffer and plays the audio coming in from the mic jack out 
through the speaker jack in real time.

mosquitto_pub -t changeling-commands -m EXIT

# To dump delay buffers, which empties the buffer while playing an audio file to cover a curse 
word spoken on air then continues to output sound to the speaker jack on a delay.

mosquitto_pub -t changeling-commands -m DUMP

I want to create a wired remote that will sit on the DJ table and publish one of the three commands above to changeling via a serial connection over USB when a button on the Arduino is pressed. I found Ardulink as a method for interfacing the Arduino with MQTT using Ardulink-MQTT. I installed the relevant Java scripts on the Ubuntu PC/MQTT broker, loaded ArdulinkProtocol.ino onto the Arduino Uno, connected them over USB, fired up the Ardulink Console and got them to interface. Right now I can connect to the Arduino from the console and remotely operate, for example, a blinking LED. I can also connect to the MQTT broker through the console, subscribe to the console and see changes I make on the console in the terminal window.

But now I want to connect the serial connection to MQTT directly to publish the above commands. I figure I have two options to do that:

OPTION 1:

A digital pin set to HIGH tells the Arduino to publish the text string of a changeling command to Ardulink-MQTT and on to Mosquitto.

PRO: I might be able to avoid writing an additional Java script that runs on the computer and stick with Ardulink software that’s already written.

CON: Those three changeling commands are long and I know how quickly I can use up the Arduino Uno’s SRAM with long strings.

OPTION 2:

A digital pin set to HIGH is received by a custom Java script based on Ardulink-MQTT, which translates the pin # to the corresponding changeling command and publishes the command to Mosquitto.

PRO: No worry of maxing out the Arduino Uno’s memory with long strings.

CON: I will have to write a custom Java script from the Ardulink-MQTT source code and compile it, which I haven’t done with Java in a very long time.

I know I could do keybinding or write a Perl/Python/etc script to send UNIX commands from a keystroke to operate changeling, but for reasons that are beyond the scope of this post I want to stick with MQTT. Basically, I also want the Arduino to subscribe to changeling over MQTT to operate an LED when the commands are run. But that’s for another post.

Any help would be much appreciated.

Thank you,
Jeremy

I asked this question on GitHub and got this response:

either use Ardulink Console or ardulink-mqtt. Enable listening on the digital pin the button is connected to by either clicking the button "Digital sensor panel" in the UI or passing "-d X" where X is digital pin the button is connected to, to ardulink-mqtt

For the LED you just have to publish a message to the broker. The default topic ardulink is listening to is home/devices/ardulink so when sending a message "1" to the topic "home/devices/ardulink/Dx/value/set" where x is the digital pin the LED is connected to, your LED should lighten up

I'm missing something obvious.

How do I tell the software what to do when it detects the button press or what event has to happen for the LED to illuminate? (or for that matter, how do I tell it to flash or slowly pulse rather than just illuminate?) It must be passed as a command line argument. I still don't get it :frowning: .

How do I tell the software what to do when it detects the button press

What software?

Try speaking gently, and offering flowers or chocolates.

Hello.

I guess the software must be ardulink-mqtt. It seems like the console is more for testing your setup.

I'm thinking I must pass a command line argument to ardulink-mqtt that identifies the pin to listen to for a button press, followed by the UNIX command argument to execute when the button is pressed (e.g. mosquitto_pub -t changeling-commands -m DUMP).

It does not make much sense to tie the sensor to the actuator. There should be a component to do this work.

  • The sensor (button) should only communicate that it has been actuated.
  • The component should then decide what to do.
  • The actuators react to what the component has decided.

There are many ways to realize this. One possibility would be e.g. nodered.
With Docker you can try this relatively easy.

So please run ardulink-mqtt (pass -d 5 as command line arg to listen to digital pin 5) to monitor the digital pin 5 on the attached arduino board.

Then start two docker containers:
docker run -d --name mosquitto -p 1883:1883 eclipse-mosquitto
this is a image providing a mqtt broker (mosquitto)

docker run -d --name nodered --link mosquitto:mosquitto -p 1880:1880 nodered/node-red-docker
this is a image providing node-red

Then navigate your browser to http://localhost:1880/
and import this flow:
[{"id":"38b4e8ae.d92828","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b40a6159.2f0ba","type":"mqtt in","z":"38b4e8ae.d92828","name":"","topic":"home/devices/ardulink/D5","qos":"0","broker":"f00e665a.69ccd","x":200,"y":120,"wires":[["55dcf7ed.f52328","347b8d7b.89a9d2"]]},{"id":"8f3558aa.499d3","type":"mqtt out","z":"38b4e8ae.d92828","name":"","topic":"","qos":"","retain":"","broker":"f00e665a.69ccd","x":950,"y":120,"wires":[]},{"id":"55dcf7ed.f52328","type":"switch","z":"38b4e8ae.d92828","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"str"},{"t":"eq","v":"false","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":120,"wires":[["8b831fc9.cf326"],["6c434266.33d61c"]]},{"id":"347b8d7b.89a9d2","type":"debug","z":"38b4e8ae.d92828","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":180,"wires":[]},{"id":"8b831fc9.cf326","type":"change","z":"38b4e8ae.d92828","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"DUMP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":100,"wires":[["72b64cdd.d55b14"]]},{"id":"6c434266.33d61c","type":"change","z":"38b4e8ae.d92828","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"FOOBAR","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":140,"wires":[["72b64cdd.d55b14"]]},{"id":"72b64cdd.d55b14","type":"change","z":"38b4e8ae.d92828","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"changeling-commands","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":120,"wires":[["8f3558aa.499d3","1c0f51b5.cfa776"]]},{"id":"1c0f51b5.cfa776","type":"debug","z":"38b4e8ae.d92828","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":970,"y":180,"wires":[]},{"id":"f00e665a.69ccd","type":"mqtt-broker","z":"","name":"","broker":"mosquitto","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

This flow subscribes to the topic for digital pin 5 then translates topic and payload (message) and publish the changed message to the broker