Created
June 12, 2015 10:28
-
-
Save addingama/c214d6110199901ce87e to your computer and use it in GitHub Desktop.
CUstom header untuk menyembunyikan api key pada header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Ethernet.h> | |
#include <PubSubClient.h> | |
// Update these with values suitable for your network. | |
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; | |
byte ip[] = { 192, 168, 137, 2 }; | |
byte dns2[] = {8, 8, 8, 8}; | |
byte gateway[] = { 192, 168, 137, 1 }; | |
String api_key = "API_KEY"; | |
unsigned long time; | |
EthernetClient ethClient; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Ethernet.begin(mac, ip, dns2, gateway); | |
Serial.print("My IP address: "); | |
Serial.println(Ethernet.localIP()); | |
} | |
void loop() | |
{ | |
// if there's a successful connection: | |
if (ethClient.connect("api.geeknesia.com", 80)) { | |
Serial.println("connecting..."); | |
// send the HTTP PUT request: | |
ethClient.println("GET /api/data?attributes={\"motion\":\"1\"} HTTP/1.1"); | |
ethClient.println("Host: api.geeknesia.com"); | |
ethClient.println("User-Agent: arduino-ethernet"); | |
ethClient.println("api_key: " + api_key); | |
ethClient.println("Connection: close"); | |
ethClient.println(); | |
} | |
else { | |
// if you couldn't make a connection: | |
Serial.println("connection failed"); | |
} | |
delay(30000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment