From 9ac2cad859b4c8d0d413b0a8d14a54e33edb697d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 23 Nov 2017 10:50:39 +0100 Subject: [PATCH] Testing core_version.h for PlatformIO --- code/.gitignore | 1 + code/core_version.py | 51 ++++++++++++++++++++++++++++++++ code/espurna/config/all.h | 6 +++- code/espurna/config/prototypes.h | 1 + code/espurna/espurna.ino | 4 +-- code/espurna/light_ir.ino | 1 - code/espurna/utils.ino | 18 +++++++++++ code/platformio.ini | 11 +++---- 8 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 code/core_version.py diff --git a/code/.gitignore b/code/.gitignore index ae0ce507..7f05aa6e 100644 --- a/code/.gitignore +++ b/code/.gitignore @@ -3,3 +3,4 @@ .pioenvs .piolibdeps .vscode/c_cpp_properties.json +core_version.h diff --git a/code/core_version.py b/code/core_version.py new file mode 100644 index 00000000..bffcb03a --- /dev/null +++ b/code/core_version.py @@ -0,0 +1,51 @@ +#!/bin/python + +import json +import commands +import subprocess +import os +import sys + +def core_version(env): + + # Get the core folder + fwdir = env["FRAMEWORK_ARDUINOESP8266_DIR"] + + # Get the core version + with open(fwdir + '/package.json') as data_file: + data = json.load(data_file) + core_version = data["version"].upper().replace(".", "_").replace("-", "_") + print "CORE VERSION: %s" % core_version + + # Get git version + pr = subprocess.Popen( + "git --git-dir .git rev-parse --short=8 HEAD 2>/dev/null || echo ffffffff", + cwd = fwdir, + shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE ) + (out, error) = pr.communicate() + git_version = str(out).replace('\n', "") + print "GIT VERSION: %s" % git_version + + #env["BUILD_FLAGS"][0] += str(" -DARDUINO_ESP8266_RELEASE=" + core_version) + #env["BUILD_FLAGS"][0] += str(" -DARDUINO_ESP8266_RELEASE_" + core_version) + #env["BUILD_FLAGS"][0] += str(" -DARDUINO_ESP8266_GIT_VER=" + git_version) + + with open('espurna/config/core_version.h', 'w') as the_file: + the_file.write('#define ARDUINO_ESP8266_RELEASE "%s"\n' % core_version) + the_file.write('#define ARDUINO_ESP8266_RELEASE_%s\n' % core_version) + the_file.write('#define ARDUINO_ESP8266_GIT_VER "%s"\n' % git_version) + + #env.Append( + # CFLAGS = [ + # str("-DARDUINO_ESP8266_RELEASE=" + core_version), + # str("-DARDUINO_ESP8266_RELEASE_" + core_version), + # str("-DARDUINO_ESP8266_GIT_VER=" + git_version) + # ] + #) + + #print " -DARDUINO_ESP8266_RELEASE=" + core_version + + # " -DARDUINO_ESP8266_RELEASE_" + core_version + + # " -DARDUINO_ESP8266_GIT_VER=" + git_version + +Import('env') +core_version(env) diff --git a/code/espurna/config/all.h b/code/espurna/config/all.h index abce7000..15ba43e2 100644 --- a/code/espurna/config/all.h +++ b/code/espurna/config/all.h @@ -5,9 +5,13 @@ #include "sensors.h" #include "prototypes.h" +#ifdef USE_CORE_VERSION_H +#include "core_version.h" +#endif + /* If you want to modify the stock configuration but you don't want to touch - the repo files you can either define USE_CUSTOM_H or remove the + the repo files you can either define USE_CUSTOM_H or remove the "#ifdef USE_CUSTOM_H" & "#endif" lines and add a "custom.h" file to this same folder. Check https://bitbucket.org/xoseperez/espurna/issues/104/general_customh diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index 185d1a9b..710063bb 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -4,6 +4,7 @@ #include #include #include +#include AsyncWebServer * webServer(); diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index bafea82e..0c024b5d 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -21,7 +21,6 @@ along with this program. If not, see . #include "config/all.h" #include -#include // W.T.H. is this include ALSO needed here ?!?!! // ----------------------------------------------------------------------------- // METHODS @@ -82,7 +81,8 @@ void welcome() { DEBUG_MSG_P(PSTR("[INIT] CPU chip ID: 0x%06X\n"), ESP.getChipId()); DEBUG_MSG_P(PSTR("[INIT] CPU frequency: %d MHz\n"), ESP.getCpuFreqMHz()); DEBUG_MSG_P(PSTR("[INIT] SDK version: %s\n"), ESP.getSdkVersion()); - DEBUG_MSG_P(PSTR("[INIT] Core version: %s\n"), ESP.getCoreVersion().c_str()); + DEBUG_MSG_P(PSTR("[INIT] Core version: %s\n"), getCoreVersion().c_str()); + DEBUG_MSG_P(PSTR("[INIT] Core revision: %s\n"), getCoreRevision().c_str()); DEBUG_MSG_P(PSTR("\n")); // ------------------------------------------------------------------------- diff --git a/code/espurna/light_ir.ino b/code/espurna/light_ir.ino index c2f48fe7..ad318d9a 100644 --- a/code/espurna/light_ir.ino +++ b/code/espurna/light_ir.ino @@ -21,7 +21,6 @@ Not currently Implemented : */ - #ifdef LIGHT_PROVIDER_EXPERIMENTAL_RGB_ONLY_HSV_IR #include diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index a094fb3b..205c54dd 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -15,6 +15,24 @@ String getIdentifier() { return String(buffer); } +String getCoreVersion() { + String version = ESP.getCoreVersion(); + #ifdef ARDUINO_ESP8266_RELEASE + if (version.equals("00000000")) { + version = String(ARDUINO_ESP8266_RELEASE); + } + #endif + return version; +} + +String getCoreRevision() { + #ifdef ARDUINO_ESP8266_GIT_VER + return String(ARDUINO_ESP8266_GIT_VER); + #else + return String(""); + #endif +} + String buildTime() { const char time_now[] = __TIME__; // hh:mm:ss diff --git a/code/platformio.ini b/code/platformio.ini index 8ccc15a6..a98248ad 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -4,18 +4,16 @@ src_dir = espurna data_dir = espurna/data [common] -platform = espressif8266 -#platform = espressif8266_stage +#platform = espressif8266 +platform = espressif8266_stage build_flags = -g -DMQTT_MAX_PACKET_SIZE=400 ${env.ESPURNA_FLAGS} debug_flags = -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM build_flags_512k = ${common.build_flags} -Wl,-Tesp8266.flash.512k0.ld build_flags_1m = ${common.build_flags} -Wl,-Tesp8266.flash.1m0.ld -#https://github.com/me-no-dev/ESPAsyncTCP#9b0cc37 // 2.3.0 compatible -#https://github.com/me-no-dev/ESPAsyncTCP#289a681 // 2.4.0-rc2 compatible lib_deps = https://github.com/xoseperez/Time ArduinoJson - https://github.com/me-no-dev/ESPAsyncTCP#9b0cc37 + https://github.com/me-no-dev/ESPAsyncTCP#a57560d https://github.com/me-no-dev/ESPAsyncWebServer#313f337 https://github.com/marvinroger/async-mqtt-client#v0.8.1 PubSubClient @@ -36,6 +34,8 @@ lib_deps = https://github.com/FastLED/FastLED#v3.1.6 https://github.com/markszabo/IRremoteESP8266#v2.2.0 lib_ignore = +#extra_scripts = post:core_version.py +extra_scripts = # ------------------------------------------------------------------------------ @@ -48,6 +48,7 @@ lib_ignore = ${common.lib_ignore} build_flags = ${common.build_flags} -DWEMOS_D1_MINI_RELAYSHIELD -DDEBUG_FAUXMO=Serial -DNOWSAUTH upload_speed = 460800 monitor_baud = 115200 +extra_scripts = ${common.extra_scripts} [env:wemos-d1mini-relayshield-ssl] platform = espressif8266_stage