info:wiznet_to_pachube_communications
Sending data to Pachube
Make an HTTP PUT call with the sensor value as the content (comma-separated if there’s more than one value) that looks like this:
PUT /api/76.csv HTTP/1.1 Host: www.pachube.com X-PachubeApiKey: ENTER_YOUR_PACHUBE_API_KEY_HERE Content-Length: 19 Connection: close 12,14,66,23.03,text
The content-length field is a count of every character in the content, which is the line at the very end. Content always comes after two newlines, at the end of an HTTP PUT request, as shown above. If sending only one sensor, the PUT statement would look like this:
PUT /api/76.csv HTTP/1.1 Host: www.pachube.com X-PachubeApiKey: ENTER_YOUR_PACHUBE_API_KEY_HERE Content-Length: 3 Connection: close 126
The Code
Using the Arduino Ethernet shield, this kind of a call is trivial. It’s just a series of print statements:
// include the Ethernet library #include <Ethernet.h> // assign a MAC address for the ethernet controller. // fill in your address here: byte mac[] = { 0x00, 0xAA, 0xAA, 0xAA, 0xAA, 0x01 }; // assign an IP address for the controller: byte ip[] = { 192,168,0,20 }; // Assign the address of the server you want to connect to: byte server[] = { 173,203,98,29 }; // pachube.com // initialize the library instance: Client client(server, 80); long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop
info/wiznet_to_pachube_communications.txt · Last modified: 2011/01/29 14:35 by tomgee