Metadata-Version: 2.1
Name: wpilib-ws-py
Version: 0.2.0
Summary: An implementation of the WPILib WebSocket protocol for Python
Home-page: https://github.com/AM2i9/wpilib-ws-py
License: MIT
Keywords: wpilib,websocket
Author: Patrick Brennan (AM2i9)
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: websockets (>=10.0,<11.0)
Project-URL: Repository, https://github.com/AM2i9/wpilib-ws-py
Description-Content-Type: text/markdown

# wpilib-ws-py
## An implementation of the WPILib WebSocket protocol for Python3

This library is an implementation of the WPILib simulation WebSocket, used for controlling non-frc hardware using WPILib. The specification of this protocol is found [here](https://github.com/wpilibsuite/allwpilib/blob/main/simulation/halsim_ws_core/doc/hardware_ws_api.md).

[Example Sever Usage](tests/examples/demo_server.py)

```py
from wpilib_ws import WPILibWsServer

server = WPILibWsServer()

# The on_message decorator will let you create handlers for message events.
# Optionally a device type can be entered to only handle messages for that
# specific device type. A list of device types and other hardware messages can
# be found here:
# https://github.com/wpilibsuite/allwpilib/blob/main/simulation/halsim_ws_core/doc/hardware_ws_api.md#hardware-messages


@server.on_message("PWM")
async def pwm_handler(event):
    payload = event.payload
    print(f"Recieved PWM event: {payload}")
    # ...


@server.on_message("CANMotor")
async def can_motor_handler(event):
    payload = event.payload
    print(f"Recieved CANMotor event: {payload}")
    # ...


# The while_connected decorator is a loop that runs alongside the server, and
# can be used for periodic tasks, such as sending battery voltage, like below.

@server.while_connected(buffer=0)
async def while_connected():
    await server.send_payload(
        {"type": "RoboRIO", "device": "", "data": {">vin_voltage": 12.0}}
    )


server.run()
```
