Libelium is offering new technical support channels, to contact with de Technical Support team to solve any issue our doubt please contact with your sales agent or visit our contact site



Post a new topicPost a reply Page 1 of 1   [ 10 posts ]
Author Message
 Post subject: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Fri May 12, 2017 5:11 am 

Joined: Fri May 12, 2017 4:59 am
Posts: 5
Hi,

I am trying to connect to the wifi module using arduino and send get data over it.
I have followed your tutorial (https://www.cooking-hacks.com/documenta ... -tutorial/) but it doesnot seems to work for me.
I had tested the code and the "Serial.available()" value is always returns 0 for me and also it shows error connecting to the wifi.
I cannot to the wifi through this code, but if i try manually entering the commands in the serial monitor, the wifi module gets connected.

I have tried putting some delays before the Serial.available() line but no use.

I am using arduino uno 3 board and roving RN-XV as wifi module and i am using a windows 10 machine.

Please let me know what i am doing wrong here .
Thank u


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Fri May 12, 2017 8:01 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi nikhilR,

Trying this code with Arduino IDE 1.8.2, the module connects correctly:

Code:
/* 
 *  Wifi Module
 * 
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L.
 *  http://www.libelium.com
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  a
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/.
 * 
 *  Version:           2.0
 *  Design:            David Gascón
 *  Implementation:    Marcos Martinez & Victor Boria
 */


//Enter here your data
const char wifi_ssid[] = "*********";
const char wifi_password[] = "*********";

const char server[] = "test.libelium.com";
const char server_port[] = "80";
const char GET[] = "test-get-post.php?a=1&b=2";

int8_t answer;
char response[300];
char response2[100];
int cont;
char aux_str[50];


void setup()
{
  //Write here you correct baud rate
  Serial.begin(9600);
  //Serial.begin(115200);
 
  wificonfig();
}

void loop()
{
 
  Serial.println(F("Sending HTTP GET"));
  sendGET();
  delay(5000);
}


void wificonfig() {
 
  Serial.println(F("Setting Wifi parameters"));
  sendCommand("exit\r","EXIT",2000);
  delay(2000);
 
  enterConfig(2000);
  sendCommand("leave\r","DeAuth",2000);
  delay(1000);
  // Sets DHCP and TCP protocol
  sendCommand("set ip dhcp 1\r","AOK",2000);
  delay(1000);   
  sendCommand("set ip protocol 18\r","AOK",2000);
  delay(1000); 

  // Configures the way to join the network AP, sets the encryption of the
  // network and joins it
  sendCommand("set wlan join 0\r","AOK",2000); //The auto-join feature is disabled
  delay(1000);

  snprintf(aux_str, sizeof(aux_str), "set wlan phrase %s\r", wifi_password);
  sendCommand(aux_str,"AOK",2000);
  delay(1000);   
  snprintf(aux_str, sizeof(aux_str), "join %s\r", wifi_ssid);
  answer = sendCommand(aux_str,"Associated",10000);


  if (answer == 1){

    snprintf(aux_str, sizeof(aux_str), "Connected to \"%s\"", wifi_ssid);
    Serial.println(aux_str);
    delay(5000);
  }

  else {
    snprintf(aux_str, sizeof(aux_str), "Error connecting to: \"%s\"", wifi_ssid);
    Serial.println(aux_str);
    delay(1000);
  }


  Serial.println(F("Wifi succesfully configured"));
  delay(1000);
}



void sendGET() {
 
  enterConfig(2000);
  sendCommand("set i h 0\r","AOK",2000);
  delay(1000);
  snprintf(aux_str, sizeof(aux_str), "set d n %s\r", server);
  sendCommand(aux_str,"AOK",2000);

  delay(1000);
  //Configures HTTP connection
  snprintf(aux_str, sizeof(aux_str), "set i r %s\r", server_port);
  sendCommand(aux_str,"AOK",2000);
  delay(1000); 

  sendCommand("set o f 1\r","AOK",2000);
  delay(1000);

  snprintf(aux_str, sizeof(aux_str), "set c r GET$/%s\r", GET);
  sendCommand(aux_str,"AOK",10000);
  delay(1000);

  // Calls open to launch the configured connection.
  sendCommand("open\r","*CLOS*",10000);
  delay(1000);

  findResponse();

}


void findResponse(){
  boolean go_On = true;
  uint16_t counter = 0;

  while (go_On){

    if (response[counter] == '\r'){

      if (response[counter+1] == '\n'){

        if (response[counter+2] == '\r'){

          if (response[counter+3] == '\n'){

            go_On = false;
          }

        }   

      }      

    }

    counter++;
  }
  counter = counter + 3;

  for (int i=0;response[i+counter]!='*'; i++){
    response2[i] = response[i+counter];
    delay(100);


  }

  snprintf(aux_str, sizeof(aux_str), "GET response:\"%s\"", response2);
  Serial.println(aux_str);


}


int8_t sendCommand(const char* Command, const char* expected_answer, unsigned int timeout){

  uint8_t x=0,  answer=0;
  unsigned long previous;

  memset(response, 0, 300);    // Initialize the string

  delay(100);

  while( Serial.available() > 0) Serial.read();    // Clean the input buffer

  Serial.println(Command);    // Send Command

    x = 0;
  previous = millis();

  // this loop waits for the answer
  do{
    if(Serial.available() != 0){   
      // if there are data in the UART input buffer, reads it and checks for the asnwer
      response[x] = Serial.read();
      x++;
      // check if the desired answer  is in the response of the module
      if (strstr(response, expected_answer) != NULL)   
      {
        answer = 1;
      }
    }
  }
  // Waits for the asnwer with time out
  while((answer == 0) && ((millis() - previous) < timeout));   

  return answer;
}


int8_t enterConfig(unsigned int timeout){

  uint8_t x=0,  answer=0;
  unsigned long previous;

  memset(response, 0, 300);    // Initialize the string

  delay(100);

  while( Serial.available() > 0) Serial.read();    // Clean the input buffer

  Serial.print("$$$");    // Send Command


  x = 0;
  previous = millis();

  // this loop waits for the answer
  do{
    if(Serial.available() != 0){   
      // if there are data in the UART input buffer, reads it and checks for the asnwer
      response[x] = Serial.read();
      x++;
      // check if the desired answer  is in the response of the module
      if (strstr(response, "CMD") != NULL)   
      {
        answer = 1;
      }
    }
  }
  // Waits for the asnwer with time out
  while((answer == 0) && ((millis() - previous) < timeout));   

  return answer;
}
       


If it doesn't work for you, try to reset the module with the next commands:

Code:
$$$
factory RESET
reboot


If it still doesn't work, please can you copy here your serial monitor?

Thanks.

Regards


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Tue May 16, 2017 1:12 pm 

Joined: Fri May 12, 2017 4:59 am
Posts: 5
Hi @libelium-dev

I have tried that code and also tried factory reset but still it doesn't solve the issue.
As requested by you this is my serial monitor result


Quote:
Setting Wifi parameters
exit

$$$leave

set ip dhcp 1

set ip protocol 18

set wlan join 0

set wlan phrase password <-my wifi password has been put here

join admin

Error connecting to: "admin"
Wifi succesfully configured
Sending HTTP GET
$$$set i h 0

set d n test.libelium.com

set i r 80

set o f 1

set c r GET$/test-get-post.php?a=1&b=2

open


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Wed May 17, 2017 7:12 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi nikhilR,

It is very strange that you can configure and connect to the Internet using the module manually and not with the sketch.

Are you sure that you have written the name of the WiFi network and the password correctly? (Upper case and lower case).

Can you show us which commands do you send manually?

Can you upload some photos to see your hardware configuration?

When you use the sketch, do you put your XBee shield in Arduino position?

Thanks.

Regards


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Thu May 18, 2017 5:42 am 

Joined: Fri May 12, 2017 4:59 am
Posts: 5
Hi,

I am doing everything exactly similar to what is given in this link
https://www.cooking-hacks.com/blog/tutorial-wifi-module-for-arduino-roving-rn-xvee/
Quote:
Are you sure that you have written the name of the WiFi network and the password correctly? (Upper case and lower case).

Yes. I am using the same for manual


Quote:
Can you show us which commands do you send manually?


This are the manual commands i have used
Code:
CMD
set ip dhcp 1

AOK
<4.41>
set ip protocol 18

AOK
<4.41>
set wlan join 1

AOK
<4.41>
set wlan phrase 12345678

AOK
<4.41>
join admin

<4.41> Auto-Assoc admin chan=1 mode=MIXED SCAN OK

Joining admin now..
Associated!
DHCP: Start
DHCP in 5032ms, lease=3600s
IF=UP
DHCP=ON
IP=192.168.43.133:2000
NM=255.255.255.0
GW=192.168.43.1
Listen on 2000



Refrence url : https://www.cooking-hacks.com/documentation/tutorials/wifi-module-for-arduino-raspberry-pi-roving-rn-xvee-tutorial/

Quote:
When you use the sketch, do you put your XBee shield in Arduino position?

what did u mean by this?

FYI i am using arduino uno r3 , does that make any difference?


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Thu May 18, 2017 7:19 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi nikhilR,

nikhilR wrote:
what did u mean by this?

FYI i am using arduino uno r3 , does that make any difference?


How are you connecting the module to the Arduino? Can you upload some photos?

Thanks.

Regards


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Thu May 18, 2017 7:39 am 

Joined: Fri May 12, 2017 4:59 am
Posts: 5
Hi
Quote:
How are you connecting the module to the Arduino? Can you upload some photos?


Please see this

http://ibb.co/fKuUi5
http://ibb.co/mgkfqk
http://ibb.co/kFHtAk
http://ibb.co/h6EJbQ


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Thu May 18, 2017 8:03 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi nikhilR,

As you can see in the XBee shield, there is a "switch" labeled with "XBee and USB". Once you have uploaded the sketch, you need to put this switch in the XBee position

You can work with the XBee shield in two ways:
· Using the module with commands (Gateway mode): In this mode you need to send the commands manually using a serial monitor. (Switch must be in USB position).

· Using the shield in standalone mode: In this mode you do a program that runs automatically. (Switch must be in XBee position).

Regards


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Thu May 18, 2017 8:55 am 

Joined: Fri May 12, 2017 4:59 am
Posts: 5
Hi libelium-dev,

It is working now.
Thank you so much for your patience and help.
:)


Top
 Profile  
 
 Post subject: Re: Wifi Module for Arduino "Roving RN-XVee"
PostPosted: Fri May 19, 2017 7:17 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi nikhilR,

Nice to read it! :)

Good luck with your project.

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 10 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use.