This is a bit off-topic, but at the moment, I'm trying to figure out why I can't get the Simple Pachube Sketch - with one-wire temp sensor code to be stable.
My code is a combination of Pachube Simple (Arduino v1.0) and one-wire temp sensing, and uses the Ethercard, one-wire, and DallasTemp libraries (all latest versions I rekon).
The code (main loop is below) - but fairly straight forward - and the error is that the payload gets corrupted after a period of time - generally between a few hours and a few days (it varies).
Heres the serial output (and you'll see where it gets corrupted) :
Requesting temperatures...
Timer:6460447 Millis:6460547
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
temperature,19.87
REPLY:
HTTP/1.1 200 OK
Date: Sun, 15 Apr 2012 13:10:25 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
X-Pachube-Logging-Key: logging.0Vg8PrlBARnpBmL2oXVl
X-PachubeRequestId: 1d80f9d2d5bc88a2e2e74aef17347fce689febda
Cache-Control: max-age=0
Content-Length: 1
Age: 0
Vary: Accept-Encoding
Requesting temperatures...
Timer:6470562 Millis:6470662
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
temperature,19.94
REPLY:
HTTP/1.1 200 OK
Date: Sun, 15 Apr 2012 13:10:35 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
X-Pachube-Logging-Key: logging.0Vg8PrlBARnpBmL2oXVl
X-PachubeRequestId: e7c101a11a588c85ce3ca089e4919db67578218c
Cache-Control: max-age=0
Content-Length: 1
Age: 0
Vary: Accept-Encoding
Requesting temperatures...
Timer:6480677 Millis:6480777
Requesting temperatures...
Timer:6490792 Millis:6490892
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
-PachubeRequestId:
REPLY:
HTTP/1.1 400 Bad Request
Date: Sun, 15 Apr 2012 13:10:55 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
X-Pachube-Logging-Key: logging.0Vg8PrlBARnpBmL2oXVl
X-PachubeRequestId: 744459b23eb14f39511ad62ce5453d521915eea7
Cache-Control: no-cache
Content-Length: 61
Age: 0
CSV Parser Error: CSV is invalid. Incorrect number of fields.
Requesting temperatures...
Timer:6500907 Millis:6501006
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
L2oXVl
X-PachubeRe
REPLY:
HTTP/1.1 400 Bad Request
Date: Sun, 15 Apr 2012 13:11:05 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
X-Pachube-Logging-Key: logging.0Vg8PrlBARnpBmL2oXVl
X-PachubeRequestId: 5ffc2d4f8915ae91d5537449e2a8ca9e3502f969
Cache-Control: no-cache
Content-Length: 61
Age: 0
CSV Parser Error: CSV is invalid. Incorrect number of fields.
Requesting temperatures...
Timer:6511021 Millis:6511120
Requesting temperatures...
Timer:6521135 Millis:6521234
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
L2oXVl
X-PachubeRe
REPLY:
HTTP/1.1 400 Bad Request
Date: Sun, 15 Apr 2012 13:11:26 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
X-Pachube-Logging-Key: logging.0Vg8PrlBARnpBmL2oXVl
X-PachubeRequestId: a493b9c148de1c807bf24b421367f18da8db2193
Cache-Control: no-cache
Content-Length: 61
Age: 0
CSV Parser Error: CSV is invalid. Incorrect number of fields.
Requesting temperatures...
Timer:6531249 Millis:6531348
And heres the main loop code :
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
//Read temperature first
//Read temp now, so we get a delay for the query
Serial.println("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print("Timer:");
Serial.print(timer);
Serial.print(" Millis:");
Serial.println( millis());
delay(700);
// Payload is ID, data pairs....
// we can determine the size of the generated message ahead of time
byte sd = stash.create();
stash.print("temperature,");
stash.println(sensors.getTempC(insideThermometer));
//stash.print("1,");
//stash.println((word) micros() / 456);
stash.save();
// generate the header with payload - note that the stash size is used,
// and that a "stash descriptor" is passed in as argument using "$H"
Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n"
"Host: $F" "\r\n"
"X-PachubeApiKey: $F" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
timer= millis() + 9300;
}
}
Theres clearly something interrupting the main loop occasionally (see where the output shows multiple 'requesting temps' - and I suspect corruption is happening during the stash creation - but why that corrupts all future execution of the loop from then on, I dont know.
Am i running out of Stack ?
Interrupts not being handled ?
Any other ideas ?
Jon.
maybe this is my problem too with the latest Ethercard and one-wire pachube stuff.
It appears that the main loop is being called at random/strange times - including twice after the initial restart - but only sometimes...
Im wondering if the main loop is being interrupted mid/ and at the start of execution intermitently...
Glad to post my code to Github if it'll help..
J.
From: nanode...@googlegroups.com [mailto:nanode...@googlegroups.com] On Behalf Of SomeRandomBloke
Sent: 16 April 2012 21:21
To: nanode...@googlegroups.com
Subject: Re: Nanode / BT Homehub3 / Pachbe wont work but Virgin router does?
Looks like my tests with latest EtherCard and Pachube example using stash code is failing after an hour so looks like there is some problem. Time to debug....
I've been looking at tcp issues with nanode base and emoncms. They may not be the same as being discussed here, but worth being aware of. In summary, I've seen one issue, and one possible issue.
The definate issue is the inability of the library to handle an out of sequence packet.
The possible issue involves the reuse of source port numbers (only 32 are used), and
connections not being properly dropped by my router.
All,
As per the other thread around Virgin routers, the stash running out of space is whats corrupting my (simple Pachube with one-wire temp) sketch too.
I added this code to the end of the main loop
Serial.print("Stash:freeCount :");
Serial.println(Stash::freeCount());
You can see the stash free gets lower and lower (although its not linear - and does occasionally go up - the trend is down to zero), at which point you can see the packet text is corrupted...
I've just spotted the HTTP response isn't being received - I need to look into that too...
Jon.
Heres the Serial out from the code at the beginning...
Requesting temperatures...
Timer:0 Millis:7370
Stash:freeCount :54
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
temperature,20.50
Requesting temperatures...
Timer:17386 Millis:17485
Stash:freeCount :54
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
temperature,20.44
Requesting temperatures...
Timer:27500 Millis:27599
And when the stash is showing zero...
Requesting temperatures...
Timer:9110473 Millis:9110573
Stash:freeCount :9
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
temperature,20.31
Requesting temperatures...
Timer:9120588 Millis:9120688
Stash:freeCount :9
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
temperature,20.31
Requesting temperatures...
Timer:36054643 Millis:36054743
Stash:freeCount :0
Requesting temperatures...
Timer:36064757 Millis:36064857
Stash:freeCount :0
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
L2oXVl
X-PachubeRe
Requesting temperatures...
Timer:36074871 Millis:36074971
Stash:freeCount :0
REQUEST: 187
PUT http://api.pachube.com/v2/feeds/48208.csv HTTP/1.0
Host: api.pachube.com
X-PachubeApiKey: yjR4WMzFzWGWu4bf_tFifyuJh43hjk£J4ltcDlpaz0g
Content-Length: 19
L2oXVl
X-PachubeRe
The lack of http response seems to be something thats changed in the Ethercard library (last few days?)....going back to a a previous version...
Jon
thanks Some.
Let us know if/how we can help.
on a slightly different topic - how come the receive packets/data aren't being sent to the Serial output in the latest library release ? How can I check for server response for my HTTP calls ?
Jon
From: nanode...@googlegroups.com [mailto:nanode...@googlegroups.com] On Behalf Of SomeRandomBloke
Sent: 22 April 2012 09:05
To: nanode...@googlegroups.com
Subject: Re: Nanode / BT Homehub3 / Pachbe wont work but Virgin router does?
Am aware of the issues and limitations. biggest one lately is the stash not being cleared because the response packet is not being detected under some circumstances. Extensive debugging added to library including new packet analysis functions and these are helping to identify issues.
Thanks - I guess that's what I meant really...
The Ethercard library as of circa March this year was sending all packets received to the serial port. Specifically this statement in the Pachube example :
ether.packetLoop(ether.packetReceive());
This was really handy for debugging.
...With the newest library it doesn't do this.
I'll look into the tcpReply function as you say..
J.
From: nanode...@googlegroups.com [mailto:nanode...@googlegroups.com] On Behalf Of SomeRandomBloke
Sent: 22 April 2012 22:37
To: nanode...@googlegroups.com
Subject: Re: Nanode / BT Homehub3 / Pachbe wont work but Virgin router does?
the packets received dont go to the serial port. The contents get picked up by either the library for low level stuff such as ARP, DNS and DHCP, the rest get passed back up to the sketch to handle.
To check for replies, use tcpReply() function, although this doesnt always get called due to issues previously discussed.
SRB
On Sunday, 22 April 2012 10:23:42 UTC+1, Jon Bartlett wrote:
thanks Some.
Let us know if/how we can help.
on a slightly different topic - how come the receive packets/data aren't being sent to the Serial output in the latest library release ? How can I check for server response for my HTTP calls ?
Jon