Go Down

Topic: SOLVED: Getting unexpected characters in data from WiFly Bee (Read 1 time) previous topic - next topic

strykeroz

Feb 24, 2012, 11:05 am Last Edit: Feb 25, 2012, 10:30 am by strykeroz Reason: 1
Hi

I'm using a WiFly bee mounted in a Bees Shield which is accessed using the SoftwareSerial library.  I've had some success with it, but find the comms unreliable as the information read back from the bee is overlaid by what appears to be random noise.  I'm hoping this will be familiar to someone here, and you'll be able to point me in the right direction to solving it.

To illustrate, I'll use a sequence of commands on the WiFly which generate no HTTP traffic to display, so this is simply command line stuff which .  In terraterm, here's these commands and the responses:
Code: [Select]
CMD
show connection
8130
<2.31> lites
<2.31> lookup google.com
google.com=74.125.237.128
<2.31> lites
<2.31> exit
EXIT

The initial CMD is in response to $$$ to enter command mode, which isn't echoed.  So I created a test script to send these same lines to the WiFly Bee, with a short delay and then echo the contents of the WiFly buffer out to the serial port.  Sketch here :
Code: [Select]
#include <SoftwareSerial.h>

// WiFly bee is using pins 2 & 3 on the Arduino
SoftwareSerial WiFly(2, 3);
const int waitTime = 2000;

void setup(void) {
 // start serial port
 Serial.begin(9600);
 WiFly.begin(9600);                                   // set the data rate for the SoftwareSerial port
 for (int i=0; i<15; i++) delay(1000);                // allow 15 secs to reset WiFly bee manually
}

void doWiFlyCommand(char* commandString) {
 // write string to WiFly bee's serial buffer,
 // wait a small while,
 // then read WiFly bee's serial output buffer for results
 for(int idx = 0; commandString[idx] != '\0'; idx++) WiFly.write(commandString[idx]);
 WiFly.println();
 delay(waitTime);
 while(WiFly.available()) Serial.write(WiFly.read());
 Serial.println();
}

void loop(void) {
 Serial.println("=============================================================================================");
 delay(300);                                          // 250ms delay either side of command mode signal
 WiFly.print("$$$");
 delay(300);                                          // 250ms delay in going into command mode in the WiFly
 while (WiFly.available()) Serial.write(WiFly.read());
 Serial.println();
 doWiFlyCommand("show connection");                    // status of WiFly bee
 doWiFlyCommand("lites");                              // on-board disco light show
 doWiFlyCommand("lookup google.com");                  // DNS lookup
 doWiFlyCommand("lites");                              // turn off light-show
 doWiFlyCommand("exit");                              // depart command mode
}

But the result is somewhat different. Note also that the unexpected characters change each loop through, so it's not predictable (or at least a pattern I recognise, but I'm really hoping you do?).  
Code: [Select]
=============================================================================================
CMD

s½ÿÿo+ÿctikÖL³Ì?
<2.31>

lÑÿe5ÖLf˳1>

l½ÿkÁÿ ½ÿÿle.cok¦ügoogle.com=74.125.237.134
<2.31>

Ñÿes5f?&æl³fÏ

e¥ÿt
)V
-µa?
=============================================================================================
CMD

shÝÿÿ¹ÿ+ÿctsÿ
S?6ÖL&æl³fÏ

¥ÿtÍÿ
SÆ&æl³fÏ

l½ÿkÁÿ ½ÿÿ?ÿÿom
SvÛÛÛ6mÙ?com=74.125.237.134
<2.31>

¥ÿtÍÿ
SÆ&æl³fÏ

e¥ÿt5V¬kÒª

=============================================================================================
CMD

s½ÿÿsÿec{ÿn
8130
<2.31>

lÑÿe5ÖLfË?1>

l½ÿkÁÿ ½ÿÿ?ÿ.cok¦ì¶ÛÛ6mÙ?com=74.125.237.134
<2.31>

lÑÿe5ÖLfË31>

e¥ÿt5¦¬kÒª

=============================================================================================
CMD

sÝÿÿonneKÿon
8130
<2.31>

¥ÿtÍÿ
#Æ&æl³fÏ

½ÿokÁÿ ½ÿÿ?ÿÿµÿ
SvÛÛÛ6mÙ?com=74.125.237.134
<2.31>

lÑÿe5kLfË?1>

e¥ÿt5S¬kÒª

=============================================================================================
CMD

s½ÿÿsÿeKÿon
8130
<2.31>

lÑÿe5ÖLfË?1>

l½ÿkÁÿ ½ÿÿ?ÿ.com
SvÛÛÛ6mÙ?com=74.125.237.134
<2.31>

¥ÿtÍÿ
SÆ&æl³fÏ

e¥ÿt5¦¬kÒª


I've tested this on two different WiFly Bees, on multiple Arduinos and two Bees Shields to try to eliminate hardware failings.  You can also see the legitimate responses are in there, just not always identifiable, and the sequence of commands actually does run as evidenced by the DNS lookup and the LED light show each loop through.

Thanks for reading this far...any ideas?
Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

strykeroz

Hi,

Further testing.  Added a test for buffer overflow to the function that outputs the commands.
Code: [Select]
void doWiFlyCommand(char* commandString) {
  // write string to WiFly bee's serial buffer,
  // wait a small while,
  // then read WiFly bee's serial output buffer for results
  for(int idx = 0; commandString[idx] != '\0'; idx++) WiFly.write(commandString[idx]);
  WiFly.println();
  delay(waitTime);
  while(WiFly.available()) {
   if (WiFly.overflow()) Serial.println("<<<OVERFLOW!>>>");
   Serial.write(WiFly.read());
  }
  Serial.println();
}


At 115200 the issue is far more pronounced, perhaps, but again teraterm at the same baud rate is flawless.
Code: [Select]
=============================================================================================
CMD
?
7öÛ÷nû?û[ö÷íû[¬?1?0
?<23?>dá
[ûWö¯¬??æ?ó¦ü
Ûû[ûìû÷ÿû?ùÛý[X?ض{ce?cm?7fY?³3?6»æ?&Ö¦?2?31? ð
[ûwö·X??æ¶æþ

6÷ûX?¬-­??ø
=============================================================================================
C¦D
?
s´owc??[Û6·í?
?
8?30?
<?.ó¦þ
[ýmX?&s6æ¦ü
Ûû·ÿéû{ÿû6ùÛû[XLض{c.±om?74?125?237YÙ3f???s6æSþ
-û?ÿk¦Æ?æ6?æSþ
O¬?¬-­??ø

However at the other extreme, setting things all up at 2400 (on WiFly and in the instantiation of SoftwareSerial in the sketch) does not improve things.
Code: [Select]
CMD

s´ow ½ÿ¹ÿeÑÿ½ÿn5¦ 6ÖL&æl³f?

lÑÿes
<2.31>

looÕÿpÿoÿ?ÿ.½ÿ5ÖLض·gle.com=74.125.237.130
<2.31>

£e5ÖLfË31>

exi5ÖLX4kT

=============================================================================================
CMD

¡ÿoþc¹ÿ?ÿK¹ÿ5¦ 6ÖL&æl³f?

lite5ÖLfË31>

½ÿokÁÿ ½ÿÿl¹þ½ÿm5¦ì¶ÛÛ6mÙ?com=74.125.237.130
<2.31>

lÑÿes
S?&æl³f?

exi[a?EXIT

=============================================================================================
CMD

shÝÿ ½ÿ¹ÿeÑÿ½ÿk¦³Ì?0
<2.31>

li?ÿs
S?&æl³f?

ÿuþg½ÿg?ÿÿo5ÖLøgoogle.com=74.125.237.131
<2.31>

£e5ÖLfË31>

exi5ÖLX4kT

So...still none the wiser.

Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

PaulS

Code: [Select]
  while (WiFly.available()) Serial.write(WiFly.read());
What does the WiFly.read() function return? ASCII or binary data? If it is ASCII, why are you using Serial.write() to send it to the serial monitor? I think you should be using Serial.print(), AND I think you should be storing the returned value in the appropriate type variable.

There have been lots of issues with "noise" that have been caused by just this sort of processing that have been solved by:
Code: [Select]
char aChar = WiFly.read();
Serial.print(aChar);

strykeroz

Hi PaulS

Thanks for looking into this.  I was under the impression Serial.print() and Serial.write() were essentially the same for character data?

But FWIW that code is lifted directly from the SoftwareSerial example sketch "SoftwareSerialExample"
Code: [Select]
void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

I'll give what you suggest a crack though, at this stage I'm taking any option.  Will report back when done.

Cheers ! Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

PaulS

Quote
But FWIW that code is lifted directly from the SoftwareSerial example sketch "SoftwareSerialExample"

If you are referring to the SoftwareSerial in 1.0, then the example is flawed. The chances of getting it changed in my lifetime range between slim and fat.

If you are referring to the SoftwareSerial example from 0023 or earlier, well then, you shouldn't even be using that obsolete-before-it-was-delivered library.

Go Up