I am using Wiserver client sketch to read website page (the page is actually only a single digit) I need to use this digit as a variable in a sketch, however all the header data is getting in the way. Does anyone have a method of either not collecting the header data or parsing the returned data and extracting the required digit. In the response data shown below the digit is the 2 just before the ended connection response.
here is the response from the webserver; I have altered some of the URLs for security reasons
Connected to www.websitexx.com.au
TX 85 bytes
RX 0 bytes from www.websitexx.com.au
RX 230 bytes from www.websitexx.com.au
HTTP/1.1 200 OK
Date: Mon, 23 Apr 2012 15:33:12 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_fcgid/2.3.6 Phusion_Passenger/3.0.9 mod_bwlimited/1.4
Connection: close
Content-Type: text/html2Ended connection with www.websitexx.com.au
Here is the code;
/*
* A simple sketch that uses WiServer and prints
* it via the Serial API
*/
#include <WiServer.h>
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++ START WIFI CONFIG ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
/////////////////////////////////////////////////////Wireless configuration parameters ////////////////////////////////////////
unsigned char local_ip[] = {192,168,1,0}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,0}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"XXXXXX"}; // 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 = {"XXXXXXXXX"}; // max 64 characters
////////////////////////////////////////////////////// no need to edit below ////////////////////////////////////////
// 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 ----------------------------------------
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++ START VARIABLES CONFIG +++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// Function that prints data from the server
void printData(char* data, int len) {
// 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.
while (len-- > 0) {
Serial.print(*(data++));
}
}
// IP Address for www.xxxxx.com.au
uint8 ip[] = {000,000,000,000};
// A request that gets the latest data for site
GETrequest getSite(ip, 80, "www.xxxxxx.com", "/xxxxxxx/output.php");
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++ VOID SETUP BELOW ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void setup() {
// Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
WiServer.init(NULL);
// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(57600);
WiServer.enableVerboseMode(true);
// Have the processData function called when data is returned by the server
getSite.setReturnFunc(printData);
}
///////////////////////////////////////////////////// delay between setup an loop run ////////////////////////////////////////
// Time (in millis) when the data should be retrieved
long updateTime = 0;
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++ START LOOP BELOW +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//////////////////////////////// original read out loop /////////////////////////////
void loop(){
// Check if it's time to get an update
if (millis() >= updateTime) {
getSite.submit();
// Get another update one hour from now
updateTime += 1000 * 60 * 60;
}
// Run WiServer
WiServer.server_task();
delay(100);
}