Go Down

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

Thomas Jespersen

#465
Aug 10, 2009, 09:58 pm Last Edit: Aug 10, 2009, 10:05 pm by tkj Reason: 1
Hi.
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) {
        Serial.print(*(data++));
    }
  }
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Rusty in Texas

#466
Aug 10, 2009, 10:04 pm Last Edit: Aug 10, 2009, 10:05 pm by Fe2o3Fish Reason: 1
Wouldn't that be:
Code: [Select]
   Serial.print(*data++);???

No '='.


Thomas Jespersen

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.
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Rusty in Texas

Code: [Select]

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

    message = &data[44];
    len -= 44;
   
    while (len-- > 0) {
        Serial.print(*(message++));
    }
}

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++);

Thomas Jespersen

#469
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) {
        Serial.print(*(data++));
      } else {
        Serial.print(*(data++));
        message[i-44] = *(data);
      }
      i++;
    }
    Serial.println(message);
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Rusty in Texas

#470
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.
[editting]

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:

    Serial.print(&data[44]);

???
&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.

Thomas Jespersen

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?
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Rusty in Texas

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.

Thomas Jespersen

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() {
      WiServer.print("wt=false&hour=");
      WiServer.print(currentHour);
  }  
 
 
void processData(char* data, int len) {
    message = &data[100];
    dataReady = true;
}



void setup() {
 // Initialize WiServer and disable the Webpage Serving Feature
 WiServer.init(NULL);
 
 // Enable Serial output and ask WiServer to generate log messages (optional)
 Serial.begin(9600);
 WiServer.enableVerboseMode(true);
 
 //POST request setup
 getTable.setReturnFunc(processData);  
   
 currentHour = 1;
 getTable.submit();
 while (dataReady == false) {
   // Run WiServer
   WiServer.server_task();
 
   delay(10);
 }
 Serial.print("Message: ");
 Serial.println(message);
}

void loop() {
 // Run WiServer
 WiServer.server_task();
 
 delay(10);
}
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Rusty in Texas

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?

royz

#475
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...

Thomas Jespersen

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.
http://elec.tkjweb.dk/blog/arduino-projects/wifi-sms-gateway/

Best Regards
Thomas Jespersen
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

royz

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?

Thomas Jespersen

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.
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

brainlessboy

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