Changes made to other files:
apps-conf.h in WiShield library:
//Here we include the header file for the application(s) we use in our project.
//#define APP_WEBSERVER
//#define APP_WEBCLIENT
//#define APP_SOCKAPP
//#define APP_UDPAPP
#define APP_WISERVER
g2100.c in WiShield library:
void zg_write_wep_key(U8* cmd_buf)
{
zg_wep_key_req_t* cmd = (zg_wep_key_req_t*)cmd_buf;
cmd->slot = 3; // WEP key slot
cmd->keyLen = 5; // Key length: 5 bytes (64-bit WEP); 13 bytes (128-bit WEP) - changed 13 to 5 here
cmd->defID = 0; // Default key ID: Key 0, 1, 2, 3
cmd->ssidLen = ssid_len;
.
.
.
- Code: Select all
/*
* 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,105}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,254}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"MYSSID"}; // max 32 bytes
unsigned char security_type = 1; // 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 = {
/* replace key 0 with my 64 bit WEP key, also changed g2100.c WEP key length from 13 to 5 */
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[] = {173,203,98,29};
char hostName[] = "www.pachube.com\nX-PachubeApiKey: my_very_long_key\nConnection: close";
char url[] = "/api/my4digitfeednumber.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
*/
Thanks.
Jay