Pachube and WiShield

Discussion about any of the included sketches (i.e. WebServer), or user-generated applications.

Re: Pachube and WiShield

Postby GregEigsti » Sat Jul 10, 2010 9:24 am

What interrupt pin is your WiShield using; the default of digital pin 2 or the less used digital pin 8? Your code is calling attachInterupt(0, ...) and the attachInterrupt docs show that when passing in a 0 as param 1 it will use digital pin 2. So if both are using pin 2 there are bound to be problems... What happens if you call attachInterupt(1, ...) which uses digital pin 3 (you don't seem to be using pin 3)?

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 955
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)

Re: Pachube and WiShield

Postby seacritter » Sat Jul 10, 2010 9:32 am

Wow... that was getting to me, I almost changed the interrupt several times... but just didn't get it...

Greg, you're really good...

That fixed it perfectly...
User avatar
seacritter
 
Posts: 45
Joined: Fri May 28, 2010 10:42 am
Location: Today? Near Philly...

Re: Pachube and WiShield

Postby seacritter » Sat Jul 10, 2010 9:37 am

Played around with it some more... I understand the interrupt scheme now...

Greg, Many thanks,
User avatar
seacritter
 
Posts: 45
Joined: Fri May 28, 2010 10:42 am
Location: Today? Near Philly...

Re: Pachube and WiShield

Postby GregEigsti » Sat Jul 10, 2010 9:43 am

Is it workin?
Gonna try to take a look at your site today.

Edit - Oh I see you posted twice before I finished my post. Glad its workin!

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 955
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)

Re: Pachube and WiShield

Postby seacritter » Sat Jul 10, 2010 9:50 am

It works perfectly with interrupt 1... But won't work at all with interrupt 0... Just looking at the wishield docs and it looks like the wishield is using interrupt 0. There is a pin to change from interrupt 0 to digital pin 8... I'm trying that now...
User avatar
seacritter
 
Posts: 45
Joined: Fri May 28, 2010 10:42 am
Location: Today? Near Philly...

Re: Pachube and WiShield

Postby GregEigsti » Sat Jul 10, 2010 9:53 am

I have never had to change the WiShield interrupt to pin 8 but think its more involved that just changing the jumper. I believe that you have to tweak the AsyncLabs code a bit to tell it to use pin 8. Instructions on the wiki or forum??? Dunno never done it myself.
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 955
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)

Re: Pachube and WiShield

Postby seacritter » Sat Jul 10, 2010 9:59 am

Tried that and it still has a problem... Must be something hardcoded with int 0... not sure. Still trying other things.
User avatar
seacritter
 
Posts: 45
Joined: Fri May 28, 2010 10:42 am
Location: Today? Near Philly...

Re: Pachube and WiShield

Postby seacritter » Sat Jul 10, 2010 10:05 am

Okay... just saw your previous post on this. I went into spi.h and changed it over...

Yep... that did it...

Good, I need both interrupts. Thanks again.
User avatar
seacritter
 
Posts: 45
Joined: Fri May 28, 2010 10:42 am
Location: Today? Near Philly...

Re: Pachube and WiShield

Postby GregEigsti » Sat Jul 10, 2010 10:38 am

Nice!
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 955
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)

Re: Pachube and WiShield

Postby bpmccain » Wed Jul 14, 2010 6:39 am

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);
}
bpmccain
 
Posts: 4
Joined: Tue Jul 13, 2010 2:31 pm

PreviousNext

Return to Sketches and Applications

Who is online

Users browsing this forum: DrStu, Yahoo [Bot] and 1 guest