Skip to content

Instantly share code, notes, and snippets.

@wheresalice
Created March 23, 2011 14:36
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheresalice/883191 to your computer and use it in GitHub Desktop.
Save wheresalice/883191 to your computer and use it in GitHub Desktop.
Arduino Redis client - pushes a message to a Redis list
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 2, 10 }; // this is the ip within my lan
byte gateway[] = { 192, 168, 2, 254 }; // neccessary to get access to the internet via your router
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 192, 168, 2, 50 }; // Redis Server
String list = "jobs";
String message = "hello world";
Client client(server, 6379);
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.println("*3");
client.println("$5");
client.println("RPUSH");
client.print("$");
client.print(list.length());
client.println(list);
client.print("$");
client.print(message.length());
client.println(message);
client.println("*1");
client.println("$4");
client.println("quit");
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment