Created
February 27, 2014 14:08
-
-
Save mdobson/9250741 to your computer and use it in GitHub Desktop.
MQTT with the Arduino Yun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Using an MQTT client with the arduino yun. | |
*/ | |
#include <SPI.h> | |
#include <Bridge.h> | |
#include <YunClient.h> | |
#include <PubSubClient.h> | |
byte mac[] = {0x90, 0xA2, 0xDA, 0xF0, 0x0E, 0x0A}; | |
byte server[] = {192, 168, 1, 9}; | |
byte ip[] = {192, 168, 1, 25}; | |
//Callback | |
void callback(char* topic, byte* payload, unsigned int length) { | |
}; | |
YunClient yClient; | |
PubSubClient client(server, 1883, callback, yClient); | |
void setup() { | |
// put your setup code here, to run once: | |
Bridge.begin(); | |
if(client.connect("arduinoClient")) { | |
client.publish("outTopic", "hello world"); | |
client.subscribe("inTopic"); | |
} | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
client.loop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment