Skip to content

Commit

Permalink
Async version: throw exception if socket connection cannot be made
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYsLab committed Mar 12, 2024
1 parent e1c47ef commit 55a4d0e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
6 changes: 0 additions & 6 deletions docs/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ renesas architecture(s).

## BLE

### Server Side Issues
BLE support for Arduino UNO R4 boards is in a Beta state. Currently, it does not
support the Servo library. An [issue has been generated](https://github.com/arduino-libraries/ArduinoBLE/issues/311) against the ArduinoBLE library.

Instructions to install the Beta version of ArduinoBLE [may be found here.](https://forum.arduino.cc/t/radio-module-firmware-version-0-2-0-is-now-available/1147361)

### Client Side Issues
BLE is only supported using the [asyncio API](telemetrix_wifi_reference_aio.md). The
threaded API does not support BLE.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ find = {} # Scan the project directory with the default parameters

[project]
name = "telemetrix_uno_r4"
version = "1.0.3"
version = "1.1.0"
authors = [
{ name="Alan Yorinks", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion telemetrix_uno_r4/r4_wifi_examples/asyncio/BLE/wba_dht.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def dht(my_board, pin):
"""
await my_board.start_aio()
# set the pin mode for a DHT 11 or 22
await my_board.set_pin_mode_dht(pin, the_callback, dht_type=11)
await my_board.set_pin_mode_dht(pin, the_callback, dht_type=22)

# just sit in a loop waiting for the reports to come in
while True:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class PrivateConstants:
FEATURES = 20
DEBUG_PRINT = 99

TELEMETRIX_VERSION = "1.00"
TELEMETRIX_VERSION = "1.1.0"

# reporting control
REPORTING_DISABLE_ALL = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class PrivateConstants:
FEATURES = 20
DEBUG_PRINT = 99

TELEMETRIX_VERSION = "1.03"
TELEMETRIX_VERSION = "1.1.0"

# reporting control
REPORTING_DISABLE_ALL = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ async def start(self):
print(f'Successfully connected to: {self.ip_address}:{self.ip_port}')
except OSError:
print("Can't open connection to " + self.ip_address)
sys.exit(0)
raise RuntimeError
# sys.exit(0)

async def write(self, data):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ async def start_aio(self):
except KeyboardInterrupt:
if self.shutdown_on_exception:
await self.shutdown()

if self.com_port:
print(f'Telemetrix4UnoR4WIFI found and connected to {self.com_port}')

# no com_port found - raise a runtime exception
else:
if self.shutdown_on_exception:
Expand All @@ -335,10 +335,15 @@ async def start_aio(self):
await self.disable_scroll_message()
# using tcp/ip
elif self.transport_type == PrivateConstants.WIFI_TRANSPORT:
self.sock = TelemetrixAioSocket(self.transport_address, self.ip_port, self.loop)
await self.sock.start()
self.sock = TelemetrixAioSocket(self.transport_address, self.ip_port,
self.loop)
try:
await self.sock.start()
except OSError:
raise RuntimeError('Could not connect to this address')
else: # ble
self.ble_instance = TelemetrixAioBle(self.ble_device_name, self._ble_report_dispatcher)
self.ble_instance = TelemetrixAioBle(self.ble_device_name,
self._ble_report_dispatcher)
await self.ble_instance.connect()

# get arduino firmware version and print it
Expand Down Expand Up @@ -977,7 +982,7 @@ async def set_pin_mode_spi(self, chip_select_list=None):
"""
if self.reported_features & PrivateConstants.SPI_FEATURE:

if type(chip_select_list) != list:
if type(chip_select_list) is not list:
if self.shutdown_on_exception:
await self.shutdown()
raise RuntimeError('chip_select_list must be in the form of a list')
Expand Down Expand Up @@ -1109,7 +1114,7 @@ async def spi_cs_control(self, chip_select_pin, select):

async def spi_read_blocking(self, chip_select, register_selection,
number_of_bytes_to_read,
call_back=None):
call_back=None):
"""
Read the specified number of bytes from the specified SPI port and
call the callback function with the reported data.
Expand Down Expand Up @@ -1342,7 +1347,7 @@ async def spi_write_blocking(self, chip_select, bytes_to_write):
#
# command = [PrivateConstants.ONE_WIRE_READ]
# await self._send_command(command)
# await asynio.sleep(.2)
# await asyncio.sleep(.2)
#
# async def onewire_reset_search(self):
# """
Expand Down Expand Up @@ -2476,6 +2481,7 @@ async def _sonar_distance_report(self, report):

async def _stepper_distance_to_go_report(self, report):
return # for now

# """
# Report stepper distance to go.
#
Expand Down Expand Up @@ -2503,6 +2509,7 @@ async def _stepper_distance_to_go_report(self, report):

async def _stepper_target_position_report(self, report):
return # for now

# """
# Report stepper target position to go.
#
Expand Down Expand Up @@ -2532,6 +2539,7 @@ async def _stepper_target_position_report(self, report):

async def _stepper_current_position_report(self, report):
return # for now

# """
# Report stepper current position.
#
Expand Down Expand Up @@ -2562,6 +2570,7 @@ async def _stepper_current_position_report(self, report):

async def _stepper_is_running_report(self, report):
return # for now

# """
# Report if the motor is currently running
#
Expand All @@ -2582,6 +2591,7 @@ async def _stepper_is_running_report(self, report):

async def _stepper_run_complete_report(self, report):
return # for now

# """
# The motor completed it motion
#
Expand Down

0 comments on commit 55a4d0e

Please sign in to comment.