You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.6 KiB
85 lines
2.6 KiB
SSID='925'
|
|
PASSWD='925925925'
|
|
def connectToWifiAndUpdate():
|
|
import time
|
|
# upd.save(b"update","False")
|
|
# aoff()
|
|
time.sleep_ms(200)
|
|
from network import WLAN ,AP_IF,STA_IF
|
|
sta_if=WLAN(STA_IF)
|
|
print(sta_if.ifconfig())
|
|
sta_if.active(True)
|
|
ap_if=WLAN(AP_IF)
|
|
ap_if.active(False)
|
|
if sta_if.ifconfig()[0]=='0.0.0.0':
|
|
print('connectToWifiAndUpdate')
|
|
try:
|
|
sta_if.connect(SSID,PASSWD)
|
|
except OSError:
|
|
pass
|
|
print('waiting for connection...')
|
|
while sta_if.ifconfig()[0]=='0.0.0.0':
|
|
print(sta_if.ifconfig())
|
|
time.sleep(3)
|
|
from ota_updater import OTAUpdater
|
|
if(sta_if.ifconfig()[0]!='0.0.0.0'):
|
|
print('network config:', sta_if.ifconfig())
|
|
token='git access token'
|
|
git='https://git.msb-co.ir/MSB_Electronics/esp32_ota_example'
|
|
md='app'
|
|
try:
|
|
print(md,'\n',git,'\n')
|
|
# otaUpdater = OTAUpdater(git, main_dir=md,headers={'Authorization': 'token {}'.format(token)})
|
|
otaUpdater = OTAUpdater(git, main_dir=md)
|
|
hasUpdated=None
|
|
try:
|
|
hasUpdated = otaUpdater.install_update_if_available()
|
|
except OSError as e:
|
|
import sys
|
|
from uio import StringIO
|
|
s=StringIO()
|
|
sys.print_exception(e, s)
|
|
s=s.getvalue()
|
|
print(s)
|
|
if hasUpdated:
|
|
import machine
|
|
machine.reset()
|
|
else:
|
|
del(otaUpdater)
|
|
except TypeError:
|
|
pass
|
|
print('DONE')
|
|
import gc
|
|
gc.collect()
|
|
connectToWifiAndUpdate()
|
|
|
|
# def connectToWifiAndUpdate():
|
|
# import time, machine, network, gc, app.secrets as secrets
|
|
# time.sleep(1)
|
|
# print('Memory free', gc.mem_free())
|
|
#
|
|
# from app.ota_updater import OTAUpdater
|
|
#
|
|
# sta_if = network.WLAN(network.STA_IF)
|
|
# if not sta_if.isconnected():
|
|
# print('connecting to network...')
|
|
# sta_if.active(True)
|
|
# sta_if.connect(secrets.WIFI_SSID, secrets.WIFI_PASSWORD)
|
|
# while not sta_if.isconnected():
|
|
# pass
|
|
# print('network config:', sta_if.ifconfig())
|
|
# otaUpdater = OTAUpdater('https://github.com/rdehuyss/micropython-ota-updater', main_dir='app', secrets_file="secrets.py")
|
|
# hasUpdated = otaUpdater.install_update_if_available()
|
|
# if hasUpdated:
|
|
# machine.reset()
|
|
# else:
|
|
# del(otaUpdater)
|
|
# gc.collect()
|
|
#
|
|
# def startApp():
|
|
# import app.start
|
|
#
|
|
#
|
|
# connectToWifiAndUpdate()
|
|
# startApp()
|