I've been following this thread for a couple of week and decided to purchase my first Arduino with a WiShield to monitor my electricity use.
Anyway, I've been trying to use Greg's code (modified slightly) and I keep getting this error when compiling.
error: 'POSTrequest' does not name a type In function 'void feedData()':
In function 'void setup()':
In function 'void loop()':
Anyway, here is my code (with a few things X'd out). Any help would be great.
- Code: Select all
/*
* A simple sketch that uses WiServer to PUT (via POST) to Pachube
*/
#include <WiServer.h>
#include <math.h>
//Wireless configuration defines ----------------------------------------
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
//Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,0,200}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,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 = {"XXXX"}; // 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 = {"XXXX"}; // max 64 characters
// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 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 ----------------------------------------
//non WiShield defines
//#define DEBUG_PRINT
#define IR_PIN 2
#define LED_PIN 13
// IP Address for Pachube.com
uint8 ip[] = {173,203,98,29};
char hostName[] = "www.pachube.com\nX-PachubeApiKey:XXXXXXX\nConnection: close";
char url[] = "/api/feeds/XXX.csv?_method=put";
// A request that POSTS data to Pachube
POSTrequest postPachube(ip, 80, hostName, url, feedData);
// 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.
#ifdef DEBUG_PRINT
while (len-- > 0) {
Serial.print(*(data++));
}
#endif //DEBUG_PRINT
}
//body data function, provides data for the POST command in comma separated values (CSV)
//currently POSTs one value but more can be added by separating with comma (no spaces)
void feedData()
{
char buf[16];
sprintf(buf, "%d,%d", energy, power);
WiServer.print(buf);
}
void setup()
{
int lastRead = HIGH; // The last reading (off)
long lastUpdate = 0; // The last time we sent an update
long counter = 0; // The current counter
long energy = 0; // The energy used in the current period (Wh)
long power = 0; // Rate of power used in current period (W)
//setup the analog pins as input, probly redundant
pinMode(IR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
// 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)
#ifdef DEBUG_PRINT
Serial.begin(9600);
//WiServer.enableVerboseMode(true);
#endif //DEBUG_PRINT
// Have the processData function called when data is returned by the server
postPachube.setReturnFunc(printData);
}
void loop()
{
int r = digitalRead(2);
if (r != lastRead)
{
lastRead = r;
if (r == LOW) // A blink has been detected.
{
counter++;
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}
if (millis() > lastUpdate + 5000 || millis() < lastUpdate)
{
// Send data out the serial port.
lastUpdate = millis();
energy=counter;
power=counter*3600/5;
#ifdef DEBUG_PRINT
Serial.print("===== LastUpdate fired: energy ");
Serial.print(tenergy, DEC);
Serial.print("Wh, power ");
Serial.println(light, DEC);
Serial.print("W");
#endif //DEBUG_PRINT
postPachube.submit();
counter=0;
energy=0;
power=0;
}
// Run WiServer
WiServer.server_task();
delay(10);
}