Skip to content

Commit

Permalink
Merge pull request #6 from Carglglz/develop
Browse files Browse the repository at this point in the history
Merge Develop branch for upydevice 0.3.2
  • Loading branch information
Carglglz authored Oct 24, 2021
2 parents b090e01 + e12a063 commit 0bd0686
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [0.3.3] Unreleased Github Repo [develop]
## [0.3.2] 2021-10-24
### Added
- mDNS `.local`/`dhcp_hostname` compatibility, so device configuration works across networks
### Fix
- `check -i`, `info` commands in `-apmd`, if connected to AP of the device.
## [0.3.1] - 2021-09-09
### Fix
- KeyboardInterrupt in AsyncBleDevice for jupyter_upydevice_kernel
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Carlos G. Gonzalez'

# The full version, including alpha/beta/rc tags
release = '0.3.0'
release = '0.3.2'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def readme():


setup(name='upydevice',
version='0.3.1',
version='0.3.2',
description='Python library to interface with wireless/serial MicroPython devices',
long_description=readme(),
long_description_content_type='text/markdown',
Expand Down
2 changes: 1 addition & 1 deletion upydevice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@

from .upydevice import *
name = 'upydevice'
__version__ = '0.3.1'
__version__ = '0.3.2'
17 changes: 14 additions & 3 deletions upydevice/upydevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
# SOFTWARE.



from .serialdevice import *
from .websocketdevice import *
from .devgroup import *
from .decorators import *
from .bledevice import *
from .exceptions import *
from ipaddress import ip_address
import socket


def check_device_type(dev_address):
def check_device_type(dev_address, resolve_name=False):
if isinstance(dev_address, str):
if '.' in dev_address and dev_address.count('.') == 3:
# check IP
Expand All @@ -41,11 +41,20 @@ def check_device_type(dev_address):
return 'WebSocketDevice'
except Exception as e:
print(e)
elif dev_address.endswith('.local'):
try:
if resolve_name:
return check_device_type(socket.gethostbyname(dev_address))
else:
return 'WebSocketDevice'
except Exception as e:
print(e)
elif 'COM' in dev_address or '/dev/' in dev_address:
return 'SerialDevice'
elif len(dev_address.split('-')) == 5:
try:
assert [len(s) for s in dev_address.split('-')] == [8, 4, 4, 4, 12], dev_address
assert [len(s) for s in dev_address.split(
'-')] == [8, 4, 4, 4, 12], dev_address
return 'BleDevice'
except Exception as e:
print('uuid malformed')
Expand All @@ -69,6 +78,8 @@ def Device(dev_address, password=None, **kargs):
baudrt = fkargs.pop('baudrate')
return SerialDevice(dev_address, baudrate=baudrt, **fkargs)
if dev_type == 'WebSocketDevice':
if dev_address.endswith('.local'):
dev_address = socket.gethostbyname(dev_address)
return WebSocketDevice(dev_address, password, **kargs)
if dev_type == 'BleDevice':
pop_args = ['ssl', 'auth', 'capath']
Expand Down
24 changes: 17 additions & 7 deletions upydevice/websocketdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def __init__(self, target, password, init=False, ssl=False, auth=False,
self.connected = True
self.repl_CONN = self.connected
else:
raise DeviceNotFound("WebSocketDevice @ {}://{}:{} is not reachable".format(self._uriprotocol, self.ip, self.port))
raise DeviceNotFound(
"WebSocketDevice @ {}://{}:{} is not reachable".format(self._uriprotocol, self.ip, self.port))

def open_wconn(self, ssl=False, auth=False, capath=CA_PATH[0]):
try:
Expand All @@ -157,7 +158,8 @@ def open_wconn(self, ssl=False, auth=False, capath=CA_PATH[0]):
self.connected = True
self.repl_CONN = self.connected
else:
raise DeviceNotFound("WebSocketDevice @ {}://{}:{} is not reachable".format(self._uriprotocol, self.ip, self.port))
raise DeviceNotFound(
"WebSocketDevice @ {}://{}:{} is not reachable".format(self._uriprotocol, self.ip, self.port))
except Exception as e:
print(e)

Expand Down Expand Up @@ -382,11 +384,19 @@ def __repr__(self):
self.connect()
repr_cmd = "import sys;import os;from machine import unique_id; import network; \
[os.uname().sysname, os.uname().release, os.uname().version, \
os.uname().machine, unique_id(), sys.implementation.name, network.WLAN(network.STA_IF).status('rssi')]"
(self.dev_platform, self._release,
self._version, self._machine, uuid, imp, rssi) = self.wr_cmd(repr_cmd,
silent=True,
rtn_resp=True)
os.uname().machine, unique_id(), sys.implementation.name, {}]"
if self.ip == '192.168.4.1':
rssi = 0
(self.dev_platform, self._release,
self._version, self._machine, uuid, imp, _) = self.wr_cmd(repr_cmd,
silent=True,
rtn_resp=True)
else:
repr_cmd = repr_cmd.format("network.WLAN(network.STA_IF).status('rssi')")
(self.dev_platform, self._release,
self._version, self._machine, uuid, imp, rssi) = self.wr_cmd(repr_cmd,
silent=True,
rtn_resp=True)
# uid = self.wr_cmd("from machine import unique_id; unique_id()",
# silent=True, rtn_resp=True)
vals = hexlify(uuid).decode()
Expand Down

0 comments on commit 0bd0686

Please sign in to comment.