Skip to content

Instantly share code, notes, and snippets.

@damienpuig
Last active December 19, 2015 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damienpuig/5868302 to your computer and use it in GitHub Desktop.
Save damienpuig/5868302 to your computer and use it in GitHub Desktop.
Corrdinator for dissertation
#include <redisClient.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192, 168, 1, 20); // Redis Server
RedisClient client(server);
void setup()
{
Ethernet.begin(mac);
Serial.begin(9600);
connection();
}
void publish()
{
Serial.println("Publishing to pub/sub channel... ");
client.startPUBLISH("Arduino1");
client.sendArg("salut");
delay(500);
Serial.println("Published!");
}
void connection()
{
RedisClient tempClient(server);
client = tempClient;
client.connect();
Serial.println("connecting...");
delay(3000);
if(client.connected())
{
Serial.println("connected!");
}
else
{
Serial.println("connection failed!");
}
}
void loop()
{
delay(5000);
if(client.connected())
{
publish();
}
else
{
Serial.println("client unavailable! retrying connection in 3 seconds..");
delay(3000);
connection();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment