Add first PoC
This commit is contained in:
commit
f4d951a088
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
bottle==0.12.13
|
40
update_server.py
Normal file
40
update_server.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python3
|
||||
import hashlib
|
||||
from bottle import route, run, request, HTTPResponse, response
|
||||
import pdb
|
||||
|
||||
updated = True
|
||||
filename = "firmware.bin"
|
||||
|
||||
@route('/update')
|
||||
def update():
|
||||
#for header in request.headers.keys():
|
||||
# print("{}: {}".format(header, request.headers.get(header, "")))
|
||||
|
||||
requestor_mac = request.headers.get("X-Esp8266-Sta-Mac")
|
||||
running_fw_md5 = request.headers.get("X-Esp8266-Sketch-Md5", "")
|
||||
print("Update request from {} with fw {}".format(requestor_mac, running_fw_md5))
|
||||
available_fw_md5 = md5(filename)
|
||||
|
||||
print("Lates firmware available is {} - ".format(available_fw_md5), end="")
|
||||
if available_fw_md5 != running_fw_md5:
|
||||
print("Differs, updating…")
|
||||
response.set_header('Content-Type', 'application/octet-stream')
|
||||
response.set_header('Content-Disposition', ' attachment; filename={}'.format(filename))
|
||||
with open(filename, "rb") as firmware:
|
||||
fw = firmware.read()
|
||||
response.set_header('Content-Length', '{}'.format(len(fw)))
|
||||
response.set_header('X-MD5', available_fw_md5)
|
||||
return fw
|
||||
else:
|
||||
print("Same, skipping…")
|
||||
return HTTPResponse(status=304, body="")
|
||||
|
||||
def md5(fname):
|
||||
hash_md5 = hashlib.md5()
|
||||
with open(fname, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(4096), b""):
|
||||
hash_md5.update(chunk)
|
||||
return hash_md5.hexdigest()
|
||||
|
||||
run(host='localhost', port=8080, debug=True)
|
Loading…
Reference in a new issue