Skip to content

Instantly share code, notes, and snippets.

@perezd
Created February 14, 2012 05:52
Show Gist options
  • Save perezd/bbcf140ff9aeebc9efc0 to your computer and use it in GitHub Desktop.
Save perezd/bbcf140ff9aeebc9efc0 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Streaming.h>
#include "WiFlySerial.h"
// **********************************************************
// CONFIG
// **********************************************************
#define WF_AP_SSID "WIFI"
#define WF_AP_PASS "PASS"
// 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 );
// **********************************************************
// SETUP
// **********************************************************
void configureWireless() {
WiFly.setDebugChannel( (Print*) &Serial);
WiFly.begin();
if (!WiFly.isConnected()) {
WiFly.leave(); // restart my link
WiFly.SendCommand("set com remote 0", "AOK");
WiFly.SendCommand("set opt jointmr 5000", "AOK");
WiFly.setSSID(WF_AP_SSID);
WiFly.setPassphrase(WF_AP_PASS);
if (WiFly.join()) {
Serial.println("connected.");
} else {
Serial.println("cannot connect.");
}
}
WiFly.exitCommandMode();
// clear out prior requests.
WiFly.uart.flush();
while (WiFly.uart.available() )
WiFly.uart.read();
}
void configureSignals() {
pinMode(9, OUTPUT);
}
void setup() {
Serial.begin(9600);
configureSignals();
configureWireless();
digitalWrite(9, HIGH);
}
char chOut;
char chIn;
void loop() {
while(WiFly.uart.available() > 0) {
chIn = (char)WiFly.uart.read();
Serial.write(chIn);
if (chIn == 'h') {
digitalWrite(9, HIGH);
} else if (chIn == 'l') {
digitalWrite(9, LOW);
}
}
if(Serial.available()) { // Outgoing data
WiFly.uart.write((chOut = Serial.read()));
Serial.write(chOut);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment