Pages: 1 ... 30 31 [32] 33   Go Down
Author Topic: Feeling interest for a WiFi shield  (Read 28605 times)
0 Members and 1 Guest are viewing this topic.
Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  // 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++));
     }
   }
« Last Edit: August 10, 2009, 03:05:41 pm by tkj » Logged

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

Van Alstyne, TX
Offline Offline
Full Member
***
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wouldn't that be:
Code:
   Serial.print(*data++);
???

No '='.

« Last Edit: August 10, 2009, 03:05:18 pm by Fe2o3Fish » Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

Van Alstyne, TX
Offline Offline
Full Member
***
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
data += 44;
and use the original Serial.print(*data++);
Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad
Code:
    while (i < len) {
       if (i < 44) {
         Serial.print(*(data++));
       } else {
         Serial.print(*(data++));
         message[i-44] = *(data);
       }
       i++;
     }
     Serial.println(message);
« Last Edit: August 10, 2009, 03:26:00 pm by tkj » Logged

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

Van Alstyne, TX
Offline Offline
Full Member
***
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: August 10, 2009, 03:34:19 pm by Fe2o3Fish » Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

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

Van Alstyne, TX
Offline Offline
Full Member
***
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've tried your &data[44] thing (I just started at byte 100 instead), but it doesn't work!
Code:
/*
 * 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);
}
Logged

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

Van Alstyne, TX
Offline Offline
Full Member
***
Karma: 1
Posts: 154
Haven't smoked an Arduino... yet.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

interested to know if anyone used this with xbee together...
« Last Edit: August 30, 2009, 10:39:02 pm by zenroy11 » Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  :-/
Logged

Pages: 1 ... 30 31 [32] 33   Go Up
Jump to: