Skip to main content

Client-server package to remotely control a Raspberrypi Pi Pico W.

Project description

https://img.shields.io/pypi/v/piconetcontrol.svg https://img.shields.io/github/license/matthiaszeller/piconetcontrol.svg

Client-server package to remotely control a Raspberrypi Pico W.

About

This package provides a client-server architecture to remotely control a Raspberry Pi Pico W. The server runs on the Pico W and the client on a computer. For testing/debugging purpose, the server can also run on e.g. a Raspberrypi 4, with limited functionality.

The goal is to handle logic on the client side, while the server is responsible for direct hardware interaction. This enables using more powerful hardware for orchestration with greater functionalities, as the server is executed with MicroPython on the Pico W.

Fail-Safe Mechanism

To handle scneraii where client-server connection is disrupted after an actuator has been activated, changing a pin state (write_pin command), requires a timeout to be specified. After the timeout, the server will revert the pin state to its previous value. Initial pin state must be set upon pin setup (setup_pin command).

Installation

Installation on PicoW

Copy Code

Connect the Pico to your computer via the USB cable. Use e.g. Thonny IDE to copy the following files (under piconetcontrol/server) at the root of Pico filesystem:

  • main.py

  • server_base.py

  • server_pico.py

Subsequent updates can be done via the client-server communication protocol (Client.update_server()).

Configuration files
  1. Create a config/config_wlan.json with fields ssid and password for the WiFi connection.

  2. Generate the certificate and copy it under config/ec_cert.der and config/ec_key.pem:

openssl ecparam -genkey -name prime256v1 -out ec_key.pem
openssl ec -in ec_key.pem -outform DER -out ec_key.der
openssl req -new -key ec_key.pem -out ec_csr.pem
openssl x509 -in ec_cert.pem -outform DER -out ec_cert.der
Run Server

Run main.py from Thonny, or disconnect it and reconnect to a power source (main.py is executed on boot).

Server Blinking Patterns

The Pico W board is equipped with an LED that can be used to indicate the status of the server.

Status

Pattern

Connecting to WiFi

3 blinks of 100ms, 200ms apart, then 1s pause

Server Listening (Idling)

Infinite blinks of 1.5s on, 1.5s off

Ongoing Connection

Continuous 20ms blinks, 100ms apart

If the board isn’t blinking:

  • Server might not be running

  • Board might be in light or deep sleep mode

    • If in light sleep, the server wakes up upon receiving a command

Client-Server Communication Protocol

The server and the Raspberry Pi Pico W (client) communicate over a TCP/IP connection. Message exchange occurs via JSON-encoded dictionaries.

Commands

GPIO Control

Setup pin

Instructs client to configure a GPIO pin as input or output, optionally set its value.

Command structure:

{
    "action": "setup_pin",
    "pin": "<pin_number>",
    "mode": "<'input'|'output'>",
    "value": "<0|1> [optional]"
}

Success Response: Client echoes back the command.

Set pin value

Instructs client to set a specified GPIO pin to specified value (high or low) during some specified time.

Command structure:

{
    "action": "write_pin",
    "pin": "<pin_number>",
    "value": "<0|1>",
    "timeout": "<duration_in_seconds>"
}

Success Response: Client echoes back the command (does not wait for timeout).

Read pin value

Requests the current value (high or low) of a specified GPIO pin.

Command structure:

{
    "action": "read_pin",
    "pin": "<pin_number>"
}

Success Response: Client echoes back the command and adds the value field (high/low).

Board Management

Reset board

Instructs client to reset the board, using the machine.reset() method.

Command structure:

{
    "action": "reset"
}

Success Response: Client echoes back the command.

Sleep for low power

Instructs client to enter a low-power state mode for a specified duration.

Command structure:

{
    "action": "sleep",
    "deep": "<0|1>",
    "time_ms": "<duration_in_ms>"
}

Success Response: Client echoes back the command.

Get resource info

Requests information about the client’s resources (e.g., memory, CPU).

Command structure:

{
    "action": "get_resource_info"
}

Success Response: Client echoes back the command and adds the info field.

Get server version

Requests the version of the server software.

Command structure:

{
    "action": "get_version"
}

Success Response: Client echoes back the command and adds the version field.

List actions

Requests a list of available actions supported by the client.

Command structure:

{
    "action": "list_actions"
}

Success Response: Client echoes back the command and adds the actions field.

Update server software

Instructs the client to update the server software.

Command structure:

{
    "action": "update"
}

The client will update the server software and restart the server. In case of failure after restart, the server will revert to the previous version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

piconetcontrol-0.2.2.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

piconetcontrol-0.2.2-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file piconetcontrol-0.2.2.tar.gz.

File metadata

  • Download URL: piconetcontrol-0.2.2.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for piconetcontrol-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ec53d334b14d6e3eded9dff5602af0c5adfa6db94dab2d887c7aa39f7d4f6b6a
MD5 2485d9b6d59da4e0e82d1d00dc2d8b36
BLAKE2b-256 b15c22a17caef5c5037d923231fab24310524c89f6a69efa20380dd2ce2d0444

See more details on using hashes here.

File details

Details for the file piconetcontrol-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: piconetcontrol-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for piconetcontrol-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5e3ae606ef59e1f2e3aca82d88f15fac23071b20bd2126a5950661dff1035779
MD5 6947f2e3f3964fa8c8e548f07f6bb503
BLAKE2b-256 c814a1fa4fa6b4a180913dd6a56d4cd59d4d6294389ce2d2808dffd8a74e1f53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page