build.py, ota.conf, platformio.ini

This commit is contained in:
Klaus K Wilting 2018-09-18 17:23:56 +02:00
parent 6052588af0
commit 2201e48800
5 changed files with 96 additions and 97 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@
.clang_complete
.gcc-flags.json
src/loraconf.h
src/ota.conf

77
build.py Normal file
View File

@ -0,0 +1,77 @@
# build.py
# pre-build script, setting up build environment
import requests
from os.path import basename
from platformio import util
Import("env")
# get keyfile from platformio.ini and parse it
project_config = util.load_project_config()
keyfile = str(env.get("PROJECTSRC_DIR")) + "/" + project_config.get("common", "keyfile")
print "Parsing OTA keys from " + keyfile
mykeys = {}
with open(keyfile) as myfile:
for line in myfile:
key, value = line.partition("=")[::2]
mykeys[key.strip()] = str(value).strip()
# get bintray credentials from keyfile
user = mykeys["BINTRAY_USER"]
repository = mykeys["BINTRAY_REPO"]
apitoken = mykeys["BINTRAY_API_TOKEN"]
# get bintray parameters from platformio.ini
version = project_config.get("common", "release_version")
package = str(env.get("PIOENV"))
# put bintray credentials to platformio environment
env.Replace(BINTRAY_USER=user)
env.Replace(BINTRAY_REPO=repository)
env.Replace(BINTRAY_API_TOKEN=apitoken)
# get runtime credentials from keyfile and put them to compiler directive
env.Replace(CPPDEFINES=[
('WIFI_SSID', '\\"' + mykeys["OTA_WIFI_SSID"] + '\\"'),
('WIFI_PASS', '\\"' + mykeys["OTA_WIFI_PASS"] + '\\"'),
('BINTRAY_USER', '\\"' + mykeys["BINTRAY_USER"] + '\\"'),
('BINTRAY_REPO', '\\"' + mykeys["BINTRAY_REPO"] + '\\"'),
])
# function for pushing new firmware to bintray storage using API
def publish_bintray(source, target, env):
firmware_path = str(source[0])
firmware_name = basename(firmware_path)
url = "/".join([
"https://api.bintray.com", "content",
user, repository, package, version, firmware_name
])
print("Uploading {0} to Bintray. Version: {1}".format(
firmware_name, version))
print(url)
headers = {
"Content-type": "application/octet-stream",
"X-Bintray-Publish": "1",
"X-Bintray-Override": "1"
}
r = requests.put(
url,
data=open(firmware_path, "rb"),
headers=headers,
auth=(user, apitoken))
if r.status_code != 201:
print("Failed to submit package: {0}\n{1}".format(
r.status_code, r.text))
else:
print("The firmware has been successfuly published at Bintray.com!")
# put build file name and upload command to platformio environment
env.Replace(
PROGNAME="firmware_" + package + "_v%s" % version,
UPLOADCMD=publish_bintray
)

View File

@ -24,34 +24,17 @@ env_default = generic
;
description = Paxcounter is a proof-of-concept ESP32 device for metering passenger flows in realtime. It counts how many mobile devices are around.
[bintray]
user = cyberman54
repository = paxcounter-firmware
api_token = 2e10f923df5d47b9c7e25752510322a1d65ee997
[ota]
;release_version = max. 9 chars total, using decimal format "a.b.c"
release_version = 1.4.32
wifi_ssid = testnet
wifi_password = test0815
build_flags =
'-DWIFI_SSID="${ota.wifi_ssid}"'
'-DWIFI_PASS="${ota.wifi_password}"'
'-DBINTRAY_USER="${bintray.user}"'
'-DBINTRAY_REPO="${bintray.repository}"'
'-DBINTRAY_PACKAGE="${PIOENV}"'
'-DPROGVERSION="${ota.release_version}"'
[common]
; DEBUG LEVEL
; For production run setto 0, otherwise device will leak RAM while running!
; for release_version use max.10 chars total, use any decimal format like "a.b.c"
release_version = 1.4.33
; 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
debug_level = 0
; UPLOAD MODE
; select esptool for USB/UART flashing, custom for OTA upload
; UPLOAD MODE: select esptool to flash via USB/UART, select custom to upload to cloud for OTA
upload_protocol = esptool
;upload_protocol = custom
extra_scripts = pre:publish_firmware.py
extra_scripts = pre:build.py
keyfile = ota.conf
platform_espressif32 = espressif32@1.3.0
board_build.partitions = min_spiffs.csv
monitor_speed = 115200
@ -69,9 +52,10 @@ build_flags =
-D_lmic_config_h_
-include "src/paxcounter.conf"
-include "src/hal/${PIOENV}.h"
${ota.build_flags}
-w
-DCORE_DEBUG_LEVEL=${common.debug_level}
'-DCORE_DEBUG_LEVEL=${common.debug_level}'
'-DBINTRAY_PACKAGE="${PIOENV}"'
'-DPROGVERSION="${common.release_version}"'
[env:ebox]
platform = ${common.platform_espressif32}

View File

@ -1,71 +0,0 @@
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import requests
from os.path import basename
from platformio import util
Import("env")
project_config = util.load_project_config()
bintray_config = {k: v for k, v in project_config.items("bintray")}
version = project_config.get("ota", "release_version")
package = env.get("PIOENV")
#
# Push new firmware to the Bintray storage using API
#
def publish_bintray(source, target, env):
firmware_path = str(source[0])
firmware_name = basename(firmware_path)
print("Uploading {0} to Bintray. Version: {1}".format(
firmware_name, version))
url = "/".join([
"https://api.bintray.com", "content",
bintray_config.get("user"),
bintray_config.get("repository"),
package, version, firmware_name
])
print(url)
headers = {
"Content-type": "application/octet-stream",
"X-Bintray-Publish": "1",
"X-Bintray-Override": "1"
}
r = requests.put(
url,
data=open(firmware_path, "rb"),
headers=headers,
auth=(bintray_config.get("user"), bintray_config['api_token']))
if r.status_code != 201:
print("Failed to submit package: {0}\n{1}".format(
r.status_code, r.text))
else:
print("The firmware has been successfuly published at Bintray.com!")
# Custom upload command and program name
env.Replace(
PROGNAME="firmware_" + package + "_v%s" % version,
UPLOADCMD=publish_bintray
)

8
src/ota.sample.conf Normal file
View File

@ -0,0 +1,8 @@
[ota]
OTA_WIFI_SSID = myhomewifi
OTA_WIFI_PASS = FooBar42!
[bintray]
BINTRAY_USER = mybintrayuser
BINTRAY_REPO = mybintrayrepo
BINTRAY_API_TOKEN = 2e10f923df5d47b9c5423432322a1d4324783997