Skip to content

Commit 0bd0686

Browse files
authored
Merge pull request #6 from Carglglz/develop
Merge Develop branch for upydevice 0.3.2
2 parents b090e01 + e12a063 commit 0bd0686

File tree

6 files changed

+40
-13
lines changed

6 files changed

+40
-13
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
66

7+
## [0.3.3] Unreleased Github Repo [develop]
8+
## [0.3.2] 2021-10-24
9+
### Added
10+
- mDNS `.local`/`dhcp_hostname` compatibility, so device configuration works across networks
11+
### Fix
12+
- `check -i`, `info` commands in `-apmd`, if connected to AP of the device.
713
## [0.3.1] - 2021-09-09
814
### Fix
915
- KeyboardInterrupt in AsyncBleDevice for jupyter_upydevice_kernel

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Carlos G. Gonzalez'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '0.3.0'
25+
release = '0.3.2'
2626

2727

2828
# -- General configuration ---------------------------------------------------

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def readme():
99

1010

1111
setup(name='upydevice',
12-
version='0.3.1',
12+
version='0.3.2',
1313
description='Python library to interface with wireless/serial MicroPython devices',
1414
long_description=readme(),
1515
long_description_content_type='text/markdown',

upydevice/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@
148148

149149
from .upydevice import *
150150
name = 'upydevice'
151-
__version__ = '0.3.1'
151+
__version__ = '0.3.2'

upydevice/upydevice.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
# SOFTWARE.
2323

2424

25-
2625
from .serialdevice import *
2726
from .websocketdevice import *
2827
from .devgroup import *
2928
from .decorators import *
3029
from .bledevice import *
3130
from .exceptions import *
3231
from ipaddress import ip_address
32+
import socket
3333

3434

35-
def check_device_type(dev_address):
35+
def check_device_type(dev_address, resolve_name=False):
3636
if isinstance(dev_address, str):
3737
if '.' in dev_address and dev_address.count('.') == 3:
3838
# check IP
@@ -41,11 +41,20 @@ def check_device_type(dev_address):
4141
return 'WebSocketDevice'
4242
except Exception as e:
4343
print(e)
44+
elif dev_address.endswith('.local'):
45+
try:
46+
if resolve_name:
47+
return check_device_type(socket.gethostbyname(dev_address))
48+
else:
49+
return 'WebSocketDevice'
50+
except Exception as e:
51+
print(e)
4452
elif 'COM' in dev_address or '/dev/' in dev_address:
4553
return 'SerialDevice'
4654
elif len(dev_address.split('-')) == 5:
4755
try:
48-
assert [len(s) for s in dev_address.split('-')] == [8, 4, 4, 4, 12], dev_address
56+
assert [len(s) for s in dev_address.split(
57+
'-')] == [8, 4, 4, 4, 12], dev_address
4958
return 'BleDevice'
5059
except Exception as e:
5160
print('uuid malformed')
@@ -69,6 +78,8 @@ def Device(dev_address, password=None, **kargs):
6978
baudrt = fkargs.pop('baudrate')
7079
return SerialDevice(dev_address, baudrate=baudrt, **fkargs)
7180
if dev_type == 'WebSocketDevice':
81+
if dev_address.endswith('.local'):
82+
dev_address = socket.gethostbyname(dev_address)
7283
return WebSocketDevice(dev_address, password, **kargs)
7384
if dev_type == 'BleDevice':
7485
pop_args = ['ssl', 'auth', 'capath']

upydevice/websocketdevice.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def __init__(self, target, password, init=False, ssl=False, auth=False,
139139
self.connected = True
140140
self.repl_CONN = self.connected
141141
else:
142-
raise DeviceNotFound("WebSocketDevice @ {}://{}:{} is not reachable".format(self._uriprotocol, self.ip, self.port))
142+
raise DeviceNotFound(
143+
"WebSocketDevice @ {}://{}:{} is not reachable".format(self._uriprotocol, self.ip, self.port))
143144

144145
def open_wconn(self, ssl=False, auth=False, capath=CA_PATH[0]):
145146
try:
@@ -157,7 +158,8 @@ def open_wconn(self, ssl=False, auth=False, capath=CA_PATH[0]):
157158
self.connected = True
158159
self.repl_CONN = self.connected
159160
else:
160-
raise DeviceNotFound("WebSocketDevice @ {}://{}:{} is not reachable".format(self._uriprotocol, self.ip, self.port))
161+
raise DeviceNotFound(
162+
"WebSocketDevice @ {}://{}:{} is not reachable".format(self._uriprotocol, self.ip, self.port))
161163
except Exception as e:
162164
print(e)
163165

@@ -382,11 +384,19 @@ def __repr__(self):
382384
self.connect()
383385
repr_cmd = "import sys;import os;from machine import unique_id; import network; \
384386
[os.uname().sysname, os.uname().release, os.uname().version, \
385-
os.uname().machine, unique_id(), sys.implementation.name, network.WLAN(network.STA_IF).status('rssi')]"
386-
(self.dev_platform, self._release,
387-
self._version, self._machine, uuid, imp, rssi) = self.wr_cmd(repr_cmd,
388-
silent=True,
389-
rtn_resp=True)
387+
os.uname().machine, unique_id(), sys.implementation.name, {}]"
388+
if self.ip == '192.168.4.1':
389+
rssi = 0
390+
(self.dev_platform, self._release,
391+
self._version, self._machine, uuid, imp, _) = self.wr_cmd(repr_cmd,
392+
silent=True,
393+
rtn_resp=True)
394+
else:
395+
repr_cmd = repr_cmd.format("network.WLAN(network.STA_IF).status('rssi')")
396+
(self.dev_platform, self._release,
397+
self._version, self._machine, uuid, imp, rssi) = self.wr_cmd(repr_cmd,
398+
silent=True,
399+
rtn_resp=True)
390400
# uid = self.wr_cmd("from machine import unique_id; unique_id()",
391401
# silent=True, rtn_resp=True)
392402
vals = hexlify(uuid).decode()

0 commit comments

Comments
 (0)