2023-02-15 00:20:08 +03:00
# подготавливаем папку для локального сервера обновлений
# для этого компилируем проект и получаем бинарные файлы:
2023-02-16 14:35:07 +03:00
# firmware.bin, littlefs.bin, partitions.bin и ver.json
2023-02-15 00:20:08 +03:00
import shutil
import configparser
import os , json , sys , getopt
from pathlib import Path
2023-02-16 14:35:07 +03:00
def copyFileIfExist ( fileName , deviceName ) :
srcFilePath = " .pio/build/ " + deviceName + " / " + fileName
dstFilePath = " iotm/ " + deviceName + " /400/ " + fileName
if Path ( srcFilePath ) . is_file ( ) :
print ( " Ok...... \" " + srcFilePath + " \" на месте! " )
Path ( dstFilePath ) . parent . mkdir ( parents = True , exist_ok = True )
shutil . copy ( srcFilePath , dstFilePath )
return True
else :
print ( " Error...... \" " + srcFilePath + " \" Н Е существует! " )
return False
2023-02-15 00:20:08 +03:00
config = configparser . ConfigParser ( ) # создаём объекта парсера INI
config . read ( " platformio.ini " )
deviceName = config [ " platformio " ] [ " default_envs " ]
homeDir = os . path . expanduser ( ' ~ ' )
os . system ( homeDir + " \ .platformio \ penv \ Scripts \ pio run " )
2023-02-16 14:35:07 +03:00
os . system ( homeDir + " \ .platformio \ penv \ Scripts \ pio run -t buildfs --disable-auto-clean " )
2023-02-15 00:20:08 +03:00
2023-02-16 14:35:07 +03:00
if copyFileIfExist ( " firmware.bin " , deviceName ) and copyFileIfExist ( " littlefs.bin " , deviceName ) and copyFileIfExist ( " partitions.bin " , deviceName ) :
versionsJson = json . loads ( ' { " ' + deviceName + ' " : { " 0 " : " 400 " }} ' )
with open ( " iotm/ver.json " , " w " , encoding = ' utf-8 ' ) as write_file :
json . dump ( versionsJson , write_file , ensure_ascii = False , indent = 4 , sort_keys = False )
print ( f " \x1b [1;31;42m Сервер для обновления ' по воздуху ' для " + deviceName + " подготовлен. Н е забудьте установить расширение Live Server, запустить е г о и прописать в ESP IP вашего компьютера. Подробнее смотрите в WIKI: https://iotmanager.org/wiki. \x1b [0m " )