-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathc_BasicWebClient.ino
64 lines (46 loc) · 1.83 KB
/
c_BasicWebClient.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
This is a basic web client demo sending test data to emoncms
It sends a couple of example variables in a semi-json like format: {power:252.4,temperature:15.4}
Try creating an account on emoncms.org then get the write api key and enter in line 51 replacing
the text YOURAPIKEY.
This example features both DCHP and DNS Lookup.
DHCP is where we ask the router for an ip address.
DNS is where we ask a Domain name server for the ip address of the server we want to send data to:
the domain name emoncms.org is linked to the ip address 213.138.101.177
Using DNS Lookup we can save having to remember these hard to remember strings of numbers.
-----------------------------------------
Part of the openenergymonitor.org project
Licence: GNU GPL V3
*/
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
unsigned long timer;
char website[] PROGMEM = "emoncms.org";
void setup ()
{
Serial.begin(9600);
Serial.println("03 - Basic Web Client");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
// DHCP Setup
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
// DNS Setup
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if ((millis()-timer)>5000) {
timer = millis();
Serial.println("Request sent");
// Send some test data to the server:
ether.browseUrl(PSTR("/api/post.json?apikey=YOURAPIKEY&json="), "{power:252.4,temperature:15.4}", website, 0);
}
}