Cooking Hacks Forum
https://www.cooking-hacks.com/forum/

roving (RN-171) RN-XV wifi + xbee shield never works
https://www.cooking-hacks.com/forum/viewtopic.php?f=43&t=5376
Page 1 of 1

Author:  user7077 [ Sun Jan 19, 2014 1:26 am ]
Post subject:  roving (RN-171) RN-XV wifi + xbee shield never works

My arduino setup has the RN-XV wifi module on top of the Xbee shield on top of the ehealth shield on top of arduino rev2 (software serial 0,1). After uploading arduino wifi/wifly examples, the RN-XV green blinks and sometimes both the green and red blink.
I bought these recently.
I have tried using the DHCP HTTP router Ap example
Code:
char recv[512];
int cont;

void setup()
{

Serial.begin(9600);
}

void loop()
{
while (Serial.available()>0) {}
// Enters in command mode
Serial.print("$$$"); check();

// Sets DHCP and TCP protocol
Serial.print("set ip dhcp 1\r"); check();
Serial.print("set ip protocol 2\r"); check();

// Configures the way to join the network AP, sets the encryption of the
// network and joins it
Serial.print("set wlan join 0\r"); check();
Serial.print("set wlan phrase PASSWORD\r"); check();
Serial.print("join libelium_wsn2\r"); check();

// Sets the DNS address
Serial.print("set i h 0\r"); check();
Serial.print("set d n www.URL.com\r"); check();

//Configures HTTP connection
Serial.print("set i r 80\r"); check();
Serial.print("set c r GET$/...\r"); check();
Serial.print("set o f 1\r"); check();

// Calls open to launch the configured connection.
Serial.print("open\r"); check();
}

void check(){
cont=0; delay(1000);
// Receive the answer from the WIFI module.
while (Serial.available()>0)
{
recv[cont]=Serial.read(); delay(100);
cont++;
}
recv[cont]='\0';
// Print the answer.
Serial.println(recv);
// Clean the buffer to be able to send a command.
Serial.flush(); delay(1000);
}


I have tried also the WiFlyHQ library and httpserver.ino examples to connect the arduino system to an SSID (my home ssid and password) but the RN-XV has never worked so far

Code:
/*
 * WiFlyHQ Example httpserver.ino
 *
 * This sketch implements a simple Web server that waits for requests
 * and serves up a small form asking for a username, then when the
 * client posts that form the server sends a greeting page with the
 * user's name and an analog reading.
 *
 * This sketch is released to the public domain.
 *
 */

 /* Notes:
  * Uses chunked message bodies to work around a problem where
  * the WiFly will not handle the close() of a client initiated
  * TCP connection. It fails to send the FIN to the client.
  * (WiFly RN-XV Firmware version 2.32).
  */

/* Work around a bug with PROGMEM and PSTR where the compiler always
 * generates warnings.
 */
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))

#include <WiFlyHQ.h>

#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(8,9);

//#include <AltSoftSerial.h>
//AltSoftSerial wifiSerial(8,9);

WiFly wifly;

/* Change these to match your WiFi network */
const char mySSID[] = "myssid";
const char myPassword[] = "my-wpa-password";

void sendIndex();
void sendGreeting(char *name);
void send404();

char buf[80];

void setup()
{
    Serial.begin(115200);
    Serial.println(F("Starting"));
    Serial.print(F("Free memory: "));
    Serial.println(wifly.getFreeMemory(),DEC);

    wifiSerial.begin(19200);
    if (!wifly.begin(&wifiSerial, &Serial)) {
        Serial.println(F("Failed to start wifly"));
   wifly.terminal();
    }

    /* Join wifi network if not already associated */
    if (!wifly.isAssociated()) {
   /* Setup the WiFly to connect to a wifi network */
   Serial.println(F("Joining network"));
   wifly.setSSID(mySSID);
   wifly.setPassphrase(myPassword);
   wifly.enableDHCP();
   wifly.save();

   if (wifly.join()) {
       Serial.println(F("Joined wifi network"));
   } else {
       Serial.println(F("Failed to join wifi network"));
       wifly.terminal();
   }
    } else {
        Serial.println(F("Already joined network"));
    }

    wifly.setBroadcastInterval(0);   // Turn off UPD broadcast

    //wifly.terminal();

    Serial.print(F("MAC: "));
    Serial.println(wifly.getMAC(buf, sizeof(buf)));
    Serial.print(F("IP: "));
    Serial.println(wifly.getIP(buf, sizeof(buf)));

    wifly.setDeviceID("Wifly-WebServer");

    if (wifly.isConnected()) {
        Serial.println(F("Old connection active. Closing"));
   wifly.close();
    }

    wifly.setProtocol(WIFLY_PROTOCOL_TCP);
    if (wifly.getPort() != 80) {
        wifly.setPort(80);
   /* local port does not take effect until the WiFly has rebooted (2.32) */
   wifly.save();
   Serial.println(F("Set port to 80, rebooting to make it work"));
   wifly.reboot();
   delay(3000);
    }
    Serial.println(F("Ready"));
}

