Feeling interest for a WiFi shield

How you take the button action on the ipod example? i mean, how the arduino know that you click the button?

Take a look at this code, to see how it is done with the Ethernet Shield (it's mostly the same) - http://elec.tkjweb.dk/blog/arduino-projects/ethernet-dmx-controller/

Thanks
Why you don't use an i2c eeprom to save the webpage[] Arduino Playground - I2CEEPROM24LC512 ? It's very easy to use that memory

Async, how easy is it just to open up an arbitrary port for binary access?

Anyone good at concatinating(sp?) long strings?
I want to add the variable te (temperature) to the webpage example, but can't seem to get it.

const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n

Hello World!
Temp is" & te &"

"};

Thanks.

I may be wrong, but I was under the impression that the arduino environment was unable to handle concatenations like this?

Below is how to convert a floating temp reading to a string

char temp_val[4];
float temp_c;
int temp_c1;
int temp_c2;

temp_c1 = temp_c;
temp_c2 = (temp_c -(int)temp_c)*10;
n = sprintf(temp_val, "%2d.%1d", temp_c1, temp_c2);

If you read the webserver code, you will see the constant "webpage" is quoted by function "memcpy_P". if you do this:

const prog_char webpage[] PROGMEM = "Temp is 00.0"

memcpy_P(data, webpage, webpage_len);  
memcpy_P(data[9], temp_val, 4);  //new added line to insert(replace) temp

data[9] means starting replace from string position 9, and width is 4; notice the "webpage" define is for demo only (won't work).

Hope this helps.

n = sprintf(temp_val, "%2d.%1d", temp_c1, temp_c2);

produces a 5 character string ( 4 printable characters plus the terminating null), use:
char temp_val[5];

Good idea YPort. So in order to send a variable to the webpage I have to convert it to a string first?
But then you state the line below won't work.
memcpy_P(data[9], temp_val, 4); //new added line to insert(replace) temp

Anyone know how to get a variable to show up on the actual webpage of the webpage example?

Any chance of the wifi class subclassing Print? Then we could use the print() and println() methods and not have to worry so much about string processing. The standard Ethernet library does this.

Pauly, add the following lines in the right place inside the webserver
example; don't change anything else, see what you will get in your
browser when you access it

char temp[5] = "78.9";

//add this extra line after each memcpy_P function calls
memcpy_P(data[80], temp, 4);

Thanks BenQuark.

I got the previous compile errors to go away.

Now it looks like I need to declare my_mac based on the following compile error in the Arduino IDE:

In function 'void loop()':
error: 'my_mac' was not declared in this scope

Yeah, from Ben's snippet of code, he didn't show the part where he declared the my_mac variable, which is inline with the compile error you are seeing.

Everybody, I created a couple of stickies on the websites for my forums (http://asynclabs.com/forums) if you have feature requests and improvements that we can integrated. I've tried to pre-populate it with some items that have already come up in this thread. I just want to make sure I don't miss anything.

We'll take a look at getting some print functionality in the stack we have, to make life easier for people. Also, another fellow is going to take a look at the Ethershield library and see if he can get it going with our driver. You'll need at least a ATMEGA328 to use this functionality though.

Anyway, we're working on more documentation, sample sketches, and improvements to the stack. We should have some stuff out by tomorrow, but it might not be till late. I forgot it's Mother's Day tomorrow, so I'm on the hook to take care of my 20-month old son all day (so that his Mom has a nice day off). :slight_smile:

Yport - If I leave your line memcpy_P(data[80], temp, 4);
alone I get a compile error - invalid conversion from 'char' to 'void*
If i take out the [80], I get the following the following webpage.

mp i/1.1 200 OK
Content-Type: text/html

temp is

I think the example of how to send data to another location is promising.
Really I should be able to make a a real webpage and have this just send the data over like temperature, wind speed etc.

Pauly, please try the following - search "YPort" for the changes
I made. This is a completed sketch.

/*
 * Web Server
 *
 * A simple web server example using the WiShield 1.0
 */

#include <WiShield.h>

#define WIRELESS_MODE_INFRA      1
#define WIRELESS_MODE_ADHOC      2

// Wireless configuration parameters ----------------------------------------
unsigned long local_ip = IP_ADDR(192,168,1,2);
const prog_char ssid[] PROGMEM = {"ASYNCLABS"};            // max 32 bytes

unsigned char security_type = 0;      // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};      // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {      0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,      // Key 0
                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      0x00,      // Key 1
                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      0x00,      // Key 2
                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      0x00      // Key 3
                                                };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------


// Webpages served by the webserver
//
// Due to the RAM limitation, the largest data packet that the application can
// transmit is limited to 446 bytes. Larger webpages can be broken down into
// smaller chunks and transmitted as shown in the code below to overcome this
// limitation

//YPort
const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><p><h1>WiShield Temprature  0000  F!</h1></p></center>"};

unsigned int webpage_len;


void setup()
{
      // Initialize the WiFi device
      // Resets the WiFi device and sets up the interrupt
      WiFi.init();
      
      Serial.begin(9600);
}

#define APP_IDLE            0
#define APP_MORE_DATA      1

void loop()
{
      char temp[5] = "78.9";  //Yport

      char* data;                        // variable pointing to the data received from the client
      unsigned int data_len;      //length of data received from the client 
      unsigned char app_state = APP_IDLE;
      
      webpage_len = strlen_P(webpage);      // length of the webpage
      
      WiFi.server_listen(80);            // start server on port 80 (HTTP)

      while(1) {
            WiFi.driver_task();            // run WiFi driver task
            WiFi.stack_task();            // run stack task
            
            data = (char*)WiFi.data_available(&data_len);
                  
            if (data_len) {
                  // process data
                  Serial.println(data);
           
                  if (memcmp(data, "GET / ", 6) == 0) {
                    // copy data into TX buffer

                    memcpy_P(data, webpage, webpage_len);
                memcpy(&data[80], temp, 4);  // YPort
                    WiFi.send_data(webpage_len);
           
                    // indicate this was the last chunk for TX
                    WiFi.set_more_data(1);
                  }
                  else {
                    WiFi.send_data(0);

                    WiFi.set_more_data(1);
                  }           
           
                  // we run the stack task again here to allow the stack
                  // to package the app data and set it up for TX when
                  // the driver task runs the next time
                  WiFi.stack_task();
                }

      }
}

Like John_Ryan mentioned earlier, the

tag inside a

isn't valid html. Actually it's "valid" but the header tag ends the paragraph leaving the

as an orphan. It probably wont affect the sketch or rendering other than taking up memory unnecessarily.

Hi,
don't know how much you are into web programming, but I suggest do the following - on the arduino try to create http data stream - valid json, xml or just txt data. To view your data load a page from another web server that upon loading requests the json data stream from the arduino.

Pros:

  • simpler syntax thus smaller program on the arduino
  • different ways to use and present the data - you can use simple perl/php scripts, flash, standalone program or whatever else to represent it.
    Cons:
  • more complex development you program the arduino to "export" the data, and then the pages to use it

Here is a simple json and xml packet describing tempearture:

{ time: 12:24:44,
date: 04.12.2009,
data: { temp: 18, humidity: 70 }
}

12:24:44 12:24:44 1870

For the development you can use simple html with jQuery (http://jquery.com), php with jQuery, or whatever does not kill you while trying to grasp it!

P.S:
I have pretty extensive experience creating web based information systems. The suggestions of PHP and jQuery are not random, but the ones I think will be most easy to start with.

P.P.S:
I always remind myself that the arduino is for physical world interaction not a computer by itself. Its strength is not in serving web pages.

Like John_Ryan mentioned earlier, the

tag inside a

isn't valid html. Actually it's "valid" but the header tag ends the paragraph leaving the

as an orphan. It probably wont affect the sketch or rendering other than taking up memory unnecessarily.

Correction.

is not valid (x)html1 transitional, that is, if your using w3.org to validate your markup.

I suspected Safari "might" have an issue if the body tag was missing or left open but I don't have a board yet to test it.

Correction.

is not valid (x)html1 transitional, that is, if your using w3.org to validate your markup.

I suspected Safari "might" have an issue if the body tag was missing or left open but I don't have a board yet to test it.

So we tried to just send a simple

Some paragraph

, and Safari still wasn't 100% happy. So we are thinking that the stack is still a bit unreliable.

Reinventing the wheel to cram a TCP/IP stack into this small MCU is always fun! ;D

We have the code for the stack up on GitHub, so hopefully those with lots of spare time and are subject matter experts can help out.

To clone the git repository:

git clone git://github.com/asynclabs/WiShield.git

Guides for how to get git working on your system, if you aren't familiar:
http://github.com/guides/home

This will help us to do better version control as well.

If it's only Safari? then I'd be inclined to suspect its the browser rather than the stack.

When my shield arrives I'll run a test using properly formed xhtml on Safari, like this:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>Test</p>
</body>
</html>

@Async... How easy to do think it'll be just to use the TCP portion of the IP stack. I'd rather implement my own binary protocol

FYI: Still waiting on the Shield in the UK, I imagine it'll be a few more days