This commit is contained in:
unknown 2020-03-04 19:53:18 +01:00
commit e2f7d72cb3
3 changed files with 64 additions and 1 deletions

View File

@ -70,6 +70,10 @@ void loop() {
ESP.restart(); ESP.restart();
} }
if (buttonActive) { if (buttonActive) {
<<<<<<< HEAD
=======
realState = !state;
>>>>>>> 9d9bdc192f48b909e5406167be3e532d9b5d07e5
jsonContent = {}; jsonContent = {};
jsonContent["token"] = apiToken; jsonContent["token"] = apiToken;
requestJson = ""; requestJson = "";
@ -79,8 +83,9 @@ void loop() {
EEPROM.commit(); EEPROM.commit();
sendDataToWeb(); sendDataToWeb();
buttonActive = false; buttonActive = false;
} else {
loadDataFromWeb();
} }
loadDataFromWeb();
} else { } else {
server.handleClient(); server.handleClient();
} }
@ -108,6 +113,7 @@ bool wifiVerify(int t) {
} }
void loadDataFromWeb() { void loadDataFromWeb() {
delay(500);
jsonContent = {}; jsonContent = {};
jsonContent["token"] = apiToken; jsonContent["token"] = apiToken;
requestJson = ""; requestJson = "";
@ -137,6 +143,7 @@ void loadDataFromWeb() {
} }
WiFi.hostname(hostName); WiFi.hostname(hostName);
<<<<<<< HEAD
Serial.println("state: " + (String)state; Serial.println("state: " + (String)state;
if (!buttonActive) { if (!buttonActive) {
if (state == 1) { if (state == 1) {
@ -146,7 +153,16 @@ void loadDataFromWeb() {
} }
digitalWrite(RELAY, state); digitalWrite(RELAY, state);
EEPROM.write(0, state); EEPROM.write(0, state);
=======
Serial.println("state: " + (String)state + ", realState: " + (String)realState);
if (state != realState && !buttonActive) {
realState = state;
digitalWrite(RELAY, realState);
EEPROM.write(0, realState);
>>>>>>> 9d9bdc192f48b909e5406167be3e532d9b5d07e5
EEPROM.commit(); EEPROM.commit();
} else {
state = realState;
} }
} }

0
app/updater/.gitkeep Normal file
View File

47
update.php Normal file
View File

@ -0,0 +1,47 @@
<?PHP
header('Content-type: text/plain; charset=utf8', true);
function check_header($name, $value = false)
{
if (!isset($_SERVER[$name])) {
return false;
}
if ($value && $_SERVER[$name] != $value) {
return false;
}
return true;
}
function sendFile($path)
{
header($_SERVER["SERVER_PROTOCOL"] . ' 200 OK', true, 200);
header('Content-Type: application/octet-stream', true);
header('Content-Disposition: attachment; filename=' . basename($path));
header('Content-Length: ' . filesize($path), true);
header('x-MD5: ' . md5_file($path), true);
readfile($path);
}
if (!check_header('HTTP_USER_AGENT', 'ESP8266-http-Update')) {
header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden', true, 403);
echo "only for ESP8266 updater!\n";
exit();
}
if (
!check_header('HTTP_X_ESP8266_STA_MAC') ||
!check_header('HTTP_X_ESP8266_AP_MAC') ||
!check_header('HTTP_X_ESP8266_FREE_SPACE') ||
!check_header('HTTP_X_ESP8266_SKETCH_SIZE') ||
!check_header('HTTP_X_ESP8266_SKETCH_MD5') ||
!check_header('HTTP_X_ESP8266_CHIP_SIZE') ||
!check_header('HTTP_X_ESP8266_SDK_VERSION')
) {
header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden', true, 403);
echo "only for ESP8266 updater! (header)\n";
exit();
}
$localBinary = "./app/updater/" . $_SERVER['HTTP_X_ESP8266_STA_MAC'] . ".bin";
sendFile($localBinary);