/*
* Web Server
*
* (Based on Ethernet's WebServer Example)
*
* A simple web server that shows the value of the analog input pins.
*/
#include <SPI.h>
#include <WiFly.h>
#include "Credentials.h"
WiFlyServer server(80);
void setup() {
WiFly.begin();
if (!WiFly.join(ssid, passphrase)) {
while (1) {
// Hang on failure.
}
}
Serial.begin(9600);
Serial.print("IP: ");
Serial.println(WiFly.ip());
server.begin();
}
void loop() {
WiFlyClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("Hello World!");
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(100);
client.stop();
}
}
This is my simple hello world code im tryng to use with my WiFly. Wifly is associating with netowork and everyhting looks fine but when i make a request to WiFly ip then the green led on it stops flashing but the page on browser wont load. Sometimes when i press refresh the red led beside the green one flashes. Very rare occasions i manage to get the response from WiFly and its showed on browser.
Any ideas what should i check/do?
Using Arduino UNO
No other shields
EDIT:
When using SpiUartTerminal scetch then afther pointing my broser to Wifly i get this feedback:
Seems like this was just a timing issue. So if anybody having similar problems then adding delay(200); before ```
WiFlyClient client = server.available();
Heres the full working code:
/*
Web Server
(Based on Ethernet’s WebServer Example)
A simple web server that shows the value of the analog input pins.
*/
#include <SPI.h> #include <WiFly.h>
#include “Credentials.h”
WiFlyServer server(80);
void setup() {
WiFly.begin();
if (!WiFly.join(ssid, passphrase)) {
while (1) {
// Hang on failure.
}
}
if (client) {
Serial.println(“We have a client!”);
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c);
// if we’ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == ‘\n’ && current_line_is_blank) {
Serial.println(“Request ended, send data back”);
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();
client.println("Hello World");
client.stop();
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(200);
client.stop();
Serial.println("Client stopped");
just want to say thanks mate… i was troubleshooting for whole day since 6am. pretty much wrote my own library to figure out where i was going wrong. and then saw this lol… thanks a lot
I’ve used the WiFly in a couple of commercial applications, and don’t recommend it for use as a web server. It’s really intended to be a client and send data to a server. It supports only one connection at time, so you have to code you web pages to prevent the browser from making more than a single request to it when it loads a page.
I haven’t used that module, but I believe it also supports only a single TCP connection. To support a web server the device needs to support 4 or 5 simultaneous TCP connections at a minimum - 10 or more is better. The big problem you’ll encounter when searching for WiFi modules is that most of the manufacturers don’t supply specs on their Stack in their datasheets. You often have to dig really deep into the documentation to find out if the module has the capabilities you need to support your application. The majority of the modules I’ve look at target the “smart sensor” market; where a device sends data to a web server. It’s much easier to support this than it is to support an embedded web server.
In my opinion the GS1011 is easier to use than the WiFly. It uses the “AT command” format, so every reponse it sends is terminated by an “OK” or “ERROR” message, whereas some of the WiFly responses have no definitive terminator. This make it easier to determine when you’ve received the complete response. You need to send it about a half-dozen commands to configure it.
Connections to the module are simple. Like most radio modules, just connect the TX and RX lines to your UART. If you want to use hardware handshaking, also connect the CTS and RTS lines.
It is combination of Wifi + Arduino. It will be perfect one for Arduino fans who require Wifi capability. I was tempted to use but there is not much support or proven project from users.
Is it supported server application as well? Sorry I have limited knowledge of wireless modules.
It’s hard to say. The MRF24WB0MA Wi-Fi radio they are using is a “dumb” radio. The TCP/IP Stack is run by the AVR processor on the board, but it’s hard to tell from the documentation what features it supports. The WiKi has example code for sending a web page, but then it also says “Please note there is no dedicated firmware for Wifi Bee yet now, but you may use the firmware of WiShield from AsyncLabs. Please make sure you can use it before you buy.”
I tried to register Gainspan and haven’t got approval yet.
Local agent contact me to sign non disclosure agreement to get registration done. Then I said I am hobbyist and required only 2 pieces. Even though I sign and send them, no approval is received till now. Maybe they don’t bother individual.
I can buy it from semiconductorstore.com but no point as I cannot get user manual, firmware update.