Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit f928e5f

Browse files
authored
Merge pull request #120 from pycom/pyb_1.4.0
[pybytes] updated to v1.4.0 (pymesh integration and coap client)
2 parents 435d6f2 + 6621135 commit f928e5f

12 files changed

+692
-282
lines changed

esp32/frozen/Pybytes/_OTA.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,24 @@ def update_device_network_config(self, fcota, config):
5757
def get_current_version(self):
5858
return os.uname().release
5959

60-
def get_update_manifest(self):
60+
def get_update_manifest(self, fwtype=None, token=None):
6161
current_version = self.get_current_version()
6262
sysname = os.uname().sysname
6363
wmac = hexlify(machine.unique_id()).decode('ascii')
64-
request_template = "manifest.json?current_ver={}&sysname={}&wmac={}&ota_slot={}"
65-
req = request_template.format(current_version, sysname, wmac, hex(pycom.ota_slot()))
64+
if fwtype == 'pymesh':
65+
request_template = "manifest.json?current_ver={}&sysname={}&token={}&ota_slot={}&wmac={}&fwtype={}"
66+
req = request_template.format(current_version, sysname, token, hex(pycom.ota_slot()), wmac.upper(), fwtype)
67+
else:
68+
request_template = "manifest.json?current_ver={}&sysname={}&wmac={}&ota_slot={}"
69+
req = request_template.format(current_version, sysname, wmac, hex(pycom.ota_slot()))
6670
manifest_data = self.get_data(req).decode()
6771
manifest = ujson.loads(manifest_data)
6872
gc.collect()
6973
return manifest
7074

71-
def update(self, customManifest=None):
75+
def update(self, customManifest=None, fwtype=None, token=None):
7276
try:
73-
manifest = self.get_update_manifest() if not customManifest else customManifest
77+
manifest = self.get_update_manifest(fwtype, token) if not customManifest else customManifest
7478
except Exception as e:
7579
print('Error reading the manifest, aborting: {}'.format(e))
7680
return 0
@@ -240,7 +244,6 @@ def get_data(self, req, dest_path=None, hash=False, firmware=False):
240244
fp = open(dest_path, 'wb')
241245

242246
if firmware:
243-
print('start')
244247
pycom.ota_start()
245248

246249
h = uhashlib.sha1()

esp32/frozen/Pybytes/_coap.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'''
2+
Copyright (c) 2020, Pycom Limited.
3+
This software is licensed under the GNU GPL version 3 or any
4+
later version, with permitted additional terms. For more information
5+
see the Pycom Licence v1.0 document supplied with this file, or
6+
available at https://www.pycom.io/opensource/licensing
7+
'''
8+
9+
from network import WLAN
10+
from network import Coap
11+
# import uselect
12+
# import _thread
13+
# import machine
14+
15+
16+
class COAPClient():
17+
def __init__(self, target_server, port):
18+
self.__coap_server = target_server
19+
self.__coap_server_port = port
20+
21+
wlan = WLAN(mode=WLAN.STA)
22+
self.__device_ip = wlan.ifconfig()[0]
23+
24+
Coap.init(str(wlan.ifconfig()[0]), service_discovery=False)
25+
26+
def send_coap_message(self, message, method, uri_path, token, include_options=True):
27+
message_id = Coap.send_request(
28+
self.__coap_server,
29+
method,
30+
uri_port=int(self.__coap_server_port),
31+
uri_path=uri_path,
32+
payload=message,
33+
token=token,
34+
include_options=include_options
35+
)
36+
return message_id
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
Copyright (c) 2020, Pycom Limited.
3+
This software is licensed under the GNU GPL version 3 or any
4+
later version, with permitted additional terms. For more information
5+
see the Pycom Licence v1.0 document supplied with this file, or
6+
available at https://www.pycom.io/opensource/licensing
7+
'''
8+
9+
10+
class PeriodicalPin:
11+
12+
TYPE_DIGITAL = 0
13+
TYPE_ANALOG = 1
14+
TYPE_VIRTUAL = 2
15+
16+
def __init__(self, persistent, pin_number, message_type, message, pin_type):
17+
self.pin_number = pin_number
18+
self.message_type = message_type
19+
self.message = message
20+
self.pin_type = pin_type

0 commit comments

Comments
 (0)