Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read params from src/config.h. Precedence given to platformio config. #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions platformio_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
#
# extra_scripts = platformio_upload.py
# upload_protocol = custom
# custom_upload_url = <your upload URL>
# custom_upload_url = <your upload URL> (optional)
# custom_username = <ElegantOTA username> (optional)
# custom_password = <ElgantOTA password> (optional)
#
# If custom_upload_url is not specified in platformio.ini, you must define a
# hostname in src/config.h using:
# #define HOSTNAME "<your hostname>"
# Username and password can similarly be specified using:
# #define OTA_USER "<ElegantOTA username>"
# #define OTA_PASS "<ElegantOTA password>"
#
# An example of an upload URL:
# custom_upload_url = http://192.168.1.123/update
Expand All @@ -33,7 +42,32 @@ def on_upload(source, target, env):
firmware_path = str(source[0])

auth = None
upload_url_compatibility = env.GetProjectOption('custom_upload_url')
upload_url_compatibility = None
username = None
password = None

# Attempt to get credentials and hostname from config header
try:
with open(env['PROJECT_SRC_DIR'] + '/config.h', 'r') as f:
for line in f.readlines():
if 'HOSTNAME' in line:
upload_url_compatibility = 'http://' + line.split('"')[1] + '/update'
if 'OTA_USER' in line:
username = line.split('"')[1]
if 'OTA_PASS' in line:
password = line.split('"')[1]
except:
pass

try:
upload_url_compatibility = env.GetProjectOption('custom_upload_url')
username = env.GetProjectOption('custom_username')
password = env.GetProjectOption('custom_password')
except:
pass

if upload_url_compatibility is None:
return "No upload URL or hostname specified."
upload_url = upload_url_compatibility.replace("/update", "")

with open(firmware_path, 'rb') as firmware:
Expand Down Expand Up @@ -61,14 +95,6 @@ def on_upload(source, target, env):
return 'Error checking auth: ' + repr(e)

if checkAuthResponse.status_code == 401:
try:
username = env.GetProjectOption('custom_username')
password = env.GetProjectOption('custom_password')
except:
username = None
password = None
print("No authentication values specified.")
print('Please, add some Options in your .ini file like: \n\ncustom_username=username\ncustom_password=password\n')
if username is None or password is None:
return "Authentication required, but no credentials provided."
print("Serverconfiguration: authentication needed.")
Expand Down
Loading