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

Commit 630aa1f

Browse files
author
Catalin Ioana
authored
Merge pull request #158 from pycom/pybytes_1.5.2
[pybytes] updated to v1.5.2 (pymesh BR fix)
2 parents bd8fd3b + 2f0ea01 commit 630aa1f

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
lines changed

esp32/frozen/Pybytes/_OTA.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ def get_update_manifest(self, fwtype=None, token=None):
6262
sysname = os.uname().sysname
6363
wmac = hexlify(machine.unique_id()).decode('ascii')
6464
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)
65+
request_template = "manifest.json?current_ver={}&sysname={}&token={}&ota_slot={}&wmac={}&fwtype={}&current_fwtype={}"
66+
req = request_template.format(current_version, sysname, token, hex(pycom.ota_slot()), wmac.upper(), fwtype, 'pymesh' if hasattr(os.uname(),'pymesh') else 'pybytes')
67+
elif fwtype == 'pygate':
68+
request_template = "manifest.json?current_ver={}&sysname={}&ota_slot={}&wmac={}&fwtype={}&current_fwtype={}"
69+
req = request_template.format(current_version, sysname, hex(pycom.ota_slot()), wmac.upper(), fwtype, 'pygate' if hasattr(os.uname(),'pygate') else 'pybytes')
6770
else:
6871
request_template = "manifest.json?current_ver={}&sysname={}&wmac={}&ota_slot={}"
6972
req = request_template.format(current_version, sysname, wmac, hex(pycom.ota_slot()))

esp32/frozen/Pybytes/_pybytes_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def connect_lte(self, activation_info=False, start_mqtt=True):
173173
self.__initialise_watchdog()
174174

175175
if lte_cfg is not None:
176-
if (os.uname()[0] not in ['FiPy', 'GPy']):
176+
if (os.uname().sysname not in ['FiPy', 'GPy']):
177177
print("You need a device with FiPy or GPy firmware to connect via LTE") # noqa
178178
return False
179179
try:

esp32/frozen/Pybytes/_pybytes_constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class constants:
105105
__DEVICE_TYPE_LOPY_4 = 0x04
106106
__DEVICE_TYPE_UNKNOWN = 0x05
107107

108+
__FWTYPE_DEFAULT = 0x00
109+
__FWTYPE_PYMESH = 0x01
110+
__FWTYPE_PYGATE = 0x02
111+
108112
# {"ssid":"%s", "mac_addr":"%s", "channel":"%s", "power":"%s"}
109113
__WIFI_NETWORK_FORMAT = ">6sBb"
110114

esp32/frozen/Pybytes/_pybytes_library.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,18 @@ def pack_info_message(self, releaseVersion=None):
8686
body.append((release >> 8) & 0xFF)
8787
body.append(release & 0xFF)
8888

89-
if releaseVersion is not None:
90-
body.append((releaseVersion >> 8) & 0xFF)
91-
body.append(releaseVersion & 0xFF)
89+
if releaseVersion is None:
90+
releaseVersion = 0
91+
92+
body.append((releaseVersion >> 8) & 0xFF)
93+
body.append(releaseVersion & 0xFF)
94+
95+
if hasattr(os.uname(), 'pymesh'):
96+
body.append(constants.__FWTYPE_PYMESH)
97+
elif hasattr(os.uname(), 'pygate'):
98+
body.append(constants.__FWTYPE_PYGATE)
99+
else:
100+
body.append(constants.__FWTYPE_DEFAULT)
92101

93102
return self.__pack_message(constants.__TYPE_INFO, body)
94103

esp32/frozen/Pybytes/_pybytes_pymesh_config.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ def pymesh_init(self):
5353
# initialize Pymesh
5454
self.__pymesh = Pymesh(self.__pymesh_config, self.pymesh_new_message_cb)
5555

56-
while not self.__pymesh.is_connected():
57-
print(self.__pymesh.status_str())
58-
time.sleep(3)
59-
60-
# send message to the Node having MAC address 5
61-
self.__pymesh.send_mess(2, "Hello World")
62-
print("Done Pymesh init, forever loop, exit/stop with Ctrl+C multiple times")
6356
self.__pymesh_br_enabled = False
6457

6558
if self.__pymesh_config.get("br_ena", False):
@@ -69,8 +62,6 @@ def pymesh_init(self):
6962
print_debug(99, "Set as border router")
7063
self.__pymesh.br_set(PymeshConfig.BR_PRIORITY_NORM, self.pymesh_new_br_message_cb)
7164

72-
self.__pybytes.send_signal(1, str(self.__pymesh.mac()) + " : " + str(time.time()) + "s, " + str(pycom.get_free_heap()))
73-
print_debug(99, "Send to Pyb,", pycom.get_free_heap())
7465
else: # not connected anymore to pybytes
7566
if self.__pymesh_br_enabled:
7667
self.__pymesh_br_enabled = False
@@ -88,8 +79,13 @@ def unpack_pymesh_message(self, signal_number, value):
8879
pyb_ip = '1:2:3::' + hex(pyb_port)[2:]
8980
pkt_start = self.__pack_tocken_prefix + self.__pack_tocken_sep + deviceID + self.__pack_tocken_sep
9081

91-
self.__pymesh.send_mess_external(pyb_ip, pyb_port, pkt_start + monitoringData)
92-
self.__pymesh.send_mess_external(pyb_ip, pyb_port, pkt_start + value)
82+
# send data to the port equal with signal_number
83+
self.__pymesh.send_mess_external(pyb_ip, signal_number, pkt_start + value)
84+
85+
time.sleep(3) # shouldn't send too fast to BR
86+
87+
# hardcode monitoring data to be sent on signal #2
88+
self.__pymesh.send_mess_external(pyb_ip, 2, pkt_start + monitoringData)
9389

9490
def pymesh_new_message_cb(self, rcv_ip, rcv_port, rcv_data):
9591
''' callback triggered when a new packet arrived '''
@@ -122,9 +118,11 @@ def pymesh_new_br_message_cb(self, rcv_ip, rcv_port, rcv_data, dest_ip, dest_por
122118
if len(x) > 2:
123119
token = x[1]
124120
rcv_data = rcv_data[len(self.__pack_tocken_prefix) + len(token) + len(self.__pack_tocken_sep):]
125-
pkt = 'BR %d B from %s (%s), to %s ( %d): %s' % (len(rcv_data), token, rcv_ip, dest_ip, dest_port, str(rcv_data))
126-
print_debug(99, 'Pymesh node packet: {} '.format(pkt))
127-
self.__pybytes.send_node_signal(1, str(rcv_data.decode()).replace("#", ""), token.decode())
121+
122+
# send data to Pybytes only if it's coded properly
123+
pkt = 'BR %d B from %s (%s), to %s ( %d): %s' % (len(rcv_data), token, rcv_ip, dest_ip, dest_port, str(rcv_data))
124+
print_debug(99, 'Pymesh node packet: {} '.format(pkt))
125+
self.__pybytes.send_node_signal(dest_port & 0xFF, str(rcv_data.decode()).replace("#", ""), token.decode())
128126
return
129127

130128
def get_config(self, token, silent=False):

esp32/pycom_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define SIGFOX_VERSION_NUMBER "1.0.1"
1818

1919
#if (VARIANT == PYBYTES)
20-
#define PYBYTES_VERSION_NUMBER "1.5.0"
20+
#define PYBYTES_VERSION_NUMBER "1.5.2"
2121
#endif
2222

2323
#ifdef PYGATE_ENABLED

0 commit comments

Comments
 (0)