Created
May 14, 2016 23:20
-
-
Save tnoborio/4fea62665ba93551cc49136cd13ad3d2 to your computer and use it in GitHub Desktop.
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
/** | |
* BasicHTTPClient.ino | |
* | |
* Created on: 24.05.2015 | |
* | |
*/ | |
#include <Arduino.h> | |
#include <ESP8266WiFi.h> | |
#include <ESP8266WiFiMulti.h> | |
#include <ESP8266HTTPClient.h> | |
#define USE_SERIAL Serial | |
ESP8266WiFiMulti WiFiMulti; | |
void setup() { | |
USE_SERIAL.begin(115200); | |
// USE_SERIAL.setDebugOutput(true); | |
USE_SERIAL.println(); | |
USE_SERIAL.println(); | |
USE_SERIAL.println(); | |
for(uint8_t t = 4; t > 0; t--) { | |
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t); | |
USE_SERIAL.flush(); | |
delay(1000); | |
} | |
pinMode(0, INPUT); | |
WiFiMulti.addAP("halake-a2", "halaketown-4F"); | |
accel_setup(); | |
} | |
void loop() { | |
// wait for WiFi connection | |
if((WiFiMulti.run() == WL_CONNECTED)) { | |
// if (digitalRead(0)) { | |
// return; | |
// } | |
HTTPClient http; | |
USE_SERIAL.print("[HTTP] begin...\n"); | |
String type; | |
type = "cube"; | |
//if (xxx > 0) { | |
// type = "box"; | |
//} | |
http.begin("http://xxxx:8080/shake/1/" + | |
type | |
); //HTTP | |
USE_SERIAL.print("[HTTP] GET...\n"); | |
// start connection and send HTTP header | |
int httpCode = http.GET(); | |
// httpCode will be negative on error | |
if(httpCode > 0) { | |
// HTTP header has been send and Server response header has been handled | |
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode); | |
// file found at server | |
if(httpCode == HTTP_CODE_OK) { | |
String payload = http.getString(); | |
USE_SERIAL.println(payload); | |
} | |
} else { | |
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); | |
} | |
http.end(); | |
delay(300); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment