Created
March 17, 2018 19:16
-
-
Save yakutozcan/3a752798168108d71daa74e1582e78b8 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> | |
#include <ESP8266httpUpdate.h> | |
#define USE_SERIAL Serial | |
// Kodunuzu her guncellediğinizde aşağıdaki sayıyı arttırmayı unutmayın!! | |
#define currentVersion 130 | |
const int ledPin = D1; | |
int ledState = LOW; | |
unsigned long previousMillisLed = 0; | |
unsigned long previousMillisUpdate = 0; | |
const long intervalLed = 1000; //Led blink hızı | |
const long intervalUpdate = 3000; //Güncelleme kontrol etme sıklığı | |
ESP8266WiFiMulti WiFiMulti; | |
void setup() { | |
USE_SERIAL.begin(115200); | |
for (uint8_t t = 4; t > 0; t--) { | |
delay(1000); | |
} | |
WiFiMulti.addAP("wifiadi", "wifisifresi"); | |
pinMode(ledPin, OUTPUT); | |
} | |
void loop() { | |
unsigned long currentMillis = millis(); | |
if (currentMillis - previousMillisLed >= intervalLed) { | |
previousMillisLed = currentMillis; | |
if (ledState == LOW) { | |
ledState = HIGH; | |
} else { | |
ledState = LOW; | |
} | |
digitalWrite(ledPin, ledState); | |
} | |
if (currentMillis - previousMillisUpdate >= intervalUpdate) { | |
previousMillisUpdate = currentMillis; | |
CheckForUpdate(currentVersion); | |
} | |
} | |
void CheckForUpdate(int) { | |
if ((WiFiMulti.run() == WL_CONNECTED)) { | |
HTTPClient http; | |
//Versiyon numarasının okunacağı adres | |
http.begin("http://192.168.1.120/version.txt"); | |
int httpCode = http.GET(); | |
if (httpCode == HTTP_CODE_OK) { | |
String payload = http.getString(); | |
int n = payload.toInt(); | |
if (n > currentVersion) { | |
//Derlemis olduğumuz arduino kodumuzun http sunucumuzda ki adresi | |
t_httpUpdate_return ret = ESPhttpUpdate.update("http://192.168.1.120/OTA_blogpost.ino.nodemcu.bin"); | |
switch (ret) { | |
case HTTP_UPDATE_FAILED: | |
USE_SERIAL.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment