stickyBUG Code

There are many pieces of sample code available on the internet for the RN171, used by the wifiBUG. This particular sample enters command mode, enabling you to set or get data. A really useful document to accompany this sample can be downloaded from here:

Source Code

#if defined(__AVR__)
#include <SoftwareSerial.h>
SoftwareSerial uart = SoftwareSerial(2,3);
#else
#include <Timer.h>
#include <TimerSerial.h>
TimerSerial uart = TimerSerial(3,2);
#endif

// if the wifi device has data, output to the screen...
void readWifi() {
   while (uart.available())
      Serial.write(uart.read());
}

// if user has entered data, send to wifi...
void readConsole() {
   while (Serial.available()) 
      uart.write(Serial.read()); 
}   

void displayIntro() {
  Serial.println("************************************************************************");
  Serial.println("* You should now be in command mode.  Make sure that all commands you  *");
  Serial.println("* enter are terminated with CR. Try entering:                          *");
  Serial.println("* get everything                                                       *");
  Serial.println("* For more commands, refer to the command interface document at :      *");
  Serial.println("* www.stickybug.info/user-uploads/Sticky/WifiBUG/command-interface.pdf *");
  Serial.println("************************************************************************");  
}

// program setup...
void setup() {

   // initialise serial ports...
   uart.begin(9600);
   Serial.begin(9600);

   // enter command mode - we don't know starting state, so send
   // exit to ensure we move from data state to command state...
   Serial.println("entering command mode...");
   uart.print("exit\r");  
   delay(250);           // must wait 250ms
   uart.print("$$$");    // the $$$ with no CR
   delay(250);           // wait another 250ms
   readWifi();           // display wifi output
   displayIntro();
}

// main program entry point...
void loop() {
   readWifi();
   readConsole();
}