Created
October 9, 2017 20:01
-
-
Save yakutozcan/6696ae1ec8d12aad30a2d6ba6a6baa9d 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
#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); | |
pinMode(LED_BUILTIN, OUTPUT); | |
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); | |
} | |
WiFiMulti.addAP("wifi_adi", "sifre"); | |
} | |
void loop() { | |
// wait for WiFi connection | |
if ((WiFiMulti.run() == WL_CONNECTED)) { | |
HTTPClient http; | |
USE_SERIAL.print("[HTTP] begin...\n"); | |
//Heroku link | |
http.begin("http://hacknbreak-iot.herokuapp.com/oku/"); //HTTP | |
USE_SERIAL.print("[HTTP] GET...\n"); | |
int httpCode = http.GET(); | |
if (httpCode > 0) { | |
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); | |
//Heroku dan okunan deger | |
int state = payload.toInt(); | |
USE_SERIAL.printf("LED STATE %d\n", state); | |
digitalWrite(LED_BUILTIN, state); | |
} | |
} else { | |
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); | |
} | |
http.end(); | |
} | |
//Heroku için 100ms biraz çok gelebilir :) | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment