From 02c870b0543a3a8c682fa0d250b4023df42ff53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sat, 31 Mar 2018 11:00:35 +0200 Subject: [PATCH 1/3] Working on extending OTA manager --- README.md | 6 +++--- code/ota.py | 32 +++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 80f2d960..68243056 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. [![version](https://img.shields.io/badge/version-1.12.5a-brightgreen.svg)](CHANGELOG.md) -![branch](https://img.shields.io/badge/branch-dev-orange.svg) -[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) -[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) +![branch](https://img.shields.io/badge/branch-ota-orange.svg) +[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=ota)](https://travis-ci.org/xoseperez/espurna) +[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/ota.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xose%2eperez%40gmail%2ecom&lc=US&no_note=0¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest) diff --git a/code/ota.py b/code/ota.py index 4726eb76..9d806831 100755 --- a/code/ota.py +++ b/code/ota.py @@ -106,6 +106,11 @@ def get_boards(): boards.append(m.group(1)) return sorted(boards) +def get_device_size(device): + if device.get('mem_size', 0) == device.get('sdk_size', 0): + return int(device.get('mem_size', 0) / 1024 + return 0 + def get_empty_board(): """ Returns the empty structure of a board to flash @@ -123,9 +128,26 @@ def get_board_by_index(index): board['hostname'] = device.get('hostname') board['board'] = device.get('device', '') board['ip'] = device.get('ip', '') - board['size'] = int(device.get('mem_size', 0) if device.get('mem_size', 0) == device.get('sdk_size', 0) else 0) / 1024 + board['size'] = get_device_size(device) return board +def get_board_by_mac(mac): + """ + Returns the required data to flash a given board + """ + hostname = hostname.lower() + for device in devices: + if device.get('mac', '').lower() == mac: + board = {} + board['hostname'] = device.get('hostname') + board['board'] = device.get('device') + board['ip'] = device.get('ip') + board['size'] = get_device_size(device) + if not board['board'] or not board['ip'] or board['size'] == 0: + return None + return board + return None + def get_board_by_hostname(hostname): """ Returns the required data to flash a given board @@ -136,13 +158,9 @@ def get_board_by_hostname(hostname): board = {} board['hostname'] = device.get('hostname') board['board'] = device.get('device') - if not board['board']: - return None board['ip'] = device.get('ip') - if not board['ip']: - return None - board['size'] = int(device.get('sdk_size', 0)) / 1024 - if board['size'] == 0: + board['size'] = get_device_size(device) + if not board['board'] or not board['ip'] or board['size'] == 0: return None return board return None From 738f7f6ab82350245cf28e763da500c880102cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 2 Apr 2018 10:53:34 +0200 Subject: [PATCH 2/3] Save ELF file to debug --- code/ota.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/code/ota.py b/code/ota.py index 9d806831..69059f85 100755 --- a/code/ota.py +++ b/code/ota.py @@ -8,6 +8,7 @@ # ------------------------------------------------------------------------------- from __future__ import print_function +import shutil import argparse import re import socket @@ -26,8 +27,7 @@ except NameError: # ------------------------------------------------------------------------------- devices = [] -description = "ESPurna OTA Manager v0.1" - +description = "ESPurna OTA Manager v0.2" # ------------------------------------------------------------------------------- @@ -214,13 +214,20 @@ def input_board(): return board +def boardname(board): + return board.get('hostname', board['ip']) + +def store(device, env): + source = ".pioenvs/%s/firmware.elf" % env + destination = ".pioenvs/elfs/%s.elf" % boardname(device).lower() + shutil.move(source, destination) def run(device, env): print("Building and flashing image over-the-air...") command = "export ESPURNA_IP=\"%s\"; export ESPURNA_BOARD=\"%s\"; export ESPURNA_AUTH=\"%s\"; export ESPURNA_FLAGS=\"%s\"; platformio run --silent --environment %s -t upload" command = command % (device['ip'], device['board'], device['auth'], device['flags'], env) subprocess.check_call(command, shell=True) - + store(device, env) # ------------------------------------------------------------------------------- @@ -298,7 +305,7 @@ if __name__ == '__main__': # Summary print() - print("HOST = %s" % board.get('hostname', board['ip'])) + print("HOST = %s" % boardname(board)) print("IP = %s" % board['ip']) print("BOARD = %s" % board['board']) print("AUTH = %s" % board['auth']) From f4bc81b733f33e995884708d500df62093952846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 20 Jun 2018 11:35:30 +0200 Subject: [PATCH 3/3] Fix typo --- code/ota.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ota.py b/code/ota.py index 90ff0755..16b86f82 100755 --- a/code/ota.py +++ b/code/ota.py @@ -114,7 +114,7 @@ def get_boards(): def get_device_size(device): if device.get('mem_size', 0) == device.get('sdk_size', 0): - return int(device.get('mem_size', 0) / 1024 + return int(device.get('mem_size', 0)) / 1024 return 0 def get_empty_board():