pynxt2ors
0 forks
A python service to connect different Lego robots (NXT, EV3, Spike) with OpenRobertaServer
id: 84
3,471 Lines
  • Python 79.7%
  • Shell 9.9%
  • Markdown 5.8%
  • Java 4.7%
README.md

pynxt2ors 0.9.2

64-bit Open-Roberta connector for LEGO NXT, EV3 and SPIKE.

GUI

Start with pynxt2ors --minimized to run in the system tray, also combinable with --server URL. Minimizing the main window also hides it in the tray. Click the icon (or choose Hauptfenster öffnen in its menu) to restore the window. The menu's Beenden action closes the connector and releases the robot.

The tray icon is yellow when the robot is connected but Open Roberta is still waiting or reconnecting, green when both are connected, gray without a robot, and red on errors. Its tooltip includes the current server and status. Connection changes produce desktop notifications while running in the tray. Notifications depend on the desktop's notification settings. Without system tray support, the window minimizes normally and remains accessible in the taskbar.

The normal GUI deliberately has no robot selector and no Connect button. Supported connector hardware is detected automatically. Exactly one connector-driven robot may be attached at a time. Open Roberta Lab öffnen stays disabled until exactly one supported robot has been detected and its Open-Roberta loadSystem is known.

Without --server, the GUI offers these server choices:

  • private/patched Lab: https://cora.corvi.schule (default)
  • official Lab: https://lab.open-roberta.org

The official server is shown on the left, the custom server address on the right. The custom address remains editable regardless of the selected server. Pending edits are highlighted in amber and applied by clicking Eigener Server, including when that option is already selected. Changing servers asks for confirmation, ends the previous server session, and automatically registers with the selected server. Editing alone leaves the active connection and browser destination unchanged. The robot transport stays open during server changes and registration retries, avoiding repeated USB initialization. Exiting the application releases the robot.

Unplugging a robot reports the interruption without a blocking dialog. The connector releases the old transport, keeps searching, and automatically registers the robot again after reconnection. Presence is also checked during server long polls. If a program is still running on the reconnected robot, the connector waits for it to finish before registering. A fresh pairing token may be required in the Lab if the server has already expired the previous session. For the same robot (identified by its hardware address), a still-valid pairing is reused automatically. An interrupted download is not resumed automatically.

With --server URL, the server is fixed for that instance: there is no server selector or editable address. Saved server settings do not override this argument.

Only one GUI instance per user can run, shared across the standard entry and all fixed-server starters. Starting another variant asks whether to close the running connector. On confirmation, it closes normally and releases the robot before the new variant starts. Declining leaves the running connector unchanged. If shutdown does not finish, the new connector does not start alongside it.

For the private Lab the connector token is added automatically to the deep link. For the official Lab only loadSystem=... is used; pairing remains the official Open-Roberta workflow.

Automatic local connector detection currently covers NXT, EV3/leJOS and SPIKE with LEGO firmware. EV3dev and SPIKE/Pybricks use Open-Roberta-side transports and can be selected as advanced CLI modes.

EV3 supports standard leJOS 0.9.1 beta through its built-in remote menu protocol on TCP port 8002. If the Open-Roberta HTTP menu is installed, that protocol remains supported as well. Detection selects the available protocol automatically. No SSH login, Java installation on the PC, or additional menu installation on the EV3 is required.

For the standard menu, the connector automatically downloads the runtime, JSON and WebSocket libraries from the selected ORS and bundles them with each program. It reads the OR-menu package only for the adapter's protocol version; it never installs that menu on the brick. ORS update requests refresh these adapter libraries, leaving the SD card firmware and standard menu intact. Programs are saved as ORS_<name>.jar in /home/lejos/programs, started through the native menu, and can also be selected again in the EV3 Files menu. Each newly transferred program includes a small Java 7 entry point with a process lease. The connector checks that lease through the native file protocol instead of trusting the menu's stale last-program name. Normal exit, System.exit, and a forced stop release the lease automatically; the connector then reports the program as finished and resumes waiting for ORS commands. No background helper is started. Programs transferred before 0.9.1 need to be transferred once again to include this entry point. A new download replaces any previous menu process. From 0.9.2, all process records are stored in programs/.pynxt2ors/. Normal JVM shutdown deletes the active .run record and retains one .state receipt per program in that folder, so even programs ending between polls are detected. After a forced kill, the connector performs the same cleanup when it observes the closed descriptor. Starting a program transferred with 0.9.2 also removes inactive legacy .pynxt2ors-*.run records from the main programs directory. Previously stored programs need to be transferred again for the new layout. Acknowledgement uses the native, finite system beep. Closing the connector releases its menu socket; no robot-side helper process is left running.

Install

sudo ./install.sh user
# or
sudo ./install.sh linuxmuster

Installation and updates also set up EV3/leJOS USB networking on Linux with an active NetworkManager and systemd. A udev rule selects CDC Ethernet for the 0525:a4a2 gadget with the leJOS musb_hdrc controller descriptor. On attachment, a system service creates and activates a dedicated NetworkManager profile bound to that interface's MAC address: PC 10.0.1.2/24, EV3 10.0.1.1, without a default gateway or DNS override. Reconnecting requires no terminal commands. In addition to the hotplug service, a system timer checks every ten seconds whether the attached EV3 has its address and direct USB route. Missing configuration is reactivated automatically; an already configured connection is left untouched. Existing network profiles are preserved. Only one EV3 on this subnet is supported at a time. The standard leJOS menu or the Open-Roberta menu must be running.

For an existing installation, run sudo ./install.sh --update user (or --update linuxmuster) once, then reconnect the EV3. The app reports a detected EV3 whose network/service is not ready; pynxt2ors --doctor checks the installed network setup. Uninstallation removes the managed profiles, helper and rules.

The standard menu entry starts the connector with server selection. After installing, manage any number of additional menu entries with fixed servers using --starter:

sudo ./install.sh --starter add schule https://cora.corvi.schule "Open Roberta – Schule"
sudo ./install.sh --starter add online https://lab.open-roberta.org "Open Roberta – Online"
sudo ./install.sh --starter list
sudo ./install.sh --starter remove schule
sudo ./install.sh --starter remove --all

The identifier is unique and may contain letters, digits, _ and -. Adding the same identifier again updates its server and menu text. Removing additional starters preserves the standard entry and the installation. Updates preserve additional starters; sudo ./install.sh --uninstall removes the installation and all its starters. The installed script is also available at /opt/pynxt2ors/app/install.sh.

CLI / simulations

pynxt2ors --debug
pynxt2ors --server https://cora.corvi.schule
pynxt2ors --server https://lab.open-roberta.org
pynxt2ors --doctor
pynxt2ors --fake-nxt
pynxt2ors --fake-ev3 --firmware lejos
pynxt2ors --fake-ev3 --firmware ev3dev
pynxt2ors --fake-spike --firmware lego
pynxt2ors --fake-spike --firmware pybricks
pynxt2ors --system ev3dev
pynxt2ors --system spikePybricks
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover