Skip to content

Instantly share code, notes, and snippets.

@joelongstreet
Created July 29, 2014 17:18
Show Gist options
  • Save joelongstreet/707dd6fa7547e842830d to your computer and use it in GitHub Desktop.
Save joelongstreet/707dd6fa7547e842830d to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x08, 0xA1 };
char server[ ]= "api.mongolab.com";
EthernetClient client;
void setup()
{
Serial.begin(9600);
if(Ethernet.begin(mac) == 0) { // start ethernet using mac & DHCP
Serial.println("Failed to configure Ethernet using DHCP");
while(true) // no point in carrying on, so stay in endless loop:
;
}
Serial.println("waiting");
delay(10000); // give the Ethernet shield a second to initialize
Serial.println("waited");
Serial.println("This IP address: ");
IPAddress myIPAddress = Ethernet.localIP();
Serial.println(myIPAddress);
if(client.connect(server, 80)>0) {
Serial.println("connected");
client.println("POST /api/1/databases/dqube/collections/temperature?apiKey=mFwuonc-P8_cFQQ0USlr377h61LGm6sq HTTP/1.1");
client.println("Connection: keep-alive");
client.println("Host: " + myIPAddress);
client.println("User-Agent: arduino-ethernet");
client.println("Content-Type: application/json");
client.println("Content-Length: 12");
client.println("{\"on\":false}");
client.println("Connection: close");
client.println();
Serial.println("all done");
String response;
for(int i = 0; i<1000;i++) {
char c = client.read();
response += c;
}
client.stop();
Serial.println(response);
} else {
Serial.println("connection failed");
}
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment