User Tools

Site Tools


2016:yun_notes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
2016:yun_notes [2016/04/05 08:22] – created 75.177.137.22016:yun_notes [2016/04/05 08:26] (current) 75.177.137.2
Line 7: Line 7:
      #include <pubsubclient.h>      #include <pubsubclient.h>
      #include <yunclient.h>      #include <yunclient.h>
- 
      void callback(char* topic, byte* payload, unsigned int length) {      void callback(char* topic, byte* payload, unsigned int length) {
      // handle message arrived      // handle message arrived
      }      }
- 
      YunClient yun;      YunClient yun;
      PubSubClient client("192.168.2.210", 1883, callback, yun);      PubSubClient client("192.168.2.210", 1883, callback, yun);
- 
      void setup()      void setup()
      {      {
 +     Bridge.begin();
 +     
  
 +
 +==== The aha Moment ====
 +
 +----
 +
 +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();      Bridge.begin();
 +     ...
 +     mqtt.connect(MQTT_CLIENTID, ....);
  
-     +The bridge opens the connection to the outside world from the Arduino via the OpenWRT host.
2016/yun_notes.1459858933.txt.gz · Last modified: 2016/04/05 08:22 by 75.177.137.2