Skip to content

Instantly share code, notes, and snippets.

@jonmarkgo
Created August 3, 2012 00:58
Show Gist options
  • Save jonmarkgo/3242876 to your computer and use it in GitHub Desktop.
Save jonmarkgo/3242876 to your computer and use it in GitHub Desktop.
#include <WiFlyHQ.h>
#include <SD.h>
#include <PusherClient.h>
PusherClient client;
WiFly wifly;
File permFile;
void setup() {
pinMode(12,OUTPUT);
digitalWrite(12,LOW);
pinMode(10, OUTPUT); //hardware SS pin for SD shield
SD.begin(4);
Serial.begin(9600);
wifly.begin(&Serial);
if (!wifly.isAssociated()) {
if (wifly.join("abc", "123", true)) {
wifly.save();
}
}
client.setClient(wifly);
if(client.connect("myid")) {
client.bind("led", modLED);
client.bind("add", addUser);
client.subscribe("robot_channel");
}
else {
while(1) {}
}
}
void loop()
{
client.monitor();
}
void addUser(String data) {
String body = client.parseMessageMember("Body", data);
permFile = SD.open("users.txt", FILE_WRITE);
if (permFile) {
permFile.println(body);
permFile.close();
}
}
void modLED(String data) {
String from = client.parseMessageMember("From", data);
String body = client.parseMessageMember("Body", data);
if (body == "on") {
digitalWrite(12,HIGH);
}
else {
digitalWrite(12,LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment