Compare commits
	
		
			2 Commits
		
	
	
		
			49a9b45ab9
			...
			bcb5208e4d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| bcb5208e4d | |||
| 14759902be | 
| 
						 | 
					@ -13,6 +13,9 @@ platform = espressif32
 | 
				
			||||||
board = esp32doit-devkit-v1
 | 
					board = esp32doit-devkit-v1
 | 
				
			||||||
framework = arduino
 | 
					framework = arduino
 | 
				
			||||||
monitor_speed = 115200
 | 
					monitor_speed = 115200
 | 
				
			||||||
lib_deps = tzapu/WiFiManager@^2.0.17
 | 
					upload_protocol = espota
 | 
				
			||||||
;upload_protocol = espota
 | 
					upload_port = 192.168.2.232
 | 
				
			||||||
;upload_port = 192.168.2.233
 | 
					lib_compat_mode = strict
 | 
				
			||||||
 | 
					lib_deps = 
 | 
				
			||||||
 | 
						tzapu/WiFiManager@^2.0.17
 | 
				
			||||||
 | 
						lostincompilation/PrettyOTA@^1.1.2
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										63
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								src/main.cpp
									
									
									
									
									
								
							| 
						 | 
					@ -2,9 +2,9 @@
 | 
				
			||||||
#include <WiFiManager.h>
 | 
					#include <WiFiManager.h>
 | 
				
			||||||
#include <WiFi.h>
 | 
					#include <WiFi.h>
 | 
				
			||||||
#include <HTTPClient.h>
 | 
					#include <HTTPClient.h>
 | 
				
			||||||
#include <ArduinoOTA.h>
 | 
					#include <PrettyOTA.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define FIRMWARE "2.0"
 | 
					#define BOARDFIRMWARE "2.2"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define BUTTONPIN 23
 | 
					#define BUTTONPIN 23
 | 
				
			||||||
#define DEBOUNCEMS 15
 | 
					#define DEBOUNCEMS 15
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,9 @@ String statusURL = "http://moon.basement.lan/l/boardstatus.php";
 | 
				
			||||||
unsigned short buttonState = HIGH, lastButtonState = HIGH;
 | 
					unsigned short buttonState = HIGH, lastButtonState = HIGH;
 | 
				
			||||||
unsigned long lastStatusTime = 0;
 | 
					unsigned long lastStatusTime = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AsyncWebServer server(80);
 | 
				
			||||||
 | 
					PrettyOTA OTAUpdates;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sendToggleMessage(bool state) {
 | 
					void sendToggleMessage(bool state) {
 | 
				
			||||||
  Serial.println("Action button triggered");
 | 
					  Serial.println("Action button triggered");
 | 
				
			||||||
  char webMsg[255] = "";
 | 
					  char webMsg[255] = "";
 | 
				
			||||||
| 
						 | 
					@ -34,12 +37,37 @@ unsigned long sendDeviceStatus() {
 | 
				
			||||||
  HTTPClient http;
 | 
					  HTTPClient http;
 | 
				
			||||||
  http.begin(client, statusURL.c_str());
 | 
					  http.begin(client, statusURL.c_str());
 | 
				
			||||||
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
 | 
					  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
 | 
				
			||||||
  String httpData = "mac=" + WiFi.macAddress() + "&board=" + BOARD + "&firmware=" + FIRMWARE + "&service=" + SERVICE;
 | 
					  String httpData = "mac=" + WiFi.macAddress() + "&board=" + BOARD + "&firmware=" + BOARDFIRMWARE + "&service=" + SERVICE;
 | 
				
			||||||
  int httpResponseCode = http.POST(httpData);
 | 
					  int httpResponseCode = http.POST(httpData);
 | 
				
			||||||
  http.end();
 | 
					  http.end();
 | 
				
			||||||
  return millis();
 | 
					  return millis();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Gets called when update starts
 | 
				
			||||||
 | 
					// updateMode can be FILESYSTEM or FIRMWARE
 | 
				
			||||||
 | 
					void OnOTAStart(NSPrettyOTA::UPDATE_MODE updateMode) {
 | 
				
			||||||
 | 
					  Serial.println("OTA update started");
 | 
				
			||||||
 | 
					  if(updateMode == NSPrettyOTA::UPDATE_MODE::FIRMWARE)
 | 
				
			||||||
 | 
					    Serial.println("Mode: Firmware");
 | 
				
			||||||
 | 
					  else if(updateMode == NSPrettyOTA::UPDATE_MODE::FILESYSTEM)
 | 
				
			||||||
 | 
					    Serial.println("Mode: Filesystem");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Gets called while update is running
 | 
				
			||||||
 | 
					// currentSize: Number of bytes already processed
 | 
				
			||||||
 | 
					// totalSize: Total size of new firmware in bytes
 | 
				
			||||||
 | 
					void OnOTAProgress(uint32_t currentSize, uint32_t totalSize) {
 | 
				
			||||||
 | 
					  Serial.printf("OTA Progress Current: %u bytes, Total: %u bytes\n", currentSize, totalSize);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Gets called when update finishes
 | 
				
			||||||
 | 
					void OnOTAEnd(bool successful) {
 | 
				
			||||||
 | 
					  if (successful)
 | 
				
			||||||
 | 
					    Serial.println("OTA update finished successfully");
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    Serial.println("OTA update failed");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void setup() {
 | 
					void setup() {
 | 
				
			||||||
  Serial.begin(115200);
 | 
					  Serial.begin(115200);
 | 
				
			||||||
  pinMode(BUTTONPIN, INPUT_PULLUP);
 | 
					  pinMode(BUTTONPIN, INPUT_PULLUP);
 | 
				
			||||||
| 
						 | 
					@ -47,26 +75,14 @@ void setup() {
 | 
				
			||||||
  WiFiManager wifiManager;
 | 
					  WiFiManager wifiManager;
 | 
				
			||||||
  wifiManager.autoConnect("LEDsActionButton");
 | 
					  wifiManager.autoConnect("LEDsActionButton");
 | 
				
			||||||
  lastStatusTime = sendDeviceStatus();
 | 
					  lastStatusTime = sendDeviceStatus();
 | 
				
			||||||
  ArduinoOTA.onStart([]() {
 | 
					  OTAUpdates.Begin(&server);
 | 
				
			||||||
    String type;
 | 
					  OTAUpdates.SetHardwareID(SERVICE);
 | 
				
			||||||
    if ( ArduinoOTA.getCommand() == U_FLASH )
 | 
					  OTAUpdates.OverwriteAppVersion(BOARDFIRMWARE);
 | 
				
			||||||
      type = "sketch";
 | 
					  PRETTY_OTA_SET_CURRENT_BUILD_TIME_AND_DATE();
 | 
				
			||||||
    else // U_SPIFFS
 | 
					  OTAUpdates.OnStart(OnOTAStart);
 | 
				
			||||||
      type = "filesystem";
 | 
					  OTAUpdates.OnProgress(OnOTAProgress);
 | 
				
			||||||
    Serial.println("Start OTA updating " + type);
 | 
					  OTAUpdates.OnEnd(OnOTAEnd);
 | 
				
			||||||
  });
 | 
					  server.begin();
 | 
				
			||||||
  ArduinoOTA.onEnd([]() {
 | 
					 | 
				
			||||||
      Serial.println("\nOTA Update Completed");
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  ArduinoOTA.onError([](ota_error_t error) {
 | 
					 | 
				
			||||||
      Serial.printf("OTA Update Error[%u]: ", error);
 | 
					 | 
				
			||||||
      if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
 | 
					 | 
				
			||||||
      else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
 | 
					 | 
				
			||||||
      else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
 | 
					 | 
				
			||||||
      else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
 | 
					 | 
				
			||||||
      else if (error == OTA_END_ERROR) Serial.println("End Failed");
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  ArduinoOTA.begin();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned long lastDebounceTime = 0;
 | 
					unsigned long lastDebounceTime = 0;
 | 
				
			||||||
| 
						 | 
					@ -95,5 +111,4 @@ void loop() {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  lastButtonState = buttonCheck;
 | 
					  lastButtonState = buttonCheck;
 | 
				
			||||||
  ArduinoOTA.handle();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user