Skip to content

Instantly share code, notes, and snippets.

@mdobson
Created February 27, 2014 14:08
Show Gist options
  • Save mdobson/9250741 to your computer and use it in GitHub Desktop.
Save mdobson/9250741 to your computer and use it in GitHub Desktop.
MQTT with the Arduino Yun
/*
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