""" thingsbyjosh.com Advanced example: full configuration, telemetry callbacks, timeout handling, and a broadcast command -- over either USB serial or WiFi, your choice (see below). See python_example.py for the minimal connect/move/read version. WiFi requires the node already configured via the Web GUI's "Configure WiFi" dialog (over USB, one time) -- this script then only talks to the control WebSocket on port 81 once that node has joined your network; it can't provision credentials itself (WIFI_SET is USB-serial-only by design, see CAN Protocol.md). Any command sent to a node over WiFi is relayed onto the CAN bus exactly like a USB command would be, so every other node on the bus is reachable too, not just the one that's actually on WiFi. Note that when using the USB serial connection, the node will reset when the serial connection is lost (when the code ends). Install: pip install canbus-stepper """ import struct import time from canbus_stepper import CANBus, MsgType if __name__ == "__main__": # -- Choose how to connect: comment out the line you're NOT using ------- with CANBus.serial("COM4") as bus: # USB serial: adjust to your COM port (Device Manager) # with CANBus.websocket("canbus-stepper-1.local") as bus: # WiFi: adjust to your node's hostname or IP node1 = bus.node(1) # Register a callback for continuous angle telemetry from node 1 def on_angle(node_id, msg_type, payload): angle = struct.unpack("