codde-protocol 0.1.6
Multi Communication protocol in heart of the C.O.D.D.E. Pi framework
Requires Python: >=3.8
Keywords: rust, python, codde_pi, iot

# CODDE Protocol

[![Build & Test](https://github.com/codde-pi/codde_protocol/actions/workflows/build.yml/badge.svg)](https://github.com/codde-pi/codde_protocol/actions/workflows/build.yml)
[![crates.io](https://img.shields.io/crates/v/codde_protocol?logo=rust)](https://crates.io/crates/codde_protocol)
[![pub.dev](https://img.shields.io/pub/v/codde_protocol.svg?include_prereleases&color=blue)](https://pub.dev/packages/codde_protocol)
[![pypi.org](https://img.shields.io/pypi/v/codde_protocol.svg?logo=python&style=flat-square)](https://pypi.org/project/codde_protocol)

CODDE Protocol is the base layer of the CODDE Pi Framework. This protocol let CODDE Pi interacts with any hardware through WiFi, Bluetooth and BLE using an embedded library and a mobile app. This technology enables users to freely interact with hardware thanks to a secure, stable and reliable technology without be (too) intrusive.

<a href="https://www.buymeacoffee.com/wddm" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>

## Development

This Project is written in Rust, enabling fast serializing/deserializing and data processing.
Client side is ported for Dart/Flutter applications, and server side has been translated in python.

CODDE Protocol integrates data generated by CODDE Pi App widgets, and received by embedded systems. See https://codde-pi.com to stay tuned about new widgets integration.

## How it works

CODDE Pi is based on client-server architecture. Basically, the mobile App you download is the client side, and the base layer you embed on your project is the server side

![Widgets & CODDE Protocol](./assets/codde_pi_widget.drawio.svg)

## Usage

```python
import codde_protocol
import time
# import gpio

# instantiate server
server = CoddePiServer.use_socket('localhost:12345')

# some hardware control
# pin10 = gpio.DigitalPin(10, gpio.OUTPUT)

@event(server)
def toggle_button_1(*args):
    widget: ToggleButton = args[0]
    print("value received : ", widget.value)
    server.callback(1, ServerStatus.Idle, ConfirmResult(True))

@event(server)
def click_button_2(*args):
    pass
    # pin10.on()

if __name__ == "__main__":
    print('opening server...', end=' ')
    server.open()
    try:
    print('serve')
        server.serve()
        while True:
            sleep(1)
    except KeyboardInterrupt:
        print("CTRL + C.")
        print("Program interrupted.")
    finally:
        server.close()
```

## Roadmap

### Libraries

| Protocols          | Flutter                               | Python                                | Rust                                   | MicroPython                            |
| ------------------ | ------------------------------------- | ------------------------------------- | -------------------------------------- | -------------------------------------- |
| WebSocket (client) | <span style="color: green">Yes</span> |                                       | <span style="color: green">Yes</span>  |                                        |
| WebSocket (server) |                                       | <span style="color: green">Yes</span> | <span style="color: green">Yes</span>  | <span style="color: yellow">WIP</span> |
| Bluetooth          |                                       |                                       | <span style="color: yellow">WIP</span> |                                        |
| USB                |                                       |                                       |                                        |                                        |
| Nearby             |                                       |                                       |                                        |                                        |

### Hardware compatibility

| Protocols          | SBC (arm64)                           | RP2040                                 | Android                               | iOS                                   | x86                                   |
| ------------------ | ------------------------------------- | -------------------------------------- | ------------------------------------- | ------------------------------------- | ------------------------------------- |
| WebSocket (client) | <span style="color: green">Yes</span> | <span style="color: yellow">WIP</span> | <span style="color: green">Yes</span> | <span style="color: green">Yes</span> | <span style="color: green">Yes</span> |
| WebSocket (server) | <span style="color: green">Yes</span> | <span style="color: yellow">WIP</span> | <span style="color: green">Yes</span> | <span style="color: green">Yes</span> | <span style="color: green">Yes</span> |
| Bluetooth          |                                       |                                        |                                       |                                       |                                       |
| USB                |                                       |                                        |                                       | <span style="color: red">No</span>    |                                       |
| Nearby             |                                       |                                        |                                       |                                       |                                       |