void loop()
{
    if (wifly.available() > 0) {

        /* See if there is a request */
   if (wifly.gets(buf, sizeof(buf))) {
       if (strncmp_P(buf, PSTR("GET / "), 6) == 0) {
      /* GET request */
      Serial.println(F("Got GET request"));
      while (wifly.gets(buf, sizeof(buf)) > 0) {
          /* Skip rest of request */
      }
      sendIndex();
      Serial.println(F("Sent index page"));
       } else if (strncmp_P(buf, PSTR("POST"), 4) == 0) {
           /* Form POST */
           char username[16];
           Serial.println(F("Got POST"));

      /* Get posted field value */
      if (wifly.match(F("user="))) {
          wifly.gets(username, sizeof(username));
          wifly.flushRx();      // discard rest of input
          sendGreeting(username);
          Serial.println(F("Sent greeting page"));
      }
       } else {
           /* Unexpected request */
      Serial.print(F("Unexpected: "));
      Serial.println(buf);
      wifly.flushRx();      // discard rest of input
      Serial.println(F("Sending 404"));
      send404();
       }
   }
    }
}

/** Send an index HTML page with an input box for a username */
void sendIndex()
{
    /* Send the header direclty with print */
    wifly.println(F("HTTP/1.1 200 OK"));
    wifly.println(F("Content-Type: text/html"));
    wifly.println(F("Transfer-Encoding: chunked"));
    wifly.println();

    /* Send the body using the chunked protocol so the client knows when
     * the message is finished.
     * Note: we're not simply doing a close() because in version 2.32
     * firmware the close() does not work for client TCP streams.
     */
    wifly.sendChunkln(F("<html>"));
    wifly.sendChunkln(F("<title>WiFly HTTP Server Example</title>"));
    wifly.sendChunkln(F("<h1>"));
    wifly.sendChunkln(F("<p>Hello</p>"));
    wifly.sendChunkln(F("</h1>"));
    wifly.sendChunkln(F("<form name=\"input\" action=\"/\" method=\"post\">"));
    wifly.sendChunkln(F("Username:"));
    wifly.sendChunkln(F("<input type=\"text\" name=\"user\" />"));
    wifly.sendChunkln(F("<input type=\"submit\" value=\"Submit\" />"));
    wifly.sendChunkln(F("</form>"));
    wifly.sendChunkln(F("</html>"));
    wifly.sendChunkln();
}

/** Send a greeting HTML page with the user's name and an analog reading */
void sendGreeting(char *name)
{
    /* Send the header directly with print */
    wifly.println(F("HTTP/1.1 200 OK"));
    wifly.println(F("Content-Type: text/html"));
    wifly.println(F("Transfer-Encoding: chunked"));
    wifly.println();

    /* Send the body using the chunked protocol so the client knows when
     * the message is finished.
     */
    wifly.sendChunkln(F("<html>"));
    wifly.sendChunkln(F("<title>WiFly HTTP Server Example</title>"));
    /* No newlines on the next parts */
    wifly.sendChunk(F("<h1><p>Hello "));
    wifly.sendChunk(name);
    /* Finish the paragraph and heading */
    wifly.sendChunkln(F("</p></h1>"));

    /* Include a reading from Analog pin 0 */
    snprintf_P(buf, sizeof(buf), PSTR("<p>Analog0=%d</p>"), analogRead(A0));
    wifly.sendChunkln(buf);

    wifly.sendChunkln(F("</html>"));
    wifly.sendChunkln();
}

/** Send a 404 error */
void send404()
{
    wifly.println(F("HTTP/1.1 404 Not Found"));
    wifly.println(F("Content-Type: text/html"));
    wifly.println(F("Transfer-Encoding: chunked"));
    wifly.println();
    wifly.sendChunkln(F("<html><head>"));
    wifly.sendChunkln(F("<title>404 Not Found</title>"));
    wifly.sendChunkln(F("</head><body>"));
    wifly.sendChunkln(F("<h1>Not Found</h1>"));
    wifly.sendChunkln(F("<hr>"));
    wifly.sendChunkln(F("</body></html>"));
    wifly.sendChunkln();
}



The serial monitor keeps returning the error:
Code:
Starting
Free memory: 979
setPrompt failed
Failed to enter command mode
Failed to start wifly


not able to enter command mode ($$$) either
Why is the error occurring and how can the RN-XV wifi be fixed?
Thank you

Author:  libelium-dev [ Mon Jan 20, 2014 8:25 am ]
Post subject:  Re: roving (RN-171) RN-XV wifi + xbee shield never works

Hi user7077,

Could you post some photo about hardware connection?

Regards.

Author:  zipi [ Thu Mar 20, 2014 3:32 pm ]
Post subject:  Re: roving (RN-171) RN-XV wifi + xbee shield never works

Hello,

I am having the same problem. Did you solve it, user7077?

However, my arduino setup has the RN-XV wifi module on top of the Xbee shield on top of arduino UNO.

Thank you!

Author:  libelium-dev [ Fri Mar 21, 2014 10:08 am ]
Post subject:  Re: roving (RN-171) RN-XV wifi + xbee shield never works

If the community knows how to help you with your questions we will be glad to hear about it.

Post in our community category.

Regards.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/