Forum >Romeo with Wifi Bee-RN-XV
ArduinoGeneral

Romeo with Wifi Bee-RN-XV

userHead arino 2014-05-08 08:13:36 5847 Views9 Replies
Hi :)

I am trying to send commands over the wifi to my romeo v2 controller with the Wifi Bee-RN-XV on it.
Is there someone who has some example code? I am stuck. I tried to send a command with the iArd app on the iphone but somehow the romeo board doesn't get it.

By the way: It seems to me, that sometimes after a new upload it cant connect and sometimes it can. So I have to upload many times until eventually it connects to my wifi router.

[code]char recv[512];
int cont;
String ESSID = "xxx";
String password = "xxx";
String inputString; // string to store HTML stuff
String inputString2; // string to store IP stuff
String ip;

void setup() {
Serial.begin(9600);
Serial1.begin(9600);
delay(1000);
Serial.println("program start");

digitalWrite(13, HIGH);
Serial1.print("$$$");
delay(300);
Serial1.println(); check();
Serial1.print("set w s "); // set your wireless name
Serial1.println(ESSID); check();
Serial1.print("set w p "); // Set your wireless password
Serial1.println(password); check();
Serial1.print("set ip localport 80\r");check(); // set default port to access your device. 80 for webservers
Serial1.println("set ip dhcp 1");check();
delay(300);

//Serial1.println("set wlan join 4");check();
//Serial1.println("set wlan ssid rn171");check();
//Serial1.println("set wlan chan 1");check();
//Serial1.println("set ip address 192.168.0.18");check();
//Serial1.println("set ip netmask 255.255.0.0");check();
//Serial1.println("set ip dhcp 0");check();

Serial1.println("save"); check();// save it forever and ever
Serial1.println("reboot"); check();// reboot to load configuration
delay(500);
Serial1.print("$$$");
Serial1.println();
delay(300); check();
Serial1.print("join UPC0048145\r");
delay(300); check();
digitalWrite(13, LOW);

Serial.println("IP configuration");
Serial1.println("get ip");
delay(300);
check();
}

void loop() {
//If we have a client Read all the browser data.
while(Serial1.available()>0){

digitalWrite(13, HIGH);
char inChar = (char)Serial1.read();
inputString += inChar;
if(inputString.length()>0 && inChar == '\n'){
inputString.trim(); // trim it down to avoid using too much RAM

if(inputString.indexOf("HTTP") >0)
{
Serial.println("if HTTP cp");
putHTML("test");
}
inputString = "";
}
}
delay(300);
digitalWrite(13, LOW);
}

void putHTML(String iStr){

Serial1.println(iStr);
Serial1.println("AnalogRead(2)");
Serial1.println(analogRead(2));
// Close the connection from the Bee manually
delay(300);
Serial1.print("$$$"); //enter command mode
delay(300);
Serial1.println();
Serial1.println("close"); // Close the connection so the port is open for others
Serial1.println("exit"); // Exit command mode
}

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

Thank you very much!

2014-05-30 22:03:02 I've seen a lot of posts online about it, can you elaborate on what didn't work?

Seems that you might be able to do it hardware way by triggering some pin.
Anyway, I believe the steps/ at commands required should be something like:

Disable dhcp
Name your ESSID
set ip (not sure)
set ad hoc mode

Why do you require adhoc mode? what is your application ?

userHeadPic Jose
2014-05-28 10:14:00 I tried it once with the rn-xv manual. but it didnt work. That means, I could not see the AP/Adhoc with my iphone or computer  :o userHeadPic arino
2014-05-26 21:18:49 We don't have a sample code for Ad-hoc or AP. But should be an extra line or two on the current sample code.
The datasheet should have the information regarding the command.
Did you manage or had any problems to get it to adhoc or AP in your code?
userHeadPic Jose
2014-05-25 15:59:28 I dont think it is a range issue. battery is full. i have just a light sensor attached.
I have no idea.

Nevertheless, do you have an example code to use the Wifi bee in the Adhoc mode or in the AP mode?
Then it does not have to connect to a router.

Thank you :)
userHeadPic arino
2014-05-23 19:47:20 Could it be a wifi range issue?
Make sure battery is fully charger as well. Low power could cause strange behavior

What else have you attached to your Romeo, and what code are you using?
userHeadPic Jose
2014-05-23 10:34:17 Hi Jose

It seems to me that the wifi bee rn-xv on the romeo v2 board disconnects sometime even if there is no code uploading respectively no reseting going on...

