Python Tools

Gateways

Utilise gateway scripts to interact with Infuse-IoT Powered devices.

The python gateway tools act as a bridge between local Infuse-IoT devices and other tools running on the computer. Currently the gateways support interaction with devices connected directly via a serial port, or directly over Bluetooth.

Bluetooth connectivity can be provided:

  • Via an Infuse-IoT powered embedded device with the infuse gateway tool. (Preferred) or
  • Directly via your machines native PC Bluetooth libraries with the infuse native_bt tool
    Using infuse native_bt requires compatible hardware with Bluetooth 5.0 and support advertising extension capabilities. See below for more details.
How Python tools use gateway connections to connect to Infuse-IoT devices
---
toolbar:
  title: How Python tools use gateway connections to connect to Infuse-IoT devices
---
flowchart LR
    Tool["Python tool<br/>(RPC runner, OTA upgrade, etc.)"]
    Gateway["infuse gateway"]
    DeviceGateway["Infuse-IoT device<br/>running gateway_usb"]
    NativeBT["infuse native_bt"]
    DeviceBT["Infuse-IoT device"]

    Tool <-->|UDP| Gateway
    Gateway <-->|Serial| DeviceGateway
    Gateway <-->|RTT| DeviceGateway
    Gateway <-->|PyOCD| DeviceGateway
    DeviceGateway <-->|Bluetooth| DeviceBT
    Tool <-->|UDP| NativeBT
    NativeBT <-->|Bluetooth| DeviceBT

Both tools are designed to run persistently in the background, managing connections to remote devices, forwarding packets out to Infuse-IoT hardware and broadcasting received data on localhost multicast UDP sockets.

Gateway tools rely on an Infuse-IoT API Key and any Custom Network Keys and definitions being provided through the Credentials command.

Common Functionality

Both gateway tools have common configuration options

--server-port: Server Port

The --server-port argument is used to run more than one instance of infuse gateway concurrently on the same machine.

When specifying --server-port, the port must be an odd number.

--root: Key File

In some instances, Tags utilise a Root Identity that is different from that provided by the Infuse-IoT Cloud. In such instances, utilising the default Cloud for authentication will cause cryptography to fail.

As a result, a root identity certificate can be provided to override the default Cloud identity with the --root argument.

Native Bluetooth

Native Bluetooth support is supported through the cross platform bleak package.

> infuse native_bt -h
usage: infuse native_bt [-h] [--root ROOT] [--server-port SERVER_SOCK]

Use the local Bluetooth adapter for Bluetooth interaction

options:
  -h, --help            show this help message and exit
  --root ROOT           Root identity certificate to use instead of cloud
  --server-port SERVER_SOCK
                        Alternate port to use for Gateway connections (default
                        8751)
Your machine must support the required Bluetooth Hardware Requirements to use infuse native_bt.
native_bt is convenient, however uses the Operating System's managed Bluetooth APIs. As a result, OS power saving policies can and will interfer with the tool's functionality.

Follow the instructions below to check compatibility.

Ensure your Bluetooth Adaptor supports Bluetooth 5.0 and advertising extensions.

Some older Bluetooth hardware might be compatible, but might not work out of the box.
Updating Bluetooth Drivers may help.
Native Bluetooth is not available when using WSL. Utilise the Infuse-IoT powered hardware options instead.

Embedded Devices

To create a bridge to a physically connected device, use the infuse gateway command. This command can be used both for firmrware applications that forward data over Bluetooth (such as infuse-sdk/apps/gateway_usb) or devices that only interact over the physical link, or even just to view device debug logs.

Supported backends

An appropriate physical connection interface (backend) must be provided to the tool depending on the physical connection:

> infuse gateway --help
usage: infuse gateway [-h] (--serial SERIAL | --rtt RTT | --pyocd PYOCD) [--display-only] [--log [filename]]

Connect to a gateway device over serial and route commands to Bluetooth devices

options:
  -h, --help            show this help message and exit
  --serial SERIAL       Gateway serial port
  --rtt RTT             RTT serial port
  --pyocd PYOCD         RTT via PyOCD
  --display-only, -d    No networking, only display serial
  --log [filename], -l [filename]
                        Save serial output to file
  --baud BAUD           Baudrate for serial port
  --root ROOT           Root identity certificate to use instead of cloud
  --server-port SERVER_SOCK
                        Alternate port to use for Gateway connections (default 8751)
  • --serial is used for standard serial ports (e.g. COMx, /dev/ttyACMx).
  • --rtt is used for RTT through pylink. The argument is the device name (e.g. nRF52840_xxAA)
  • --pyocd is used for RTT through pyocd. The argument is the device name (e.g. stm32l451ceux)

--display-only: Only display serial output

As the tool is also useful to display basic text logging message displays, the networking aspect of the tool can be disabled with --display-only or -d.

--log: Record serial logs to a file

Recording of the serial logs to a dedicated file can be enabled with the --log parameter. This can be useful for long lived monitoring that would otherwise be lost due to terminal scrollback limits.

--baud: Specify the baud rate for serial connections

When using --serial the baud rate can be specified with --baud.