From 29b3ae7041cc8621a295417a679f9b5b60c1c9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 8 Jan 2018 00:25:12 +0100 Subject: [PATCH] Support to build a core version of the firmware (<290Kb) keeping track of the board type for future reference --- code/espurna/config/arduino.h | 2 +- code/espurna/config/general.h | 15 +++++++++++++++ code/espurna/config/sensors.h | 6 ++++-- code/espurna/espurna.ino | 4 ++-- code/espurna/mdns.ino | 7 ++++++- code/espurna/utils.ino | 10 ++++++++++ code/extra_scripts.py | 8 +++++--- code/ota.py | 19 +++++++++++++++---- 8 files changed, 58 insertions(+), 13 deletions(-) diff --git a/code/espurna/config/arduino.h b/code/espurna/config/arduino.h index 1a05cbd5..f6f1eedc 100644 --- a/code/espurna/config/arduino.h +++ b/code/espurna/config/arduino.h @@ -71,7 +71,7 @@ //#define DOMOTICZ_SUPPORT 0 //#define HOMEASSISTANT_SUPPORT 0 //#define I2C_SUPPORT 1 -//#define INFLUXDB_SUPPORT 0 +//#define INFLUXDB_SUPPORT 1 //#define IR_SUPPORT 1 //#define LLMNR_SUPPORT 1 // Only with Arduino Core 2.4.0 //#define MDNS_SUPPORT 0 diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 74e9c0d6..1f6e627c 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -15,6 +15,21 @@ #define ARRAYINIT(type, name, ...) \ type name[] = {__VA_ARGS__}; +//------------------------------------------------------------------------------ +// ESPURNA CORE +//------------------------------------------------------------------------------ + +#ifdef ESPURNA_CORE + #define ALEXA_SUPPORT 0 + #define DOMOTICZ_SUPPORT 0 + #define HOMEASSISTANT_SUPPORT 0 + #define MQTT_SUPPORT 0 + #define NTP_SUPPORT 0 + #define WEB_SUPPORT 0 + #define SENSOR_SUPPORT 0 + #define I2C_SUPPORT 0 +#endif + //------------------------------------------------------------------------------ // TELNET //------------------------------------------------------------------------------ diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index 4dad0ab1..0f2f006a 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -438,15 +438,17 @@ // Sensor helpers configuration // ============================================================================= +#ifndef SENSOR_SUPPORT #if ANALOG_SUPPORT || BH1750_SUPPORT || BMX280_SUPPORT || DALLAS_SUPPORT \ || DHT_SUPPORT || DIGITAL_SUPPORT || ECH1560_SUPPORT \ || EMON_ADC121_SUPPORT || EMON_ADS1X15_SUPPORT \ || EMON_ANALOG_SUPPORT || EVENTS_SUPPORT || HLW8012_SUPPORT \ || MHZ19_SUPPORT || PMSX003_SUPPORT || SHT3X_I2C_SUPPORT \ || SI7021_SUPPORT || V9261F_SUPPORT - #define SENSOR_SUPPORT 1 - +#else +#define SENSOR_SUPPORT 0 +#endif #endif // ----------------------------------------------------------------------------- diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 9ad20828..33999ad5 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -128,8 +128,7 @@ void welcome() { // ------------------------------------------------------------------------- - DEBUG_MSG_P(PSTR("[INIT] MANUFACTURER: %s\n"), MANUFACTURER); - DEBUG_MSG_P(PSTR("[INIT] DEVICE: %s\n"), DEVICE); + DEBUG_MSG_P(PSTR("[INIT] BOARD: %s\n"), getBoardName().c_str()); DEBUG_MSG_P(PSTR("[INIT] SUPPORT:")); #if ALEXA_SUPPORT @@ -286,6 +285,7 @@ void setup() { if (getSetting("hostname").length() == 0) { setSetting("hostname", getIdentifier()); } + setBoardName(); // Cache loop delay value to speed things (recommended max 250ms) _loopDelay = atol(getSetting("loopDelay", LOOP_DELAY_TIME).c_str()); diff --git a/code/espurna/mdns.ino b/code/espurna/mdns.ino index 90fce569..018c2e38 100644 --- a/code/espurna/mdns.ino +++ b/code/espurna/mdns.ino @@ -45,7 +45,7 @@ void mdnsSetup() { // Public ESPurna related txt for OTA discovery MDNS.addServiceTxt("arduino", "tcp", "app_name", APP_NAME); MDNS.addServiceTxt("arduino", "tcp", "app_version", APP_VERSION); - MDNS.addServiceTxt("arduino", "tcp", "target_board", DEVICE_NAME); + MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName()); { char buffer[6]; itoa(ESP.getFlashChipRealSize() / 1024, buffer, 10); @@ -56,6 +56,11 @@ void mdnsSetup() { itoa(ESP.getFlashChipSize() / 1024, buffer, 10); MDNS.addServiceTxt("arduino", "tcp", "sdk_size", (const char *) buffer); } + { + char buffer[6]; + itoa(ESP.getFreeSketchSpace(), buffer, 10); + MDNS.addServiceTxt("arduino", "tcp", "free_space", (const char *) buffer); + } _mdns_wifi_onSTA = WiFi.onStationModeGotIP([](WiFiEventStationModeGotIP ipInfo) { _mdnsStart(); diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index c28f4a34..04fa9fc2 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -15,6 +15,16 @@ String getIdentifier() { return String(buffer); } +void setBoardName() { + #ifndef ESPURNA_CORE + setSetting("boardName", DEVICE_NAME); + #endif +} + +String getBoardName() { + return getSetting("boardName", DEVICE_NAME); +} + String getCoreVersion() { String version = ESP.getCoreVersion(); #ifdef ARDUINO_ESP8266_RELEASE diff --git a/code/extra_scripts.py b/code/extra_scripts.py index 2a0a42f1..c981db86 100644 --- a/code/extra_scripts.py +++ b/code/extra_scripts.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import time Import("env") # ------------------------------------------------------------------------------ @@ -31,11 +32,12 @@ def clr(color, text): # ------------------------------------------------------------------------------ def check_size(source, target, env): + time.sleep(1) size = target[0].get_size() print clr(Color.LIGHT_BLUE, "Binary size: %s bytes" % size) - if size > 512000: - print clr(Color.LIGHT_RED, "File too large for OTA!") - Exit(1) + #if size > 512000: + # print clr(Color.LIGHT_RED, "File too large for OTA!") + # Exit(1) # ------------------------------------------------------------------------------ # Hooks diff --git a/code/ota.py b/code/ota.py index 8e5a4bc6..e66cc7f5 100644 --- a/code/ota.py +++ b/code/ota.py @@ -38,15 +38,19 @@ def on_service_state_change(zeroconf, service_type, name, state_change): device['app'] = info.properties.get('app_name', '') device['version'] = info.properties.get('app_version', '') device['device'] = info.properties.get('target_board', '') - device['mem_size'] = info.properties.get('mem_size', '') - device['sdk_size'] = info.properties.get('sdk_size', '') + if 'mem_size' in info.properties: + device['mem_size'] = info.properties.get('mem_size') + if 'sdk_size' in info.properties: + device['sdk_size'] = info.properties.get('sdk_size') + if 'free_space' in info.properties: + device['free_space'] = info.properties.get('free_space') devices.append(device) def list(): ''' Shows the list of discovered devices ''' - output_format="{:>3} {:<25}{:<25}{:<15}{:<15}{:<30}{:<10}{:<10}" + output_format="{:>3} {:<25}{:<25}{:<15}{:<15}{:<30}{:<10}{:<10}{:<10}" print(output_format.format( "#", "HOSTNAME", @@ -56,8 +60,9 @@ def list(): "DEVICE", "MEM_SIZE", "SDK_SIZE", + "FREE_SPACE" )) - print "-" * 135 + print "-" * 146 index = 0 for device in devices: @@ -71,6 +76,7 @@ def list(): device.get('device', ''), device.get('mem_size', ''), device.get('sdk_size', ''), + device.get('free_space', ''), )) print @@ -161,6 +167,7 @@ if __name__ == '__main__': # Parse command line options parser = argparse.ArgumentParser(description=description) #parser.add_argument("-v", "--verbose", help="show verbose output", default=0, action='count') + parser.add_argument("-c", "--core", help="flash ESPurna core", default=0, action='count') parser.add_argument("-f", "--flash", help="flash device", default=0, action='count') parser.add_argument("-s", "--sort", help="sort devices list by field", default='hostname') args = parser.parse_args() @@ -194,6 +201,10 @@ if __name__ == '__main__': device = flash() if device: + # Flash core version? + if args.core > 0: + device['flags'] = "-DESPURNA_CORE " + device['flags'] + env = "esp8266-%sm-ota" % device['size'] # Summary