Do you know why that happens?
userHeadPic arino
2014-05-12 21:39:33 [quote="arino"]
I don't want to bother you too much, but I try now my other wifi bees from dfrobots on other boards like for example the Stalker v2.3 (not from dfrobot sorry :( ) with Atmega328 3.3V 8Mhz. Sorry, I tried to contact them over the forum but they never reply. Maybe I could ask you for a hint?
[/quote]
haha, I'm sorry for you  ;)
I'll try to help, but I don't have this platform so I am unaware of what causes this issue.

[quote="arino"]
It seems, that my Wifi bee does not respond to commands like Serial.print("$$$"); do you have a hint?
It seems to me, that when the Wifi bee is on that board it cant even connect to the router.
[/quote]
Try to check whether or not the Serial pins are connected and how. Follow Rx and Tx. Maybe they are not connected?
Did you manage to reverse the pins?

check out this other options just in case.I'm not sure what you are trying to do but it might help to get it working:
[url=https://www.dfrobot.com/index.php?route=product/product&filter_name=leonardo&product_id=832]https://www.dfrobot.com/index.php?route=product/product&filter_name=leonardo&product_id=832[/url]
[url=https://www.dfrobot.com/index.php?route=product/product&filter_name=xboard%20relay&product_id=837]https://www.dfrobot.com/index.php?route=product/product&filter_name=xboard%20relay&product_id=837[/url]
[url=https://www.dfrobot.com/index.php?route=product/product&filter_name=expansion%20shield&product_id=1009]https://www.dfrobot.com/index.php?route=product/product&filter_name=expansion%20shield&product_id=1009[/url]
userHeadPic Jose
2014-05-11 08:12:34 Hi Jose

That was exactly the problem! It is not necessary to have that many delays and to set the settings that often neither!! Thank you so much.

I don't want to bother you too much, but I try now my other wifi bees from dfrobots on other boards like for example the Stalker v2.3 (not from dfrobot sorry :( ) with Atmega328 3.3V 8Mhz. Sorry, I tried to contact them over the forum but they never reply. Maybe I could ask you for a hint?

It seems, that my Wifi bee does not respond to commands like Serial.print("$$$"); do you have a hint?
It seems to me, that when the Wifi bee is on that board it cant even connect to the router.

[code]// Date and time functions using DS3231 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "DS3231.h"

DS3231 RTC; //Create the DS3231 object

char recv[512];
int cont;

void setup ()
{
    delay(2000);
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
    delay(300);
    Serial.print("$$$");
    delay(300);
    Serial.println();
    check();
}

void loop ()
{
    RTC.convertTemperature();            //convert current temperature into registers
    Serial.print(RTC.getTemperature()); //read registers and display the temperature
    Serial.println("deg C");
    delay(1000);
}

void check(){
  cont=0;
  delay(300);
  // Receive the answer from the WIFI module.
  while (Serial.available()>0)
    {
      recv[cont]=Serial.read();
      cont++;
    }
  recv[cont]='\0';
  // Print the answer.
  Serial.println(recv);
  // Clean the buffer to be able to send a command.
  delay(3000);
}[/code]
userHeadPic arino
2014-05-08 23:48:26 Welcome Arino!

For your check function:
Looks like has too many delays(), this can cause issues with serial. If you are just reading the serial, you should not need any delay.
Serial.println(recv); does it print anything at all? maybe you need to put a loop and print char by char on the whole array.
I think Serial.flush() does not clean the buffer in latest arduino versions.
another tip, is that the function name does not exactly check. perhaps you should call it something else.

try the whole function out of the main code first to find out what it is doing:
[code]
char recv[512];
int cont;

void setup() {
  Serial.begin(9600);
}

void loop() {
  cont=0;
  while (Serial.available()>0)
  {
    recv[cont]=Serial.read();
    cont++;
  }
  recv[cont]='\0';
  Serial.println(recv);
  delay(3000);
}
[/code]

I think there is another issue that i see potentially dangerous. You are setting the ESSID twice, every time you run the program. The first few lines should be done just once.
The lines:
  Serial1.println("save"); check();// save it forever and ever
  Serial1.println("reboot"); check();// reboot to load configuration

Will save the configuration and it will remain after power off. Perhaps instead of reboot, it should do this:
while(true){} so it does nothing until you change the configuration parameters.

the definition of:
#ifdef firsttime
In the wiki example means that it should be run or loaded once.
Running this every time you turn on the board, will reset the configuration. doing it many times will drive the router crazy probably hehe
userHeadPic Jose