Hi all, I’m very new at this and have been searching the forums for an example that would help me but I can’t seem to find one.
I’ve setup my arduino & wishield to hit a text file on my webserver. That part works fine and I can print my result to the serial monitor. What I need to do now is parse the result down to a specific value and place that in a variable that will ultimately light my LEDs. I’m not worried about putting the value into a variable yet, it’s the parsing part that I’m having issues with.
Most, if not all, examples I’ve seen in the forums talk about looking for a pointer when parsing, like a |, and then reading beyond that, however I don’t have that luxury. (I think.)
I’m modifying the SimpleClient example that takes the GET result and puts it into an array. I have no parsing code in here yet. My code:
/*
* A simple sketch that uses WiServer to get the hourly weather data from LAX and prints
* it via the Serial API
*/
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,200}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"wifinetwork"}; // max 32 bytes
unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"password"}; // 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 ----------------------------------------
// Function that prints data from the server
void printPublicData(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 Public Prod
uint8 ip[] = {8,8,8,8};
// Base64 encoded USERNAME:PASSWORD
char auth[] = "user:pass";
// A request that gets the latest production server from Remix. (Don't use http:// in the domain)
GETrequest getPublicProd(ip, 80, "url", "/deploy.txt");
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);
//Set the auth string to be sent
getPublicProd.setAuth(auth);
// Have the processData function called when data is returned by the server
getPublicProd.setReturnFunc(printPublicData);
}
// Time (in millis) when the data should be retrieved
long updateTime = 0;
void loop(){
// Check if it's time to get an update
if (millis() >= updateTime) {
getPublicProd.submit();
// Get another update one hour from now
updateTime += 1000 * 60 * 60;
}
// Run WiServer
WiServer.server_task();
delay(10);
}
This is the complete result I get. The value that I want to parse out is plain text, either ra, rb or rc. (Really just a,b or c.) And I can’t modify the text file on the server
Connected to foo.com
TX 118 bytes
RX 0 bytes from a foo.com
RX 164 bytes from foo.com
HTTP/1.0 200 OK
Connection: close
X-Mashery-Responder: mashery-web2.ATL
Date: Mon, 01 Nov 2010 02:48:51 GMT
Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/RX 164 bytes from foo.com
0.9.8e-fips-rhel5
Last-Modified: Thu, 14 Oct 2010 17:08:00 GMT
Etag: "4990b66-20-49296c08c1c00"
Content-Type: text/plain
Accept-Ranges: bytes
Content-Length: 3RX 37 bytes from foo.com
2
[glow]rb[/glow] Thu Oct 14 12:08:00 CDT 2010
Ended connection with foo.com
Can someone help with advice on how I’d parse that text out?
Much appreciated,
selch