Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
13e1cfd
:fire: Remove hardcoded keepalive - fix #301 (#314)
bertmelis Mar 10, 2017
2564160
:racehorse: Improve uptime accuracy (#315)
bertmelis Mar 10, 2017
ad58871
:bug: Fix truncated IP (#318)
bertmelis Mar 10, 2017
11d7876
:art: Fix warning with parenthesis
marvinroger Mar 22, 2017
bf7188e
:bug: Fix pio library.json bad dependency name
marvinroger Mar 28, 2017
590ed4f
:sparkles: Add support for static IP and BSSID/MAC, channel of AP (#327)
benzino77 Apr 19, 2017
e3b0713
:racehorse: Pass all callbacks by reference
marvinroger Apr 19, 2017
9ef6a3a
:art: Rename globalInputHandler argument to be the same as in hpp
marvinroger Apr 19, 2017
23a7e37
:racehorse: Make isActive const
marvinroger Apr 19, 2017
a3fd195
:art: Add custom settings value to initial log
marvinroger Apr 19, 2017
ed9ea1b
:sparkles: Abort if default setting value does not pass validator fun…
marvinroger Apr 19, 2017
efff143
:memo: Clarify ISSUE_TEMPLATE docs location for #331
marvinroger May 4, 2017
c7db527
:memo: Implement new versioned Git docs (#341)
marvinroger May 30, 2017
f8e569d
:memo: Update all URLs to new docs
marvinroger May 30, 2017
6653dc7
:art: Fix broken doc link in README
marvinroger May 30, 2017
243dd9c
:memo: Add edit link to docs
marvinroger May 31, 2017
105ac05
:memo: Move firmware_parser.py to scripts folder
marvinroger Jun 1, 2017
b3020a1
:bug: Fix out of limits abort message not showing
marvinroger Jun 1, 2017
ce56c22
:shirt: Be less strict on whitespace in comments
marvinroger Jun 2, 2017
113c3e8
:memo: Add dummy OTA updater script (TODO)
marvinroger Jun 2, 2017
0bcf2bb
:art: :racehorse: Use CircleCi instead of Travis CI (#348)
marvinroger Jun 2, 2017
c091e4f
:art: Add SonoffDualShutters example
marvinroger Jun 2, 2017
4af701c
:bug: Install current lib to platformio
marvinroger Jun 2, 2017
34541aa
:bug: Actually ignore gh-pages in CI
marvinroger Jun 2, 2017
65c7944
:bug: Add missing SonoffDual dep
marvinroger Jun 2, 2017
d9a2760
:bug: Fix ArduinoJSON 5.11.0 (#363)
kylegordon Jul 1, 2017
83abe47
:arrow_up: Update pio dependencies
marvinroger Jun 1, 2017
38933b6
:art: Cleanup code a bit
marvinroger Jun 1, 2017
182f15d
:bug: Make sure every announcements packet are sent - closes #345
marvinroger Jun 6, 2017
98ffc1f
:art: Refactor code and implement new OTA system
marvinroger Jun 7, 2017
a897bdd
:shirt: Fix lint
marvinroger Jul 23, 2017
221f209
:white_check_mark: Use new workflow feature from Circle
marvinroger Jul 23, 2017
a51848e
:white_check_mark: Ignore gh-pages at workflow level
marvinroger Jul 23, 2017
bff53d4
:sparkles: Add OTA_PROGRESS event
marvinroger Jul 23, 2017
bb8941a
:memo: Update docs for new OTA system
marvinroger Jul 23, 2017
cd2fa9f
:arrow_up: Upgrade AsyncMqttClient dependency to 0.8.0
marvinroger Jul 23, 2017
bb7fbc9
:bug: IHomieSetting::settings first, HomieNode-settings second! (#335)
euphi Aug 2, 2017
c116da4
:bug: Fix not returning a value in setConfigurationApPassword (#378)
euphi Aug 3, 2017
57cb4d0
:bug: Fix crash when starting up without any defined node (#379)
jbliesener Aug 4, 2017
4ae67a6
:bug: Fix topic check for OTA upload (#375)
Aug 4, 2017
ec03fd5
:bug: Rename last OTA topic instance
marvinroger Aug 4, 2017
e11b456
:sparkles: Add OTA updater script (#384)
LiyouZhou Aug 20, 2017
5470b1b
:memo: Add details on how to interact with range property (#393)
LiyouZhou Sep 7, 2017
bec8c46
:memo: Add warning to input-handlers.md about concurrency (#400)
euphi Sep 22, 2017
d4d48e0
:bug: Interpret firmware file as an bytearray (#403)
LiyouZhou Sep 24, 2017
715ad3f
:memo: Update input-handlers.md (#401)
euphi Nov 15, 2017
e9fbf46
:sparkles: Use AsyncWebServer + Refactoring (#425)
timpur Nov 16, 2017
9859c0c
:art: Update BootNormal.cpp (#426)
scharph Nov 17, 2017
76e00a0
:arrow_up: Update dependency to "ESP Async WebServer" (#434)
ivankravets Nov 28, 2017
5f2576f
:memo: Add instruction for @PlatformIO (#435)
ivankravets Nov 28, 2017
1dc38e0
:bug: Use v2.0.0-beta.2 as a working tagged example for @PlatformIO (…
ivankravets Nov 28, 2017
1209ba6
:art: Simplify CI with @PlatformIO (#438)
ivankravets Nov 28, 2017
8e94d9e
:bug: Install library via @PlatformIO with all dependencies (#439)
ivankravets Nov 29, 2017
d3fc66d
:green_heart: CI: Install staging version of Arduino Core for ESP8266…
ivankravets Nov 29, 2017
48fa76d
:bug: Pin Shutters dep version
marvinroger Nov 29, 2017
f024c6d
:fire: Don't fail on CI docs step when testing a fork
marvinroger Nov 30, 2017
e41bb9c
:art: More Refactoring + Deep Sleep + Prevent WiFi Reconnect when reb…
timpur Nov 30, 2017
ad876b2
:art: First pass to fix linting
marvinroger Nov 30, 2017
65b89fa
:art: Second pass of lint
marvinroger Nov 30, 2017
93a00e9
:art: Final lint fix
marvinroger Nov 30, 2017
3dd1829
:memo: Update docs deps
marvinroger Dec 1, 2017
aa8e233
:memo: :art: Update docs manifest
marvinroger Dec 1, 2017
7f932c3
:memo: :art: Adjust HTTP JSON API doc
marvinroger Dec 1, 2017
f9f0232
:memo: Add configurators on website
marvinroger Dec 1, 2017
f605adf
:memo: Update links to configurator
marvinroger Dec 1, 2017
999959a
Fix links under Features (#452)
ashmckenzie Dec 21, 2017
89991d4
Set Device Stats Interval (#451) (#455)
timpur Dec 21, 2017
cd3c6e7
Add last step to uibundle README (#460)
Dec 26, 2017
63fb96d
Update updater script addressing quirks (#461)
Dec 26, 2017
9f05e09
Update API for /wifi/connect from GET to PUT (#468)
tripflex Jan 3, 2018
28469e4
Proposal to optionally run HomieNode::loop() also in disconnected state
euphi Feb 13, 2018
b5e8926
Show Homie version
timpur Mar 12, 2018
95d9566
Fix #446 #477 (#501)
timpur Mar 18, 2018
b7b6776
Fix Safari not displaying the config bundle HTML page (Fix #476) (#502)
timpur Mar 19, 2018
03938e1
Update Readme Homie Version
timpur Mar 19, 2018
901076f
Fix Warnings (#503)
timpur Mar 19, 2018
bfba03d
Update Readme - Homie Convention
timpur Mar 20, 2018
99161ce
Update to Homie Convention v2.0.1 (#507)
timpur Mar 30, 2018
2ce7192
Merge branch 'develop' of https://github.com/marvinroger/homie-esp826…
euphi Mar 31, 2018
4e1cfe5
Merge branch 'develop' into upstream-develop
euphi Mar 31, 2018
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
Prev Previous commit
Next Next commit
✨ Add OTA updater script (homieiot#384)
* 🐍Add python ota updater script

* 💼 Update documentation of ota update script

* 😑 Add comments to ota updater script

* 🔮 Use 127.0.0.1:1883 as default broker setting

For the ota updater script
  • Loading branch information
LiyouZhou authored and marvinroger committed Aug 20, 2017
commit e11b456ae19082f75002d8d3f7a1d65a419a1679
38 changes: 28 additions & 10 deletions scripts/ota_updater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,33 @@ This will allow you to send an OTA update to your device.
## Usage

```bash
python ./ota_update.py \
--broker-host "127.0.0.1" \
--broker-port "1883" \
--broker-username "" \
--broker-password "" \
--base-topic "homie/" \
--device-id "my-device-id" \
~/my_firmware.bin
> scripts/ota_updater/ota_updater.py -h
usage: ota_updater.py [-h] -l BROKER_HOST -p BROKER_PORT [-u BROKER_USERNAME]
[-d BROKER_PASSWORD] [-t BASE_TOPIC] -i DEVICE_ID
firmware

ota firmware update scirpt for ESP8226 implemenation of the Homie mqtt IoT
convention.

positional arguments:
firmware path to the firmware to be sent to the device

arguments:
-h, --help show this help message and exit
-l BROKER_HOST, --broker-host BROKER_HOST
host name or ip address of the mqtt broker
-p BROKER_PORT, --broker-port BROKER_PORT
port of the mqtt broker
-u BROKER_USERNAME, --broker-username BROKER_USERNAME
username used to authenticate with the mqtt broker
-d BROKER_PASSWORD, --broker-password BROKER_PASSWORD
password used to authenticate with the mqtt broker
-t BASE_TOPIC, --base-topic BASE_TOPIC
base topic of the homie devices on the broker
-i DEVICE_ID, --device-id DEVICE_ID
homie device id
```

All parameters are optional, except `--device-id` and the firmware path.
Default values are the one above.
* `BROKER_HOST` and `BROKER_PORT` defaults to 127.0.0.1 and 1883 respectively if not set.
* `BROKER_USERNAME` and `BROKER_PASSWORD` are optional.
* `BASE_TOPIC` defaults to `homie/` if not set
152 changes: 152 additions & 0 deletions scripts/ota_updater/ota_updater.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,153 @@
#!/usr/bin/env python

from __future__ import division, print_function
import paho.mqtt.client as mqtt
import base64, sys, math
from hashlib import md5

# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
if rc != 0:
print("Connection Failed with result code {}".format(rc))
client.disconnect()
else:
print("Connected with result code {}".format(rc))

# calcluate firmware md5
firmware_md5 = md5(userdata['firmware']).hexdigest()
userdata.update({'md5': firmware_md5})

# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("{base_topic}{device_id}/$implementation/ota/status".format(**userdata))
client.subscribe("{base_topic}{device_id}/$implementation/ota/enabled".format(**userdata))
client.subscribe("{base_topic}{device_id}/$fw/#".format(**userdata))

# Wait for device info to come in and invoke the on_message callback where update will continue
print("Waiting for device info...")


# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
# decode string for python2/3 compatiblity
msg.payload = msg.payload.decode()

if msg.topic.endswith('$implementation/ota/status'):
status = int(msg.payload.split()[0])

if userdata.get("published"):
if status == 206: # in progress
# state in progress, print progress bar
progress, total = [int(x) for x in msg.payload.split()[1].split('/')]
bar_width = 30
bar = int(bar_width*(progress/total))
print("\r[", '+'*bar, ' '*(bar_width-bar), "] ", msg.payload.split()[1], end='', sep='')
if (progress == total):
print()
sys.stdout.flush()
elif status == 304: # not modified
print("Device firmware already up to date with md5 checksum: {}".format(userdata.get('md5')))
client.disconnect()
elif status == 403: # forbidden
print("Device ota disabled, aborting...")
client.disconnect()

elif msg.topic.endswith('$fw/checksum'):
checksum = msg.payload

if userdata.get("published"):
if checksum == userdata.get('md5'):
print("Device back online. Update Successful!")
else:
print("Expecting checksum {}, got {}, update failed!".format(userdata.get('md5'), checksum))
client.disconnect()
else:
if checksum != userdata.get('md5'): # save old md5 for comparison with new firmware
userdata.update({'old_md5': checksum})
else:
print("Device firmware already up to date with md5 checksum: {}".format(checksum))
client.disconnect()

elif msg.topic.endswith('ota/enabled'):
if msg.payload == 'true':
userdata.update({'ota_enabled': True})
else:
print("Device ota disabled, aborting...")
client.disconnect()

if ( not userdata.get("published") ) and ( userdata.get('ota_enabled') ) and \
( 'old_md5' in userdata.keys() ) and ( userdata.get('md5') != userdata.get('old_md5') ):
# push the firmware binary
userdata.update({"published": True})
topic = "{base_topic}{device_id}/$implementation/ota/firmware/{md5}".format(**userdata)
print("Publishing new firmware with checksum {}".format(userdata.get('md5')))
client.publish(topic, userdata['firmware'])


def main(broker_host, broker_port, broker_username, broker_password, base_topic, device_id, firmware):
# initialise mqtt client and register callbacks
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

# set username and password if given
if broker_username and broker_password:
client.username_pw_set(broker_username, broker_password)

# save data to be used in the callbacks
client.user_data_set({
"base_topic": base_topic,
"device_id": device_id,
"firmware": firmware
})

# start connection
print("Connecting to mqtt broker {} on port {}".format(broker_host, broker_port))
client.connect(broker_host, broker_port, 60)

# Blocking call that processes network traffic, dispatches callbacks and handles reconnecting.
client.loop_forever()


if __name__ == '__main__':
import argparse

parser = argparse.ArgumentParser(
description='ota firmware update scirpt for ESP8226 implemenation of the Homie mqtt IoT convention.')

# ensure base topic always ends with a '/'
def base_topic_arg(s):
s = str(s)
if not s.endswith('/'):
s = s + '/'
return s

# specify arguments
parser.add_argument('-l', '--broker-host', type=str, required=False,
help='host name or ip address of the mqtt broker', default="127.0.0.1")
parser.add_argument('-p', '--broker-port', type=int, required=False,
help='port of the mqtt broker', default=1883)
parser.add_argument('-u', '--broker-username', type=str, required=False,
help='username used to authenticate with the mqtt broker')
parser.add_argument('-d', '--broker-password', type=str, required=False,
help='password used to authenticate with the mqtt broker')
parser.add_argument('-t', '--base-topic', type=base_topic_arg, required=False,
help='base topic of the homie devices on the broker', default="homie/")
parser.add_argument('-i', '--device-id', type=str, required=True,
help='homie device id')
parser.add_argument('firmware', type=argparse.FileType('rb'),
help='path to the firmware to be sent to the device')

# workaround for http://bugs.python.org/issue9694
parser._optionals.title = "arguments"

# get and validate arguments
args = parser.parse_args()

# read the contents of firmware into buffer
firmware = args.firmware.read()
args.firmware.close()

# Invoke the business logic
main(args.broker_host, args.broker_port, args.broker_username,
args.broker_password, args.base_topic, args.device_id, firmware)
2 changes: 1 addition & 1 deletion scripts/ota_updater/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
paho-mqtt==1.2.3
paho-mqtt >1.2.3,<=1.3.0