Setup ota remote - Not working

This commit is contained in:
2023-11-28 11:39:31 +05:30
parent f88f38c8e8
commit 03acf4a31c
6 changed files with 39 additions and 11 deletions
Binary file not shown.
+4 -2
View File
@@ -1,4 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
void setupOTA(); void setupOTALocal();
void handleOTA(); void handleOTALocal();
void handleOTARemote();
+3 -3
View File
@@ -1,9 +1,9 @@
#ifndef BUILD_NUMBER #ifndef BUILD_NUMBER
#define BUILD_NUMBER 1 #define BUILD_NUMBER 2
#endif #endif
#ifndef VERSION #ifndef VERSION
#define VERSION "v0.1.1 - 2023-11-28 09:09:49.089072" #define VERSION "v0.1.2 - 2023-11-28 11:38:15.948331"
#endif #endif
#ifndef VERSION_SHORT #ifndef VERSION_SHORT
#define VERSION_SHORT "v0.1.1" #define VERSION_SHORT "v0.1.2"
#endif #endif
+10 -2
View File
@@ -74,6 +74,7 @@ const String KEY_C = "0x1FE807F";
const String KEY_D = "0x1FE20DF"; const String KEY_D = "0x1FE20DF";
const String KEY_ON = "0x1FE48B7"; const String KEY_ON = "0x1FE48B7";
const String KEY_OFF = "0x1FE48B7"; const String KEY_OFF = "0x1FE48B7";
const String KEY_MODE = "0x1FE58A7";
char lastPressedKey = '\0'; char lastPressedKey = '\0';
@@ -111,6 +112,11 @@ void handleKeyPress(char pressedKey) {
playBuzzer(BUZZER_PIN, TONE_BEEP_LONG); playBuzzer(BUZZER_PIN, TONE_BEEP_LONG);
ESP.restart(); ESP.restart();
} }
if (pressedKey == 'U') {
Serial.println("Pressed update. Updating via remote server..");
playBuzzer(BUZZER_PIN, TONE_BEEP_TWICE);
handleOTARemote();
}
// If pressed number // If pressed number
uint8_t currentNumberEntered = pressedKey - '0'; uint8_t currentNumberEntered = pressedKey - '0';
uint8_t lastNumberEntered = lastPressedKey - '0'; uint8_t lastNumberEntered = lastPressedKey - '0';
@@ -149,7 +155,7 @@ void setup() {
irrecv.setTolerance(kTolerancePercentage); // Override the default tolerance. irrecv.setTolerance(kTolerancePercentage); // Override the default tolerance.
irrecv.enableIRIn(); // Start the receiver irrecv.enableIRIn(); // Start the receiver
setupOTA(); setupOTALocal();
} }
void loop() { void loop() {
@@ -199,6 +205,8 @@ void loop() {
pressedKey = 'R'; pressedKey = 'R';
} else if (hexKey == KEY_OFF) { } else if (hexKey == KEY_OFF) {
pressedKey = 'R'; pressedKey = 'R';
} else if (hexKey == KEY_MODE) {
pressedKey = 'U';
} }
if (pressedKey != '\0') { if (pressedKey != '\0') {
handleKeyPress(pressedKey); handleKeyPress(pressedKey);
@@ -209,5 +217,5 @@ void loop() {
yield(); // Feed the WDT (again) yield(); // Feed the WDT (again)
} }
handleOTA(); handleOTALocal();
} }
+21 -3
View File
@@ -2,10 +2,12 @@
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <networkCredentials.h> #include <networkCredentials.h>
#include <version.h>
#include <ArduinoOTA.h>
#include <ESP8266httpUpdate.h>
void setupOTA() { void setupOTALocal() {
Serial.println("Booting"); Serial.println("Booting");
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
@@ -37,6 +39,22 @@ void setupOTA() {
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
} }
void handleOTA() { void handleOTALocal() {
ArduinoOTA.handle(); ArduinoOTA.handle();
} }
void handleOTARemote() {
WiFiClient client;
t_httpUpdate_return ret = ESPhttpUpdate.update(client, "https://github.com/bendtherules/Patient-counter-esp8266/raw/main/.pio/build/esp12e/firmware.bin", VERSION_SHORT);
switch(ret) {
case HTTP_UPDATE_FAILED:
Serial.println("[update] Update failed.");
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("[update] Update no Update.");
break;
case HTTP_UPDATE_OK:
Serial.println("[update] Update ok."); // may not be called since we reboot the ESP
break;
}
}
+1 -1
View File
@@ -1 +1 @@
1 2