mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
more checks
This commit is contained in:
@@ -34,18 +34,25 @@ except ImportError:
|
|||||||
from termcolor import cprint
|
from termcolor import cprint
|
||||||
|
|
||||||
def print_success(x): return cprint(x, 'green')
|
def print_success(x): return cprint(x, 'green')
|
||||||
def print_fail(x): return cprint(x, 'red')
|
def print_fail(x): return cprint('Error: '+x, 'red')
|
||||||
|
|
||||||
def on_upload(source, target, env):
|
def on_upload(source, target, env):
|
||||||
|
|
||||||
|
# make sure we have set the upload_protocol to custom
|
||||||
|
if env.get('UPLOAD_PROTOCOL') != 'custom':
|
||||||
|
print_fail("Please set upload_protocol = custom in your pio_local.ini file when using upload.py")
|
||||||
|
return
|
||||||
|
|
||||||
# first check authentication
|
# first check authentication
|
||||||
try:
|
try:
|
||||||
username = env.GetProjectOption('custom_username')
|
username = env.GetProjectOption('custom_username')
|
||||||
password = env.GetProjectOption('custom_password')
|
password = env.GetProjectOption('custom_password')
|
||||||
|
emsesp_ip = env.GetProjectOption('custom_emsesp_ip')
|
||||||
except:
|
except:
|
||||||
print('No authentication settings specified. Please, add these to your pio_local.ini file: \n\ncustom_username=username\ncustom_password=password\n')
|
print_fail('Missing settings. Add these to your pio_local.ini file: \n\ncustom_username=username\ncustom_password=password\ncustom_emsesp_ip=ems-esp.local\n')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
emsesp_url = "http://" + env.GetProjectOption('custom_emsesp_ip')
|
emsesp_url = "http://" + env.GetProjectOption('custom_emsesp_ip')
|
||||||
parsed_url = urlparse(emsesp_url)
|
parsed_url = urlparse(emsesp_url)
|
||||||
host_ip = parsed_url.netloc
|
host_ip = parsed_url.netloc
|
||||||
@@ -71,10 +78,10 @@ def on_upload(source, target, env):
|
|||||||
response = requests.post(signon_url, json=username_password, headers=signon_headers)
|
response = requests.post(signon_url, json=username_password, headers=signon_headers)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print_fail("Authentication failed (code " + str(response.status_code) + ")")
|
print_fail("Authentication with EMS-ESP failed (code " + str(response.status_code) + ")")
|
||||||
return
|
return
|
||||||
|
|
||||||
print_success("Authentication successful")
|
print_success("Authentication with EMS-ESP successful")
|
||||||
access_token = response.json().get('access_token')
|
access_token = response.json().get('access_token')
|
||||||
|
|
||||||
# start the upload
|
# start the upload
|
||||||
|
|||||||
Reference in New Issue
Block a user