Go Down

Topic: Feeling interest for a WiFi shield (Read 71289 times) previous topic - next topic


Aug 10, 2009, 09:58 pm Last Edit: Aug 10, 2009, 10:05 pm by tkj Reason: 1
I'm having a problem getting the returned data from a POSTrequest (WiServer) into a char* array.

This is the process data code, and I would like to have the Webpage, not the HTTP header, into a char* array.
The webpage is coming after 44 characters, so I need to have everything after character 44!

Code: [Select]
  // Function to handle data from the server
  void processData(char* data, int len) { // Table data recieved
    // Print the data returned by the server
    // Note that the data is not null-terminated, may be broken up into smaller packets, and
    // includes the HTTP header.
    char* message;
    while (len-- > 0) {


Aug 10, 2009, 10:04 pm Last Edit: Aug 10, 2009, 10:05 pm by Fe2o3Fish Reason: 1
Wouldn't that be:
Code: [Select]

No '='.


Sorry, forget that... That isn't my problem!
I get the data response (incl. the HTTP) if I use the Serial.print code - but I need to know how to get that into a char* array.


Code: [Select]

void processData(char* data, int len) {
    char* message;

    message = &data[44];
    len -= 44;
    while (len-- > 0) {

Although the message variable is not necessary here -- just
modify the data variable with :
Code: [Select]
data += 44;
and use the original Serial.print(*data++);


Aug 10, 2009, 10:22 pm Last Edit: Aug 10, 2009, 10:26 pm by tkj Reason: 1
But I need to have everything from character 44 to the end of data*
Not from character 0 to 44!

Something like this, but this doesn't work :(
Code: [Select]
    while (i < len) {
      if (i < 44) {
      } else {
        message[i-44] = *(data);


Aug 10, 2009, 10:29 pm Last Edit: Aug 10, 2009, 10:34 pm by Fe2o3Fish Reason: 1
Oppps.  Didn't see your code segment.

There's no need to copy the data before printing.
Besides, the message variable is simply a pointer and
have no memory for character data associated when
declared as char *message;

What's wrong with using simply:


&data[44] is a char * that points to the 45th character in data[], 44 char's
after the start of data.

No need for all that code.


Then what if I need to use the message array outside the processData routine? Will that be possible when you only make a pointer to the data array?
Wouldn't the data array be unavailable after the routine is finished?


In C, arguments are passed by value and thus your function has a copy
of the pointer, not a copy of the data.  Because of this, the pointer can be
modified at will.  So long as you only read what the pointer points to then
the original data is preserved and still available.


I've tried your &data[44] thing (I just started at byte 100 instead), but it doesn't work!
Code: [Select]
* A simple sketch that uses WiServer to serve a web page

#include <WiServer.h>

#include <LCD4Bit.h>
//create object to control an LCD.  
//number of lines in display=2
LCD4Bit lcd = LCD4Bit(2);

#define WIRELESS_MODE_INFRA      1
#define WIRELESS_MODE_ADHOC      2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,2,124};      // IP address of WiShield
unsigned char gateway_ip[] = {192,168,2,254};      // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};      // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"PRJWLAN"};            // max 32 bytes

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

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"MatheV_home"};      // 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;
// End of wireless configuration parameters ----------------------------------------

char* message;
boolean dataReady = false;

int currentHour = 1;

//POST request settings
  // IP Address for www.tkjweb.dk  
  uint8 ip[] = {188,40,48,208};
  // Create a POST request that sends an email
  POSTrequest getTable(ip, 80, "www.tkjweb.dk", "/skoleskema.php", tableInput);
  // This function generates the body of our POST request
  void tableInput() {
void processData(char* data, int len) {
    message = &data[100];
    dataReady = true;

void setup() {
 // Initialize WiServer and disable the Webpage Serving Feature
 // Enable Serial output and ask WiServer to generate log messages (optional)
 //POST request setup
 currentHour = 1;
 while (dataReady == false) {
   // Run WiServer
 Serial.print("Message: ");

void loop() {
 // Run WiServer


You're not helping very much to just say "it doesn't work!".  Would you
care to tell us HOW it didn't work?   I mean, all you've told me is that the
car isn't running.  You haven't told me if the tank has gas, the battery is
charged, oil in the engine, the engine starts, etc, etc.

Keep in mind that you copied the address of the 101th character without
verifying that the data was long enough for that pointer to point to
anything.  Do you know that the URL arrived to the WiShield in one piece?

Is the rest of the code like example code that came with the WiShield?


Aug 31, 2009, 05:38 am Last Edit: Aug 31, 2009, 05:39 am by zenroy11 Reason: 1
interested to know if anyone used this with xbee together...


Hi guys.
Take a look at my WiFi SMS Gateway project, where I use the WiShield and a GM862 connected to the Arduino Duemillanove, with an ATMEGA328.

Best Regards
Thomas Jespersen


good work, Thomas!

do you mind to highlight what's the purpose(application) for
this gateway? I thought use WIFI or GPRS (only one) should be enough?


The purpose is for example is you set this up so this is running all the time, then you can make scripts which just calls the URL adress and then it sends an SMS (from your own number - so if you have free SMS, you can send free SMS's via the internet).

I thought about making a PHP script which calls the URL, so maybe in an ordering-system, people can get a confirmation SMS when their package is shipped.


what did you have to do get the wishield up and running with your arduino? can you give us beginners a little step by step ? pliiiiiise  :-/

Go Up