diff --git a/build.py b/build.py index 7f2c3a28..f5ab56b8 100644 --- a/build.py +++ b/build.py @@ -13,33 +13,43 @@ Import("env") # get platformio environment variables project_config = util.load_project_config() -# check if file loraconf.h is present in source directory -keyfile = str(env.get("PROJECTSRC_DIR")) + "/loraconf.h" -if os.path.isfile(keyfile) and os.access(keyfile, os.R_OK): - print "Parsing LORAWAN keys from " + keyfile -else: - sys.exit("Missing file loraconf.h, please create it using template loraconf.sample.h! Aborting.") +# get platformio source path +srcdir = str(env.get("PROJECTSRC_DIR")).replace("\\", "/") + "/" -# check if file ota.conf is present in source directory -keyfile = str(env.get("PROJECTSRC_DIR")) + "/" + project_config.get("common", "keyfile") -if os.path.isfile(keyfile) and os.access(keyfile, os.R_OK): - print "Parsing OTA keys from " + keyfile +# check if lmic config file is present in source directory +lmicconfigfile = srcdir.lower() + project_config.get("common", "lmicconfigfile") +if os.path.isfile(lmicconfigfile) and os.access(lmicconfigfile, os.R_OK): + print "Parsing LMIC configuration from " + lmicconfigfile else: - sys.exit("Missing file ota.conf, please create it using template ota.sample.conf! Aborting.") + sys.exit("Missing file " + lmicconfigfile + ", please create it! Aborting.") -# parse file ota.conf +# check if lora key file is present in source directory +lorakeyfile = srcdir + project_config.get("common", "lorakeyfile") +if os.path.isfile(lorakeyfile) and os.access(lorakeyfile, os.R_OK): + print "Parsing LORAWAN keys from " + lorakeyfile +else: + sys.exit("Missing file " + lorakeyfile + ", please create it! Aborting.") + +# check if ota key file is present in source directory +otakeyfile = srcdir + project_config.get("common", "otakeyfile") +if os.path.isfile(otakeyfile) and os.access(otakeyfile, os.R_OK): + print "Parsing OTA keys from " + otakeyfile +else: + sys.exit("Missing file " + otakeyfile + ", please create it! Aborting.") + +# parse ota key file mykeys = {} -with open(keyfile) as myfile: +with open(otakeyfile) as myfile: for line in myfile: key, value = line.partition("=")[::2] mykeys[key.strip()] = str(value).strip() -# get bintray user credentials +# get bintray user credentials from ota key file user = mykeys["BINTRAY_USER"] repository = mykeys["BINTRAY_REPO"] apitoken = mykeys["BINTRAY_API_TOKEN"] -# get bintray upload parameters +# get bintray upload parameters from platformio environment version = project_config.get("common", "release_version") package = str(env.get("PIOENV")) @@ -54,6 +64,7 @@ env.Replace(CPPDEFINES=[ ('WIFI_PASS', '\\"' + mykeys["OTA_WIFI_PASS"] + '\\"'), ('BINTRAY_USER', '\\"' + mykeys["BINTRAY_USER"] + '\\"'), ('BINTRAY_REPO', '\\"' + mykeys["BINTRAY_REPO"] + '\\"'), + ('ARDUINO_LMIC_PROJECT_CONFIG_H', '\"' + lmicconfigfile + '\"') ]) # function for pushing new firmware to bintray storage using API diff --git a/platformio.ini b/platformio.ini index 8cde83eb..d3b9a9b1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -6,7 +6,7 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -env_default = generic +;env_default = generic ;env_default = ebox ;env_default = eboxtube ;env_default = ecopower @@ -16,7 +16,7 @@ env_default = generic ;env_default = ttgov2 ;env_default = ttgov21old ;env_default = ttgov21new -;env_default = ttgobeam +env_default = ttgobeam ;env_default = ttgofox ;env_default = lopy ;env_default = lopy4 @@ -40,7 +40,9 @@ debug_level = 3 upload_protocol = esptool ;upload_protocol = custom extra_scripts = pre:build.py -keyfile = ota.conf +otakeyfile = ota.conf +lorakeyfile = loraconf.h +lmicconfigfile = lmic_config.h platform_espressif32 = espressif32@1.8.0 ;platform_espressif32 = https://github.com/platformio/platform-espressif32.git#develop board_build.partitions = min_spiffs.csv @@ -74,13 +76,9 @@ build_flags_basic = -include "src/hal/${PIOENV}.h" -include "src/paxcounter.conf" -w - ;use this is you have platformio version >= 4.0.0a15 - '-DARDUINO_LMIC_PROJECT_CONFIG_H=../../../../../src/lmic_config.h' - ;use this is you have platformio version < 4.0.0a15 - ;'-DARDUINO_LMIC_PROJECT_CONFIG_H=../../../src/lmic_config.h' '-DCORE_DEBUG_LEVEL=${common.debug_level}' '-DLOG_LOCAL_LEVEL=${common.debug_level}' - '-DBINTRAY_PACKAGE="${PIOENV}"' + '-DBINTRAY_PACKAGE="$PIOENV"' '-DPROGVERSION="${common.release_version}"' build_flags_sensors = -Llib/Bosch-BSEC/src/esp32/