@surferTim - Thanks for the suggestion, I've tried setting pin4 high and 10 low to disable the SD SPI - no luck ![]()
Ok Here's the code on the UnoR3 + wifly shield.
This has so far worked for a max of 2 hours and then failed to receive any response from the server.
Also, interestingly this is all I get in the console:
connecting...
connected
HTTP/1.1 200 OK
Date: Mon, 12 Mar 2012 20:02:48 GMT
Content-Ty
disconnecting.
disconnected.
#include "WiFly.h"
#include "Credentials.h"
//byte server[] = { 173,203,98,29 };
WiFlyClient client("api.pachube.com", 80);
void setup() {
//pinMode(8,OUTPUT);
//digitalWrite(8,HIGH);
// lots of time for the WiFly to start up and also in case I need to stop the transmit
delay(10000);
Serial.begin(9600);
Serial.println("Wifly begin");
WiFly.begin();
Serial.println("Wifly join");
//if (!WiFly.join(ssid, passphrase, WEP_MODE)) {
if (!WiFly.join(ssid, passphrase)) {
Serial.println("Association failed.");
while (1) {
// Hang on failure.
}
}
}
uint32_t timeLastUpdated;
int i;
char buff[64];
void loop() {
if (millis() - timeLastUpdated > TIMETOUPDATE)
{ // time for the next update
timeLastUpdated = millis();
int thisData = random(100);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.print("PUT /v2/feeds/"); // APIV2
client.print(PACHUBEFEED);
client.print(".csv HTTP/1.1\r\n");
client.print("Host: api.pachube.com\r\n");
client.print("X-PachubeApiKey:");
client.println(APIKEY);
client.print("Content-Type: text/csv\nContent-Length: ");
int thisLength = getLength(thisData)+4;
client.println(thisLength, DEC);
client.println("Connection: close\n");
client.print(1,DEC);
client.print(",");
client.println(thisData,DEC);
} else {
Serial.println("connection failed");
}
delay(2000);
while (client.available()) {
Serial.write(client.read());
}
Serial.println();
if (client.connected()) {
Serial.println("disconnecting.");
client.stop();
Serial.println("disconnected.");
}
}
}
int getLength(int someValue) {
// there's at least one byte:
int digits = 1;
// continually divide the value by ten,
// adding one to the digit count for each
// time you divide, until you're at 0:
int dividend = someValue /10;
while (dividend > 0) {
dividend = dividend /10;
digits++;
}
// return the number of digits:
return digits;
}
I'll start with this one as it is my main concern. I know getting to the root of the problem is the best thing to do but I'd also like to explore the idea of an automated power reset with maybe a 555 and relay?
Thanks, Matt