Hey, so I have this code that pulls data from a server, parses it, and stores two integers in variables. Based on what these integers are, the LED attached to pin 13 should be lighting, but it's not. I can't figure out why, but I'm new to all this. Can someone spot what's wrong with my code? I do know that my variables are what they should be, because I'm a uncomment all the serial command, the variables print actually what they should. This is on a asynclabs yellow jacket wifi board.
// A sketch that downloads heat index and weather condition from local server
// and displays it using RGB LEDS.
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {10,0,0,7}; // IP address of WiShield
unsigned char gateway_ip[] = {10,0,0,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 = {"XXXXXXXXX"}; // 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 = {"XXXXXXX"}; // 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 ----------------------------------------
//Variables
int ledPin = 13;
char Temp[4];
char Rain[2];
int t;
int r;
// IP Address for local server
uint8 ip[] = {10,0,0,9};
// A request that gets the latest data from server
GETrequest getWeather(ip, 80, "10,0,0,9", "/html/weatherData.txt");
void setup() {
pinMode(ledPin, OUTPUT);
// Initialize WiServer
WiServer.init(NULL);
// Serial.begin(57600);
WiServer.enableVerboseMode(false);
// Have the processData function called when data is returned by the server
getWeather.setReturnFunc(processData);
}
// --- Function that process data from a .submit request
void processData(char* data, int len) {
int myPointer=0, foundit=0;
if (len > 0) { // if len of packet greater than 0 then do following
memset(data, ' ', sizeof(data)); // initialize to empty
for (int ix=0; ix < len; ix++) { // count number of characters from the packet to read
char theChar=data[ix]; // read 1 character
if ((theChar=='|') || (foundit!=0)) { // found the pointer
if((foundit!=0) && (theChar!='\n') && (theChar!='\t')) { // If foundit already set to true, and char isn't junk, then add char to wiDateTime
data[myPointer] = theChar; // add qualified char to wiDateTime
myPointer++; // increment wiDateTime pointer
}
foundit=1; // terminator was found so foundit = true
}
} // if the pointer wasn't found in this packet, then it'll do the same to the subsequent packets, until the pointer is found
if (foundit!=0) {
// The terminator was found, now split the string into light_sensor, door_sensor, lounge_pir, hallway_pir
sscanf (data,"%[^','], %[^',']", Temp, Rain);
// the last variable is limited to the number of bytes expected, so that sscanf doesn't add extra bytes
r = atoi(Rain);
t = atoi(Temp);
// Serial.println(r);
// Serial.println(t);
}
}
}
// Time (in millis) when the data should be retrieved
long updateTime = 0;
void loop() {
if (t >= 85 && r == 0) {
digitalWrite(ledPin, HIGH); }
// Check if it's time to get an update
if (millis() >= updateTime) {
getWeather.submit();
// Set update time in milliseconds
updateTime += 1000 * 30;
}
// Run WiServer
WiServer.server_task();
delay(10);
}