Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worth taking a look at pyspinel CLI as a reference? #3

Open
Hedda opened this issue Nov 15, 2021 · 1 comment
Open

Worth taking a look at pyspinel CLI as a reference? #3

Hedda opened this issue Nov 15, 2021 · 1 comment

Comments

@Hedda
Copy link

Hedda commented Nov 15, 2021

While the pyspinel is not made for Zigbee but for OpenThread NCPs instead, concepts in the Spinel CLI might however still be interesting as it is a relatively mature CLI for an NCP and actively maintained so might cover a lot of the same wishlist that developers and users would want?

A Python CLI tool called "Pyspinel" is available for testing purposes (and it is an active project so still being developed):

https://openthread.io/guides/pyspinel

Pyspinel, available on the pyspinel GitHub repository, is a Python CLI for the Spinel protocol.

The Spinel CLI exposes the OpenThread configuration and management APIs running on an NCP build via a command line interface. Spinel CLI is primarily targeted for driving the automated continuous integration tests, and is suitable for manual experimentation with controlling OpenThread NCP instances.

Pyspinel is used to:

  • Add simulated Co-Processor testing to continuous integration.
  • Automate testing of testbeds running Co-Processor firmware on hardware.
  • Debug Co-Processor builds of OpenThread.
  • Convert an OpenThread Co-Processor into a packet sniffer.

Use the CLI to play with NCP builds of OpenThread on a Linux or Mac OS platform, including starting a basic tunnel interface to allow IPv6 applications to run on the HOST and use the Thread network.

The power of this tool is threefold:

  1. As a path to add testing of the NCP in simulation to continuous integration
  2. As a path to automated testing of testbeds running NCP firmware on hardware
  3. As a simple debugging tool for NCP builds of OpenThread

For more information, see the Internet-Draft for the Spinel Host-Controller Protocol:

https://datatracker.ietf.org/doc/html/draft-rquattle-spinel-unified

This full protocol source code is also included with OpenThread at /src/lib/spinel in openthread repo:

https://github.com/openthread/openthread/tree/master/src/lib/spinel

For a production grade host driver that uses the Spinel CLI , see the "wpantund" project:

https://github.com/openthread/wpantund

One specific concept it had is "Vendor package" extension of the Spinel CLI with custom properties and commands:

https://github.com/openthread/pyspinel#vendor-package

"This plugin-like extension adds vendor-specific commands and properties to pyspinel in a way that does not impact the implementation of core pyspinel functionalities."

Just noticed this when Elelabs (maker of the Elelabs and Popp Zigbee sticks) forked it and made a vendor package for it:

https://github.com/Elelabs/pyspinel/tree/elelabs/elelabs

With that they have started by including "btl", "data", and "help" as Elelabs Pyspinel vendor package commands:

https://github.com/Elelabs/pyspinel/blob/elelabs/elelabs/README.md

https://github.com/Elelabs/pyspinel/tree/elelabs/elelabs#btl

https://github.com/Elelabs/pyspinel/tree/elelabs/elelabs#data

https://github.com/Elelabs/pyspinel/tree/elelabs/elelabs#help

I guess that "MFG_LAUNCH_BOOTLOADER" command to could maybe be ported first as command to enter Silabs bootloader?

https://github.com/Elelabs/pyspinel/tree/elelabs/elelabs#elelabs-thread-spinel-commands

"Launch Bootloader NCP command. Causes the NCP to perform a software reset and enter XMODEM bootloader mode"

$ cd <path-to-pyspinel>
$ spinel-cli.py -u /dev/ttyS1 -b 115200 --vendor-path=elelabs
spinel-cli > version
SL-OPENTHREAD/1.1.2.0_GitHub-5c2ad91cf; EFR32; Jun 16 2021 22:54:45
Done
spinel-cli > vendor data
Elelabs
Done
ELU013
Done
spinel-cli > vendor btl
spinel-cli > exit
@Hedda Hedda changed the title Worth taking a look at pyspinel as a reference? Worth taking a look at pyspinel CLI as a reference? Nov 15, 2021
@puddly
Copy link
Contributor

puddly commented Nov 29, 2021

Thanks, that is an interesting project.

I was eventually planning on trying to add a similar shell using IPython for sending commands interactively (since it has autocompletion and is async-friendly).

Preliminary work has begun on merging bellows and zigpy-znp's respective command line tools into zigpy-cli:

  • Cross-radio backup/restore (currently working with ZNP and Conbee): Implement new radio API #2
  • Bellows is a bit more complicated so I'm saving it for last, once the network state structures are finalized and iterated a few more times (New radio API zigpy#848).
  • Energy scanning already works with ZNP and the Conbee using the same code, the zigpy-znp command line tool just needs to be transplanted into zigpy-cli.

I guess that "MFG_LAUNCH_BOOTLOADER" command to could maybe be ported first as command to enter Silabs bootloader?

Bootloader commands are low on the priority list, since that code is often pretty complex and uses internal radio library code. A plugin system could work, but since the existing bootloader tools are synchronous, it'd take either a complete rewrite to work with zigpy-cli, or the tools would essentially be run externally in a separate thread, which is no easier than directly running the original tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants