Forum >DFRobot Wifi Shielf v2.1 Data Mode
DFRobot Wifi Shielf v2.1 Data Mode

Hi,
I've manage to get the DFRobot wifi shield v2.1 working by following the tutorials and referencing the manual and other documentation.
It's a little tricky at first but then you get into it.
The tutorial focusses on setting up the shield by putting the jumpers into USB/command mode then allowing you to via the serial monitor setup the shield to connect to an existing wifi network, setting up an IP address or DHCP, then setting up the shield to act as a server on port 4000, then finally saving that config and making all those commands/settings initialise the shield when it restarts again. Once the shield is restarted and the jumpers put into wifi/data mode I can get my laptop to connect to the Arduino board via the wifi shield which is great.
What I need is to have the Arduino connect to other remote sites. I've been able to do this by putting it back into command mode (via the jumpers) then instead of setting it up as a server, setting it up to connect to a specific server - in this case my laptop. This is also nice however I'd like to have the Arduino board connect to multiple servers rather than just one.
Once the board is back in wifi/data mode I've been able to write a script that programmatically tells the shield to connect to a specific server. I've done with this the following code (note it's only the command sending part):
[code]
...
Serial.print( "+++" ); // While in data mode, we can send +++ and the shield will go into command mode.
Serial.flush();
delay( 1500 ); // We need to wait for about a second, her we wait 1.5sec
Serial.println( "AT+NCTCP=192.168.1.200,80" ); // Connect to 192.168.1.200 on port 80, in this case apache
Serial.flush();
delay( 100 );
Serial.print( "\x1B" "S0" ); // Send escape character then letter 'S' and CID (in this case 0)
Serial.println( "GET "+ paramURL+ " HTTP/1.0" ); // Send GET command
Serial.println( "" );
Serial.println( "" );
Serial.print( "\x1B" "E" ); // End HTTP request, this again from documentation.
Serial.flush();
delay( 100 );
...
[/code]
So the above snippet works, it allows me to specify a server with code, send through a basic HTTP request to the web server on my laptop.
My problem however is receiving data.
From the above code I get a HTTP response, the problem however comes in when I try read the complete response. Here is an example of how I read the HTTP response from the server
[code]
...
char HTMLResponse[ 1024 ]; // Text buffer for our HTTP response, 1024 is enough for data and headers
int index = 0;
while ( Serial.available() > 0 ) {
HTMLResponse[ index ] = Serial.read();
delay( 10 );
index++;
}
...
[/code]
The problem with the above response is that it only allows me to read 64bytes of the response.
This apparently is due to the serial buffer being only 64bytes. I've checked and Serial.available() only returns at most 64 bytes. This is a problem because the headers in the HTTP response take up more than the first 64bytes of the response.
The alternative is to use the ATO command, I saw this in the same section in the manual as the bit that allows me to send +++ to enter comment mode. So by doing a ATO we're supposed to be able to kick back into data mode. Other wifi shield do this is other types of commands but in essence allow you to kick into data mode to tell the shields to connect to specific address then back back into data more to allow the code to send and receive data.
The manual states "[i]The ATO command (terminated by the ASCII character “O”, not the number 0) is used to return to data mode.[/i]"
My problem is that I can't get that ATO command right. I've tried sending ATO and ATO <ESC>O but I just can't get out of command mode. I've tried the following but no luck.
[code] Serial.print( "ATO" );
Serial.print( "\x1B" "O" );
Serial.flush();
delay( 1100 );
[/code]
and
[code] Serial.print( "\x1B" "O" );
Serial.flush();
delay( 1100 );
[/code]
I've spend a few days trying all kinds of things but just can't kick out of the command mode. I've tried "[i]Applying the “AT+XEHT=1” command (Enable Hardware Trigger), you can change between data mode and command mode using GPIO 10, without escape sequence (“+++”).[/i]" but can't get that working either.
Please help, I've spend days trying to get it work but but can't, so close but just so far.
I've manage to get the DFRobot wifi shield v2.1 working by following the tutorials and referencing the manual and other documentation.
It's a little tricky at first but then you get into it.
The tutorial focusses on setting up the shield by putting the jumpers into USB/command mode then allowing you to via the serial monitor setup the shield to connect to an existing wifi network, setting up an IP address or DHCP, then setting up the shield to act as a server on port 4000, then finally saving that config and making all those commands/settings initialise the shield when it restarts again. Once the shield is restarted and the jumpers put into wifi/data mode I can get my laptop to connect to the Arduino board via the wifi shield which is great.
What I need is to have the Arduino connect to other remote sites. I've been able to do this by putting it back into command mode (via the jumpers) then instead of setting it up as a server, setting it up to connect to a specific server - in this case my laptop. This is also nice however I'd like to have the Arduino board connect to multiple servers rather than just one.
Once the board is back in wifi/data mode I've been able to write a script that programmatically tells the shield to connect to a specific server. I've done with this the following code (note it's only the command sending part):
[code]
...
Serial.print( "+++" ); // While in data mode, we can send +++ and the shield will go into command mode.
Serial.flush();
delay( 1500 ); // We need to wait for about a second, her we wait 1.5sec
Serial.println( "AT+NCTCP=192.168.1.200,80" ); // Connect to 192.168.1.200 on port 80, in this case apache
Serial.flush();
delay( 100 );
Serial.print( "\x1B" "S0" ); // Send escape character then letter 'S' and CID (in this case 0)
Serial.println( "GET "+ paramURL+ " HTTP/1.0" ); // Send GET command
Serial.println( "" );
Serial.println( "" );
Serial.print( "\x1B" "E" ); // End HTTP request, this again from documentation.
Serial.flush();
delay( 100 );
...
[/code]
So the above snippet works, it allows me to specify a server with code, send through a basic HTTP request to the web server on my laptop.
My problem however is receiving data.
From the above code I get a HTTP response, the problem however comes in when I try read the complete response. Here is an example of how I read the HTTP response from the server
[code]
...
char HTMLResponse[ 1024 ]; // Text buffer for our HTTP response, 1024 is enough for data and headers
int index = 0;
while ( Serial.available() > 0 ) {
HTMLResponse[ index ] = Serial.read();
delay( 10 );
index++;
}
...
[/code]
The problem with the above response is that it only allows me to read 64bytes of the response.
This apparently is due to the serial buffer being only 64bytes. I've checked and Serial.available() only returns at most 64 bytes. This is a problem because the headers in the HTTP response take up more than the first 64bytes of the response.
The alternative is to use the ATO command, I saw this in the same section in the manual as the bit that allows me to send +++ to enter comment mode. So by doing a ATO we're supposed to be able to kick back into data mode. Other wifi shield do this is other types of commands but in essence allow you to kick into data mode to tell the shields to connect to specific address then back back into data more to allow the code to send and receive data.
The manual states "[i]The ATO command (terminated by the ASCII character “O”, not the number 0) is used to return to data mode.[/i]"
My problem is that I can't get that ATO command right. I've tried sending ATO and ATO <ESC>O but I just can't get out of command mode. I've tried the following but no luck.
[code] Serial.print( "ATO" );
Serial.print( "\x1B" "O" );
Serial.flush();
delay( 1100 );
[/code]
and
[code] Serial.print( "\x1B" "O" );
Serial.flush();
delay( 1100 );
[/code]
I've spend a few days trying all kinds of things but just can't kick out of the command mode. I've tried "[i]Applying the “AT+XEHT=1” command (Enable Hardware Trigger), you can change between data mode and command mode using GPIO 10, without escape sequence (“+++”).[/i]" but can't get that working either.
Please help, I've spend days trying to get it work but but can't, so close but just so far.
2012-07-13 22:59:08 {
// if there are incoming bytes available
// from the peer device, read them and print them:
while (Serial.available()) {
int in;
while ((in = Serial.read()) == -1);
Serial.print((char)in);
}
y2kgrays
// if there are incoming bytes available
// from the peer device, read them and print them:
while (Serial.available()) {
int in;
while ((in = Serial.read()) == -1);
Serial.print((char)in);
}

2012-07-10 01:21:37 [b]@y2kgrays[/b]: What method have you used to get full HTML data/pages?
If you do [b]while ( Serial.available() > 0 )[/b] and then do read each byte with [b]Serial.read()[/b] into a [b]String[/b] or [b]char[][/b] then it seems like you only get only 64 bytes or partial pages (increments of 64 bytes) not full pages.
All the examples I've seen use a while loop and [b]Serial.read()[/b], this is problematic is your JSON/XML feed is not fully downloaded.
soundf
If you do [b]while ( Serial.available() > 0 )[/b] and then do read each byte with [b]Serial.read()[/b] into a [b]String[/b] or [b]char[][/b] then it seems like you only get only 64 bytes or partial pages (increments of 64 bytes) not full pages.
All the examples I've seen use a while loop and [b]Serial.read()[/b], this is problematic is your JSON/XML feed is not fully downloaded.

2012-07-10 01:11:49 [quote="y2kgrays"]
got it sorted as below
Serial.print("+"); //put in command mode
delay(300);
Serial.print("+");
delay(300);
Serial.print("+");
delay( 5000 ); //hang round on command mode for a bit - no reason
Serial.println("ATO"); // send a command to ensure back in data mode
Serial.flush();
[/quote]
That's weird because I can send all [b]+[/b]s in one go with [b]Serial.print( "+++" )[/b] with flush and delay rather than [b]Serial.print( "+" )[/b] with flush and delay three times to get into command mode.
I however get [b][ERROR][/b] when I send [b]Serial.print( "ATO" )[/b], the documentation even suggests [b]"The ATO command (terminated by the ASCII character “O”, not the number 0) is used to return to data mode."[/b]
What version of firmware are you running? You can use [b]ATI1[/b] and [b]ATI2[/b] to check the version.
soundf
got it sorted as below
Serial.print("+"); //put in command mode
delay(300);
Serial.print("+");
delay(300);
Serial.print("+");
delay( 5000 ); //hang round on command mode for a bit - no reason
Serial.println("ATO"); // send a command to ensure back in data mode
Serial.flush();
[/quote]
That's weird because I can send all [b]+[/b]s in one go with [b]Serial.print( "+++" )[/b] with flush and delay rather than [b]Serial.print( "+" )[/b] with flush and delay three times to get into command mode.
I however get [b][ERROR][/b] when I send [b]Serial.print( "ATO" )[/b], the documentation even suggests [b]"The ATO command (terminated by the ASCII character “O”, not the number 0) is used to return to data mode."[/b]
What version of firmware are you running? You can use [b]ATI1[/b] and [b]ATI2[/b] to check the version.

2012-07-09 13:29:59 got it sorted as below
Serial.print("+"); //put in command mode
delay(300);
Serial.print("+");
delay(300);
Serial.print("+");
delay( 5000 ); //hang round on command mode for a bit - no reason
Serial.println("ATO"); // send a command to ensure back in data mode
Serial.flush();
y2kgrays
Serial.print("+"); //put in command mode
delay(300);
Serial.print("+");
delay(300);
Serial.print("+");
delay( 5000 ); //hang round on command mode for a bit - no reason
Serial.println("ATO"); // send a command to ensure back in data mode
Serial.flush();

2012-07-07 17:54:23 Bit more info
the wizfi script
SerialClearBuffer(@COM)
MakeString(#SParam11, "+++")
SerialSendString(@COM, #SParam11, [color=red][b]0[/b][/color])
UXMessageText(1, "Sent +++...")
Sleep(1000)
this works fine to take out of data mode --- but change the 0 for a 1 or 2 and it will not work
SerialClearBuffer(@COM)
MakeString(#SParam11, "AT")
UXMessageText(1, "Sent AT again...")
Sleep(1000)
SerialSendString(@COM, #SParam11,[color=red][b] 2[/b][/color])
the rest of the scrpts have a 2 in the same place
?? what does the 0 & 2 do?
y2kgrays
the wizfi script
SerialClearBuffer(@COM)
MakeString(#SParam11, "+++")
SerialSendString(@COM, #SParam11, [color=red][b]0[/b][/color])
UXMessageText(1, "Sent +++...")
Sleep(1000)
this works fine to take out of data mode --- but change the 0 for a 1 or 2 and it will not work
SerialClearBuffer(@COM)
MakeString(#SParam11, "AT")
UXMessageText(1, "Sent AT again...")
Sleep(1000)
SerialSendString(@COM, #SParam11,[color=red][b] 2[/b][/color])
the rest of the scrpts have a 2 in the same place
?? what does the 0 & 2 do?

2012-07-07 11:07:49 Decided to test all this on my unit and same issue - can get into data mode but unable to get back to command mode via any sketch ... intereseting to note it you try the WizSmartScript gui interface you can toggle between command and data easy and when the script is ooked at it uses "+++" and "at"...but maybe it is doing something else ... [b]Hector[/b] maybe the guy that created the WizSmartScript gui could elighten us
This would also enable me to solve my data to pachube issue if i could toggle between the modes..
y2kgrays
This would also enable me to solve my data to pachube issue if i could toggle between the modes..

2012-07-05 09:40:02 @y2kgrays: I think "0x1B" and "\x1B" are the same thing, I could be wrong.
@Ricky: thanks, I'd appreciate any help. I'll need to access more one server for data transfer so I really need to be able to switch to and from command and data mode easily and reliably.
soundf
@Ricky: thanks, I'd appreciate any help. I'll need to access more one server for data transfer so I really need to be able to switch to and from command and data mode easily and reliably.
