/test.cpp Secret
Created
February 13, 2012 21:00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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