In spite of my having looked at Arduino Yun's bridge I couldn't come up with a way of connecting PubSubclient to the Yun. An important hint by Nick O'Leary earlier today made it 'click' into place.

Instead of doing this with EthernetClient, on say, a Duemilanove with an Ethernet shield:

#include <Ethernet.h>
...
EthernetClient eth;
PubSubClient mqtt(MQTT_SERVER, MQTT_PORT, callback, eth);
...
Ethernet.begin(mac);
...
mqtt.connect(MQTT_CLIENTID, ....);

you do this with the Yun:

#include <YunClient.h>
...
YunClient yun;
PubSubClient mqtt(MQTT_SERVER, MQTT_PORT, callback, yun);
...
Bridge.begin();
...
mqtt.connect(MQTT_CLIENTID, ....);

The bridge opens the connection to the outside world from the Arduino via the OpenWRT host.

Here's a Yun subscribed to an MQTT topic which reads numbers and writes them to a 7-segment display.

Once you know that, it's easy. Even so, it's probably much more sensible to run a full MQTT client on the OpenWRT part of the Yun (even a full-blown Mosquitto if you like).

Flattr this
Arduino and MQTT :: 15 Oct 2013 :: e-mail

Comments

blog comments powered by Disqus