RN-XV Wifly module connecting to WiFi and Sending an alert Tweet

I have a project whose idea is to connect an arduino board to a home wifi network using the RN-XV WiFly module and to then alert the user via their smartphone when their laundry is done by listening for an alarm from the washing machine is finished it’s cycle (that annoying default Bosch one). I initially wanted to use an external service that required me to make an HTTPS request with specific information in the form of a GET. It worked from a browser and thought that it would be easy to implement from a wifi-enabled arduino.

After starting another thread yesterday, PaulS was polite enough to correct me on the ability to make an HTTPS request with an arduino. After some more research across these forums, I found this library made by dhunt (http://forum.arduino.cc/index.php?topic=99362.0, shout out to fellow Wellingtonians!) that seems to make the wifly’s use a lot easier. Further down the thread, I found this project by kwalk (https://github.com/hackinstance/WiFly_twitter/commit/eb4fd7760764357fb1efe557c428bfbbec602563) who seemed to even get twitter working through http://arduino-tweet.appspot.com/, however it does just stop after a while, whereas I intend to only turn on the device for the duration of it’s use, where it will only connect at the end of the cycle and send a single tweet. Using mobile notifications for a selected account I can receive the notifications I need from the arduino when it has detected the alarm from the wash cycle ending (I’m planning on using analogRead and lots of testing for the specific values that the alarm generates in order to detect). This way, I achieve the criteria of being alerted on my mobile device when the washing machine’s finished.

Here’s some of the code I’ve started to adapt from kwalk’s project (most of it is still his), the issue is that I don’t know what exactly I should be cutting out to attain a bare minimal wifi connection and ability to tweet on connection (which seems dodgy as it is) since the examples are also a little difficult to understand:

#include <WiFlyHQ.h> // Download from https://github.com/harlequin-tech/WiFlyHQ
#include <SoftwareSerial.h> // included in Arduino install
#include <SPI.h> // included in Arduino install

WiFly wifly; // Initialise wifly

// Updatable settings:
const char mySSID[] = "nuh uh"; // Wifi network name
const char myPassword[] = "not today guys, sorry"; // Wifi network password
char token[] = "I have some semblance of security, you could use this and abuse the twitter account"; // Get this from arduino-tweet.appspot.com
//int threshold = 60; // Sensor calibration

// Fixed settings:
const char site[] = "arduino-tweet.appspot.com"; // Site that sends our tweets
SoftwareSerial wifiSerial(1,0); // This is where Arduino i/o pins are set
char msg[140]; // Tweet length;
String tweetText; // Variable to hold the tweet text
unsigned long start_time; // Timer stuff
unsigned long current_time;
unsigned long elapsed_time;

/* Connect the WiFly serial to the serial monitor. */
void terminal(){
  while (1) {
    if (wifly.available() > 0) {
      Serial.write(wifly.read());
    }
  }
}

void setup(){
  pinMode(13, OUTPUT); // LED for feedback
  digitalWrite(13, LOW); // Turn it off to start
  char buf[32]; // Serial buffer size
  Serial.begin(115200); // Serial port baud rate: SET BAUD RATE TO THIS IN SERIAL MONITOR
  Serial.println("Starting");
  Serial.print("Free memory: ");
  Serial.println(wifly.getFreeMemory(),DEC);

  wifiSerial.begin(9600); // Wifly baud rate: It's OK that this doesn't match serial port rate above.
  if (!wifly.begin(&wifiSerial, &Serial)) {
    Serial.println("Failed to start wifly");
    terminal();
  }

  /* Join wifi network if not already associated */
  if (!wifly.isAssociated()) {
    /* Setup the WiFly to connect to a wifi network */
    Serial.println("Joining network");
    wifly.setSSID(mySSID);
    wifly.setPassphrase(myPassword);
    wifly.enableDHCP();
    if (wifly.join()) {
      Serial.println("Joined wifi network");
    } 
    else {
      Serial.println("Failed to join wifi network");
      terminal();
    }
  } 
  else {
    Serial.println("Already joined network");
  }

  Serial.print("MAC: ");
  Serial.println(wifly.getMAC(buf, sizeof(buf)));
  Serial.print("IP: ");
  Serial.println(wifly.getIP(buf, sizeof(buf)));
  Serial.print("Netmask: ");
  Serial.println(wifly.getNetmask(buf, sizeof(buf)));
  Serial.print("Gateway: ");
  Serial.println(wifly.getGateway(buf, sizeof(buf)));
  wifly.setDeviceID("Wifly-WebClient");
  Serial.print("DeviceID: ");
  Serial.println(wifly.getDeviceID(buf, sizeof(buf)));
  if (wifly.isConnected()) {
    Serial.println("Old connection active. Closing");
    wifly.close();
  }
  start_time = millis();
}

void loop(){
  current_time = millis();
  elapsed_time = current_time - start_time;
  if(elapsed_time > 60000) {// Don't tweet more than once a minute!
      tweetText = "Arduino WiFly Tweet testing." + random(255); // Construct the tweet; random because Twitter doesn't like to see the same thing repeatedly
       Serial.println(tweetText);{ // for debugging
      //tweet(); // THIS IS THE LINE THAT TWEETS: details below
    start_time = millis();
  }
}
}

void tweet(){
  digitalWrite(13, HIGH); // Turn on the LED to show we're sending
  // The following copied from setup() above:
  wifiSerial.begin(9600); // Wifly baud rate: It's OK that this doesn't match serial port rate above.
  if (!wifly.begin(&wifiSerial, &Serial)) {
    Serial.println("Failed to start wifly");
    terminal();
  }

  /* Join wifi network if not already associated */
  if (!wifly.isAssociated()) {
    /* Setup the WiFly to connect to a wifi network */
    Serial.println("Joining network");
    wifly.setSSID(mySSID);
    wifly.setPassphrase(myPassword);
    wifly.enableDHCP();
    if (wifly.join()) {
      Serial.println("Joined wifi network");
    }
    else {
      Serial.println("Failed to join wifi network");
      terminal();
    }
  }
  else {
    Serial.println("Already joined network");
  }

  if (wifly.open(site, 80)) { // Go to the website on http port 80
    Serial.print("Connected to ");
    Serial.println(site);
    // end of text copied from setup()
    /* Send the tweet */
    for ( int i = 0; i < sizeof( msg ); i++ ) {
      msg[i] = '\0';
    }
    tweetText.toCharArray( msg, tweetText.length() + 1 );
    Serial.println("connected");
    wifly.println("POST http://arduino-tweet.appspot.com/update HTTP/1.0");
    wifly.print("Content-Length: ");
    wifly.println(strlen(msg)+strlen(token)+14);
    wifly.println();
    wifly.print("token=");
    wifly.print(token);
    wifly.print("&status=");
    wifly.println(msg);
  } 
  else {
    Serial.println("Failed to connect");
  }
  digitalWrite(13, LOW); // We're done.
}

I’m still fairly new to this whole networking thing but I am experienced with analogue conversion and using it in functionality of projects (I once made Pong using a 32x16 LED Dot matrix from freetronics and an arduino Uno + 2 Pots, played quite well). I just am unsure of what to cut and/or add to kwalk’s code to work more along the lines I had in mind. All credit to dhunt for the library and kwalk for the code, I am simply the guy that wants to adapt it and figure this out.

Also, attached should be my current wiring setup excluding the analogue electret microphone which I’ll use as part of an if statement for criteria to connect and tweet the message + a random value so twitter doesn’t have a hissy fit. I would appreciate it if anyone could notify me of errors.

Any help would be appreciated, and here’s to Team New Zealand to take the America’s cup! (Hopefully, eventually, maybe…)

I pay $10 a month for having my own domain hosted. For that, I can run any number of scripts on the server. Any one of those scripts could be structured to send a message to a cell phone, given the number to send the message to.

I can also use that domain to send and receive e-mail, which makes it worth the $10 a month to me.

Making the Arduino connect to the server, and issue a GET request (with a phone number) is easy, when it is wearing an Ethernet shield. It is only slightly more difficult when it wears a WiFi shield.

Setting up an Apache server on your PC (Apache is free), and connecting the PC to the same wireless network that the Arduino is connected to means that the Arduino simply needs to ask your PC to send the message to a cell phone. That seems like a no-brainer to me.

That sounds like a viable option but given that one of the criteria of this project is to be independent and easy to use, I wanted to use twitter's mobile notifications for as an alert on a smartphone. I'm still trying to understand what bare minimal code I need to connect to the WiFi network, since something that basic keeps getting skipped over by people who have done it and aren't too keen on explaining it.

I just need to know how to connect it for the moment, getting it to work should be easy from there.

I'm still trying to understand what bare minimal code I need to connect to the WiFi network

The WiFi network? There isn't ONE WiFi network. You might have a WiFi network. Your neighbor might have one. Which one do you want to connect to?

The reason that details are hard to come by is because there are dozens of different kinds of WiFi routers, with different encryption schemes. It is assumed that you know how to connect a new device to your network. If not, you've got a tough battle ahead of you.

given that one of the criteria of this project is to be independent and easy to use,

That would seem to rule out WiFi, then. Nothing about WiFi is "easy to use". By comparison, plugging a network cord into the wall is trivial. Of course, sometimes that cord is limiting, but it is easy.

Sketch Arduino for Wifly RN-XV modem configuration without Wifly library and with front-end: https://dl.dropboxusercontent.com/u/101922388/WiflySanUSB.zip