Skip to content

Instantly share code, notes, and snippets.

@dwblair
Last active December 18, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwblair/5725122 to your computer and use it in GitHub Desktop.
Save dwblair/5725122 to your computer and use it in GitHub Desktop.
Posting from OLM to http://open-log.pvos.org/ ...
// Simple demo for feeding some random data to Open-Log
// 2013-06-06 http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
// change these settings to match your own setup
#define FEED "3"
#define APIKEY "bananas"
static void my_result_cb (byte status, word off, word len) {
Serial.print("<<< reply ");
Serial.println(" ms");
Serial.println((const char*) Ethernet::buffer + off);
}
// from https://github.com/jcw/ethercard/blob/master/examples/pachube/pachube.ino
// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
char website[] PROGMEM = "open-log.pvos.org";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 10000;
/*
// generate two fake values as payload - by using a separate stash,
// we can determine the size of the generated message ahead of time
Serial.println("trying ...");
byte sd = stash.create();
stash.print("0,");
stash.println((word) millis() / 123);
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();
//char buffer [100];
//sprintf(buffer,"
*/
float temperature = 1.12;
char tmp[10];
char field1[] = "temp1";
//usage of dtostrf(floatVar, minStringWidthIncDecimalPoint, numVarsAfterDecimal, charBuf);
dtostrf(temperature,1,2, tmp);
char buffer [100];
sprintf(buffer,"feedID=%s&secretKey=%s&field1=%s&val1=%s",FEED, APIKEY, field1, tmp);
//http://open-log.pvos.org/senddata?feedID=3&secretKey=bananas&field1=temp1&val1=3.
//ether.browseUrl(PSTR("/senddata?"),"feedID=4&secretKey=bananas&field1=temp1&val1=3.03",website,my_result_cb);
ether.browseUrl(PSTR("/senddata?"),buffer,website,my_result_cb);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment