Skip to content

Instantly share code, notes, and snippets.

@perezd

perezd/test.cpp Secret

Created February 13, 2012 21:00
Show Gist options
  • Save perezd/4daf3c2a14c9e9a28d88 to your computer and use it in GitHub Desktop.
Save perezd/4daf3c2a14c9e9a28d88 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Streaming.h>
#include "WiFlySerial.h"
#include <WebSocketClient.h>
#include <WiFlyClient.h>
#define WF_AP_SSID "xxx"
#define WF_AP_PASS "xxx"
// Connect the WiFly TX pin to the Arduino RX pin (Transmit from WiFly-> Receive into Arduino)
// Connect the WiFly RX pin to the Arduino TX pin (Transmit from Arduino-> Receive into WiFly)
#define ARD_RX_PIN 2
#define ARD_TX_PIN 3
WiFlySerial WiFly( ARD_RX_PIN, ARD_TX_PIN );
WebSocketClient client( WiFly );
// **********************************************************
// WiFly Setup
// **********************************************************
void configureWireless() {
WiFly.setDebugChannel( (Print*) &Serial );
WiFly.begin();
if (!WiFly.isConnected()) {
WiFly.leave();
WiFly.setSSID(WF_AP_SSID);
WiFly.setPassphrase(WF_AP_PASS);
WiFly.join();
}
Serial.println("configured wireless.");
}
void configureWebSockets() {
Serial.println("configuring sockets...");
client.setDebugChannel( (Print*) &Serial );
client.connect("192.168.1.68", "/", 8000);
client.setDataArrivedDelegate(dataArrived);
Serial.println("configured sockets.");
}
void setup() {
Serial.begin(9600);
configureWireless();
configureWebSockets();
}
void loop() {
client.monitor();
}
void dataArrived(WebSocketClient client, String data) {
Serial.println("Data Arrived: " + data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment