make OTA selectable
This commit is contained in:
		
							parent
							
								
									c713b0a0e0
								
							
						
					
					
						commit
						c7445f0a1e
					
				
							
								
								
									
										3
									
								
								build.py
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								build.py
									
									
									
									
									
								
							@ -90,5 +90,4 @@ def publish_bintray(source, target, env):
 | 
				
			|||||||
# put build file name and upload command to platformio environment
 | 
					# put build file name and upload command to platformio environment
 | 
				
			||||||
env.Replace(
 | 
					env.Replace(
 | 
				
			||||||
    PROGNAME="firmware_" + package + "_v%s" % version,
 | 
					    PROGNAME="firmware_" + package + "_v%s" % version,
 | 
				
			||||||
    UPLOADCMD=publish_bintray
 | 
					    UPLOADCMD=publish_bintray)
 | 
				
			||||||
)
 | 
					 | 
				
			||||||
@ -26,7 +26,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[common]
 | 
					[common]
 | 
				
			||||||
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
 | 
					; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
 | 
				
			||||||
release_version = 1.5.5
 | 
					release_version = 1.5.6
 | 
				
			||||||
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
 | 
					; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
 | 
				
			||||||
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
 | 
					; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
 | 
				
			||||||
debug_level = 0
 | 
					debug_level = 0
 | 
				
			||||||
 | 
				
			|||||||
@ -143,12 +143,15 @@ void setup() {
 | 
				
			|||||||
  batt_voltage = read_voltage();
 | 
					  batt_voltage = read_voltage();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef USE_OTA
 | 
				
			||||||
 | 
					  strcat_P(features, " OTA");
 | 
				
			||||||
  // reboot to firmware update mode if ota trigger switch is set
 | 
					  // reboot to firmware update mode if ota trigger switch is set
 | 
				
			||||||
  if (cfg.runmode == 1) {
 | 
					  if (cfg.runmode == 1) {
 | 
				
			||||||
    cfg.runmode = 0;
 | 
					    cfg.runmode = 0;
 | 
				
			||||||
    saveConfig();
 | 
					    saveConfig();
 | 
				
			||||||
    start_ota_update();
 | 
					    start_ota_update();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // initialize button
 | 
					  // initialize button
 | 
				
			||||||
#ifdef HAS_BUTTON
 | 
					#ifdef HAS_BUTTON
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								src/ota.cpp
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/ota.cpp
									
									
									
									
									
								
							@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					#ifdef USE_OTA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 Parts of this code:
 | 
					 Parts of this code:
 | 
				
			||||||
 Copyright (c) 2014-present PlatformIO <contact@platformio.org>
 | 
					 Copyright (c) 2014-present PlatformIO <contact@platformio.org>
 | 
				
			||||||
@ -17,7 +19,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "ota.h"
 | 
					#include "ota.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <string>
 | 
					 | 
				
			||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE);
 | 
					const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE);
 | 
				
			||||||
@ -250,10 +251,10 @@ void do_ota_update() {
 | 
				
			|||||||
    size_t written, current, size;
 | 
					    size_t written, current, size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (Update.begin(contentLength)) {
 | 
					    if (Update.begin(contentLength)) {
 | 
				
			||||||
 | 
					#ifdef HAS_DISPLAY
 | 
				
			||||||
      // register callback function for showing progress while streaming data
 | 
					      // register callback function for showing progress while streaming data
 | 
				
			||||||
      Update.onProgress(&show_progress);
 | 
					      Update.onProgress(&show_progress);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
      int i = FLASH_MAX_TRY;
 | 
					      int i = FLASH_MAX_TRY;
 | 
				
			||||||
      while ((i--) && (written != contentLength)) {
 | 
					      while ((i--) && (written != contentLength)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -311,7 +312,7 @@ void do_ota_update() {
 | 
				
			|||||||
  client.stop();
 | 
					  client.stop();
 | 
				
			||||||
} // do_ota_update
 | 
					} // do_ota_update
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void display(const uint8_t row, std::string status, std::string msg) {
 | 
					void display(const uint8_t row, const std::string status, const std::string msg) {
 | 
				
			||||||
#ifdef HAS_DISPLAY
 | 
					#ifdef HAS_DISPLAY
 | 
				
			||||||
  u8x8.setCursor(14, row);
 | 
					  u8x8.setCursor(14, row);
 | 
				
			||||||
  u8x8.print((status.substr(0, 2)).c_str());
 | 
					  u8x8.print((status.substr(0, 2)).c_str());
 | 
				
			||||||
@ -320,7 +321,6 @@ void display(const uint8_t row, std::string status, std::string msg) {
 | 
				
			|||||||
    u8x8.setCursor(0, 7);
 | 
					    u8x8.setCursor(0, 7);
 | 
				
			||||||
    u8x8.print(msg.substr(0, 16).c_str());
 | 
					    u8x8.print(msg.substr(0, 16).c_str());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// callback function to show download progress while streaming data
 | 
					// callback function to show download progress while streaming data
 | 
				
			||||||
@ -328,6 +328,7 @@ void show_progress(size_t current, size_t size) {
 | 
				
			|||||||
  char buf[17];
 | 
					  char buf[17];
 | 
				
			||||||
  snprintf(buf, 17, "%-9lu (%3lu%%)", current, current * 100 / size);
 | 
					  snprintf(buf, 17, "%-9lu (%3lu%%)", current, current * 100 / size);
 | 
				
			||||||
  display(4, "**", buf);
 | 
					  display(4, "**", buf);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// helper function to compare two versions. Returns 1 if v2 is
 | 
					// helper function to compare two versions. Returns 1 if v2 is
 | 
				
			||||||
@ -364,3 +365,4 @@ int version_compare(const String v1, const String v2) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  return 0;
 | 
					  return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#endif // USE_OTA
 | 
				
			||||||
@ -1,6 +1,8 @@
 | 
				
			|||||||
#ifndef OTA_H
 | 
					#ifndef OTA_H
 | 
				
			||||||
#define OTA_H
 | 
					#define OTA_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef USE_OTA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "globals.h"
 | 
					#include "globals.h"
 | 
				
			||||||
#include "update.h"
 | 
					#include "update.h"
 | 
				
			||||||
#include <WiFi.h>
 | 
					#include <WiFi.h>
 | 
				
			||||||
@ -12,6 +14,8 @@ void do_ota_update();
 | 
				
			|||||||
void start_ota_update();
 | 
					void start_ota_update();
 | 
				
			||||||
int version_compare(const String v1, const String v2);
 | 
					int version_compare(const String v1, const String v2);
 | 
				
			||||||
void show_progress(size_t current, size_t size);
 | 
					void show_progress(size_t current, size_t size);
 | 
				
			||||||
void display(const uint8_t row, std::string status, std::string msg);
 | 
					void display(const uint8_t row, const std::string status, const std::string msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif // USE_OTA
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // OTA_H
 | 
					#endif // OTA_H
 | 
				
			||||||
 | 
				
			|||||||
@ -66,6 +66,7 @@
 | 
				
			|||||||
#define HOMECYCLE                       30      // house keeping cycle in seconds [default = 30 secs]
 | 
					#define HOMECYCLE                       30      // house keeping cycle in seconds [default = 30 secs]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// OTA settings
 | 
					// OTA settings
 | 
				
			||||||
 | 
					#define USE_OTA                         1       // Comment out to disable OTA update
 | 
				
			||||||
#define WIFI_MAX_TRY                    20      // maximum number of wifi connect attempts for OTA update [default = 20]
 | 
					#define WIFI_MAX_TRY                    20      // maximum number of wifi connect attempts for OTA update [default = 20]
 | 
				
			||||||
#define FLASH_MAX_TRY                   3       // maximum number of attempts for writing update binary to flash [default = 3]
 | 
					#define FLASH_MAX_TRY                   3       // maximum number of attempts for writing update binary to flash [default = 3]
 | 
				
			||||||
#define OTA_MIN_BATT                    3700    // minimum battery level vor OTA [millivolt]
 | 
					#define OTA_MIN_BATT                    3700    // minimum battery level vor OTA [millivolt]
 | 
				
			||||||
 | 
				
			|||||||
@ -33,9 +33,14 @@ void set_reset(uint8_t val[]) {
 | 
				
			|||||||
    break;
 | 
					    break;
 | 
				
			||||||
  case 9: // reset and ask for software update via Wifi OTA
 | 
					  case 9: // reset and ask for software update via Wifi OTA
 | 
				
			||||||
    ESP_LOGI(TAG, "Remote command: software update via Wifi");
 | 
					    ESP_LOGI(TAG, "Remote command: software update via Wifi");
 | 
				
			||||||
 | 
					#ifdef USE_OTA
 | 
				
			||||||
    sprintf(display_line6, "Software update");
 | 
					    sprintf(display_line6, "Software update");
 | 
				
			||||||
    cfg.runmode = 1;
 | 
					    cfg.runmode = 1;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    sprintf(display_line6, "Software update not implemented");
 | 
				
			||||||
 | 
					#endif // USE_OTA
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  default:
 | 
					  default:
 | 
				
			||||||
    ESP_LOGW(TAG, "Remote command: reset called with invalid parameter(s)");
 | 
					    ESP_LOGW(TAG, "Remote command: reset called with invalid parameter(s)");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user