http://www.pachube.com/feeds/2557
Also just got my outside WX feeds hooked up (outside temp, air pressure)
http://www.pachube.com/feeds/2555
Greg
/*
* A simple sketch that uses WiServer to PUT (via POST) to Pachube
*/
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2}; // 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 = {"ASYNCLABS"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // 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 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++));
}
}
//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 commas (no spaces)
//Your program will not want to use the hardcoded values below, rather it would read the
//sensor(s) and build the data string shown below.
void feedData()
{
//e.g. a single value
WiServer.print("21");
//e.g. two values
//WiServer.print("21,42");
}
// IP Address for Pachube.com
uint8 ip[] = {209,40,205,190};
char hostName[] = "www.pachube.com\nX-PachubeApiKey: YOUR_PACHUBE_API_KEY\nConnection: close";
char url[] = "/api/2556.csv?_method=put";
// A request that POSTS data to Pachube
POSTrequest postPachube(ip, 80, hostName, url, feedData);
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(9600);
WiServer.enableVerboseMode(true);
// Have the printData function called when data is returned by the server
postPachube.setReturnFunc(printData);
}
// 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) {
postPachube.submit();
// Get another update one minute from now
updateTime += 1000 * 60;
}
// Run WiServer
WiServer.server_task();
delay(10);
}
/*
* A simple sketch that uses WiServer to PUT (via POST) to Pachube
*/
#include <WiServer.h>
#include <MsTimer2.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,1,2}; // 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 = {"SSID"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // 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 TEMPERATURE_PIN 5
#define LIGHT_PIN 0
//global state data
boolean intTimer;
int temperature;
int light;
// IP Address for Pachube.com
uint8 ip[] = {209,40,205,190};
char hostName[] = "www.pachube.com\nX-PachubeApiKey: YOUR_PACHUBE_API_KEY\nConnection: close";
char url[] = "/api/YOUR_PACHUBE_FEED.csv?_method=put";
// A request that POSTS data to Pachube
POSTrequest postPachube(ip, 80, hostName, url, feedData);
//MsTimer2 one minute timer ISR
void timerISR() {
intTimer = true;
}
// 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)
//Your program will not want to use the hardcoded values below, rather it would read the
//sensor(s) and build the data string shown below.
void feedData()
{
char buf[16];
sprintf(buf, "%d,%d", temperature, light);
WiServer.print(buf);
}
void setup()
{
temperature = 0;
light = 0;
//setup the analog pins as input, probly redundant
pinMode(TEMPERATURE_PIN, INPUT);
pinMode(LIGHT_PIN, INPUT);
// 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);
//set up global state data
intTimer = false;
//setup the timerISR to be called every minute
MsTimer2::set(60000, timerISR); // 60000ms/1min period
MsTimer2::start();
}
void loop()
{
//--------------------------------------------------------------------------------------------
//handle the timer overflow
//--------------------------------------------------------------------------------------------
if(true == intTimer) {
//one minute has passed
intTimer = false;
temperature = convertTemp(analogRead(TEMPERATURE_PIN));
light = 1024 - analogRead(LIGHT_PIN);
#ifdef DEBUG_PRINT
Serial.print("===== intTimer fired: temperature ");
Serial.print(temperature, DEC);
Serial.print("F, light ");
Serial.println(light, DEC);
#endif //DEBUG_PRINT
postPachube.submit();
}
// Run WiServer
WiServer.server_task();
delay(10);
}
/*
http://www.arduino.cc/playground/ComponentLib/Thermistor2
(Ground) ---- (10k-Resistor) -------|------- (Thermistor) ---- (+5v)
|
Analog Pin 0
*/
int convertTemp(int value)
{
double temp;
temp = log(((10240000 / value) - 10000));
temp = 1 / (0.001129148 + (0.000234125 * temp) + (0.0000000876741 * temp * temp * temp));
temp = temp - 273.15; // Convert Kelvin to Celcius
temp = (temp * 9.0) / 5.0 + 32.0; // Convert Celcius to Fahrenheit
return (int)temp;
}
/*
http://www.libelium.com/squidbee/index.php?title=Adding_a_light_sensor
(Ground) ---- (Light Sensor) -------|------- (1k-Resistor) ---- (+5v)
|
Analog Pin 0
*/
Can I just use WiServer.print(x); ?
//this is just a storage buffer, somewhere where we can stick some bytes...
char buf[16];
//in this sprintf use the following "happens" - think of it as kind of a search and replace
//1 - the results end up in buf
//2 - the "%d,%d" gets turned into an array of characters; two numbers separated by a comma (and ends up in buf)
//3 - %d tells sprintf to replace me with the string equivalent of a decimal value
//4 - the first %d is replaced with the first "data variable", in this case "temperature", the second with "light"
sprintf(buf, "%d,%d", temperature, light);
//now use WiServer to send our string
WiServer.print(buf);
//so if you did the following (assuming buf is big enough to hold it all)
sprintf(buf, "My favorite numbers are %d and %d", 100, 200);
Serial.println(buf)
//you would get this printed
My favorite numbers are 100 and 200
/*
* A simple sketch that uses WiServer to PUT (via POST) to Pachube
*/
#include <WiServer.h>
#include <MsTimer2.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,1,20}; // 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 = {"lolathon"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // 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_ADHOC;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
//non WiShield defines
//#define DEBUG_PRINT
//#define TEMPERATURE_PIN 5
#define LIGHT_PIN 0
//global state data
boolean intTimer;
//int temperature;
int light;
// IP Address for Pachube.com
uint8 ip[] = {209,40,205,190};
char hostName[] = "www.pachube.com\nX-PachubeApiKey: a1ee945349e1ecd25d745ca8d03306e7396053be***********************\nConnection: close";
char url[] = "/api/5860.csv?_method=put";
// A request that POSTS data to Pachube
POSTrequest postPachube(ip, 80, hostName, url, feedData);
//MsTimer2 one minute timer ISR
void timerISR() {
intTimer = true;
}
// 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)
//Your program will not want to use the hardcoded values below, rather it would read the
//sensor(s) and build the data string shown below.
void feedData()
{
char buf[16];
sprintf(buf, "%d", light);
WiServer.print(buf);
}
void setup()
{
// temperature = 0;
light = 0;
//setup the analog pins as input, probly redundant
// pinMode(TEMPERATURE_PIN, INPUT);
pinMode(LIGHT_PIN, INPUT);
// 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);
//set up global state data
intTimer = false;
//setup the timerISR to be called every minute
MsTimer2::set(60000, timerISR); // 60000ms/1min period
MsTimer2::start();
}
void loop()
{
//--------------------------------------------------------------------------------------------
//handle the timer overflow
//--------------------------------------------------------------------------------------------
if(true == intTimer) {
//one minute has passed
intTimer = false;
// temperature = convertTemp(analogRead(TEMPERATURE_PIN));
light = 1024 - analogRead(LIGHT_PIN);
#ifdef DEBUG_PRINT
// Serial.print("===== intTimer fired: temperature ");
// Serial.print(temperature, DEC);
Serial.print("F, light ");
//Serial.println(light, DEC);
#endif //DEBUG_PRINT
postPachube.submit();
}
// Run WiServer
WiServer.server_task();
delay(10);
}
/*
http://www.arduino.cc/playground/ComponentLib/Thermistor2
(Ground) ---- (10k-Resistor) -------|------- (Thermistor) ---- (+5v)
|
Analog Pin 0
*/
//int convertTemp(int value)
//{
// double temp;
// temp = log(((10240000 / value) - 10000));
// temp = 1 / (0.001129148 + (0.000234125 * temp) + (0.0000000876741 * temp * temp * temp));
// temp = temp - 273.15; // Convert Kelvin to Celcius
// temp = (temp * 9.0) / 5.0 + 32.0; // Convert Celcius to Fahrenheit
// return (int)temp;
//}
/*
http://www.libelium.com/squidbee/index.php?title=Adding_a_light_sensor
(Ground) ---- (Light Sensor) -------|------- (1k-Resistor) ---- (+5v)
|
Analog Pin 0
*/Ive tried commenting the debug stuff but still no dice.
Return to Sketches and Applications
Users browsing this forum: Yahoo [Bot] and 0 guests