Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
2025-11-03 09:48:23 +09:00
parent 16a87c0f40
commit 1f06c677c6
18 changed files with 0 additions and 502 deletions

View File

@@ -1,283 +0,0 @@
# ODROID Remote API Documentation
This document outlines the HTTP REST and WebSocket APIs for communication between the web interface and the ESP32 device.
---
## WebSocket API
The WebSocket API provides a full-duplex communication channel for real-time data, such as sensor metrics and the
interactive serial console. All server-to-client communication is done via binary WebSocket frames containing Protocol
Buffers (protobuf) messages.
**Endpoint**: `/ws`
### Server-to-Client Messages
The server pushes binary messages to the client. Each message is a Protocol Buffers (protobuf) encoded `StatusMessage`.
This top-level message uses a `oneof` field to carry different payload types.
The protobuf schema is defined in `proto/status.proto`.
```proto
// Top-level message for all websocket communication
message StatusMessage {
oneof payload {
SensorData sensor_data = 1;
WifiStatus wifi_status = 2;
UartData uart_data = 3;
}
}
```
The client decodes the `StatusMessage` and then handles the specific payload:
| `oneof` payload field | Contained Message | Description |
|-----------------------|-------------------|-----------------------------------------------------------------------------------------|
| `sensor_data` | `SensorData` | Pushed periodically (e.g., every second) with the latest power metrics. |
| `wifi_status` | `WifiStatus` | Pushed periodically or on change to update the current Wi-Fi connection status. |
| `uart_data` | `UartData` | Forwards raw binary data from the ODROID's serial (UART) port to the client's terminal. |
### Client-to-Server Messages
The client sends raw binary/text data, which is interpreted as terminal input.
- **Description**: Raw binary data representing user input from the web terminal. This data is forwarded directly to the ODROID's serial (UART) port.
- **Payload**: `(raw data)`
---
## HTTP REST API
The REST API is used for configuration and to trigger specific actions. All request and response bodies are in `application/json` format.
### Endpoint: `/api/control`
Manages power relays and system actions.
#### `GET /api/control`
Retrieves the current status of the power relays.
- **Success Response (200 OK)**
```json
{
"load_12v_on": true,
"load_5v_on": false
}
```
- `load_12v_on` (boolean): The state of the main 12V power relay.
- `load_5v_on` (boolean): The state of the 5V USB power relay.
#### `POST /api/control`
Sets the state of power relays or triggers a power action. You can send one or more commands in a single request.
- **Request Body Examples**:
- To turn the main power on:
```json
{ "load_12v_on": true }
```
- To trigger a system reset:
```json
{ "reset_trigger": true }
```
- To toggle the power button:
```json
{ "power_trigger": true }
```
- **Request Fields**:
- `load_12v_on` (boolean, optional): Sets the state of the 12V relay.
- `load_5v_on` (boolean, optional): Sets the state of the 5V relay.
- `reset_trigger` (boolean, optional): If `true`, momentarily triggers the reset button (pulls the line low for 3 seconds). The action is triggered only on a `true` value.
- `power_trigger` (boolean, optional): If `true`, momentarily triggers the power button (pulls the line low for 3 seconds). The action is triggered only on a `true` value.
- **Success Response (200 OK)**: `{"status":"ok"}`
---
### Endpoint: `/api/setting`
Manages all Wi-Fi, network, and system-related configurations.
#### `GET /api/setting`
Retrieves the complete current network and system configuration.
- **Success Response (200 OK)**
```json
{
"connected": true,
"ssid": "MyHome_WiFi",
"rssi": -65,
"mode": "apsta",
"net_type": "static",
"baudrate": "115200",
"vin_current_limit": 8.0,
"main_current_limit": 7.0,
"usb_current_limit": 5.0,
"ip": {
"ip": "192.168.1.100",
"gateway": "192.168.1.1",
"subnet": "255.255.255.0",
"dns1": "8.8.8.8",
"dns2": "8.8.4.4"
}
}
```
- **Response Fields**:
- `connected` (boolean): Current Wi-Fi connection state.
- `ssid` (string): The SSID of the connected network.
- `rssi` (integer): The Received Signal Strength Indicator in dBm. Only present if connected.
- `mode` (string): The current Wi-Fi mode (`"sta"` or `"apsta"`).
- `net_type` (string): The network type (`"dhcp"` or `"static"`).
- `baudrate` (string): The current UART baud rate.
- `vin_current_limit` (number): The current limit for VIN in Amps. `0` means disabled.
- `main_current_limit` (number): The current limit for the Main channel in Amps. `0` means disabled.
- `usb_current_limit` (number): The current limit for the USB channel in Amps. `0` means disabled.
- `ip` (object): Contains IP configuration details. Present even if using DHCP (may show the last-leased IP).
- `ip` (string): The device's IP address.
- `gateway` (string): The network gateway address.
- `subnet` (string): The network subnet mask.
- `dns1` (string): The primary DNS server address.
- `dns2` (string): The secondary DNS server address.
#### `POST /api/setting`
This is a multi-purpose endpoint. The server determines the action based on the fields provided in the request body.
- **Action: Connect to a Wi-Fi Network**
- **Request Body**:
```json
{
"ssid": "MyHome_WiFi",
"password": "my_secret_password"
}
```
- **Success Response (200 OK)**:
```json
{ "status": "connection_initiated" }
```
- **Action: Configure Network Type (DHCP/Static)**
- **Request Body (for DHCP)**:
```json
{ "net_type": "dhcp" }
```
- **Request Body (for Static IP)**:
```json
{
"net_type": "static",
"ip": "192.168.1.100",
"gateway": "192.168.1.1",
"subnet": "255.255.255.0",
"dns1": "8.8.8.8",
"dns2": "8.8.4.4"
}
```
- **Success Response (200 OK)**:
- `{"status":"dhcp_config_applied"}`
- `{"status":"static_config_applied"}`
- **Action: Configure Wi-Fi Mode (STA/APSTA)**
- **Request Body (for STA mode)**:
```json
{ "mode": "sta" }
```
- **Request Body (for AP+STA mode)**:
```json
{
"mode": "apsta",
"ap_ssid": "ODROID-Remote-AP",
"ap_password": "hardkernel"
}
```
*Note: `ap_password` is optional. If omitted, the AP will be open.*
- **Success Response (200 OK)**: `{"status":"mode_switch_initiated"}`
- **Action: Configure UART Baud Rate**
- **Request Body**:
```json
{ "baudrate": "115200" }
```
- **Success Response (200 OK)**:
```json
{ "status": "baudrate_updated" }
```
- **Action: Configure Current Limits**
- **Request Body**:
*Note: You can set one or more limits in a single request. A value of `-1.0` disables the limit.*
```json
{
"vin_current_limit": 7.5,
"main_current_limit": 6.0,
"usb_current_limit": -1.0
}
```
- **Success Response (200 OK)**: `{"status":"current_limit_updated"}`
---
### Endpoint: `/api/wifi/scan`
Scans for available Wi-Fi networks.
#### `GET /api/wifi/scan`
- **Success Response (200 OK)**: Returns a JSON array of found networks.
```json
[
{
"ssid": "MyHome_WiFi",
"rssi": -55,
"authmode": "WPA2_PSK"
},
{
"ssid": "GuestNetwork",
"rssi": -78,
"authmode": "OPEN"
}
]
```
- **Response Fields**:
- `ssid` (string): The network's Service Set Identifier.
- `rssi` (integer): Signal strength in dBm.
- `authmode` (string): The authentication mode (e.g., `"OPEN"`, `"WPA_PSK"`, `"WPA2_PSK"`).
---
### Endpoint: `/datalog.csv`
Provides access to the historical sensor data log.
#### `GET /datalog.csv`
- **Description**: Downloads a CSV file containing the history of sensor data readings (voltage, current, power). The log is rotated when it reaches its maximum size (1MB).
- **Success Response (200 OK)**: The body of the response is the CSV file content.
- **Response Headers**:
- `Content-Type: text/csv`
- `Content-Disposition: attachment; filename="datalog.csv"`
- **CSV Format**:
```csv
timestamp,voltage,current,power
1672531200,12.01,1.52,18.25
1672531201,12.02,1.53,18.39
...
```
---
### General Error Responses
In case of an error, the server will respond with an appropriate HTTP status code.
- **`400 Bad Request`**: The request is malformed, contains invalid parameters, or is otherwise incorrect. The response body may contain a JSON object with more details.
```json
{
"error": "Invalid request body"
}
```
- **`404 Not Found`**: The requested endpoint does not exist.
- **`500 Internal Server Error`**: The server encountered an unexpected condition that prevented it from fulfilling the request.

View File

@@ -1,66 +0,0 @@
# Custom firmware
If you want, you can create your own custom firmware.
## Install Tools
To build the source code, you need the following packages on Ubuntu 24.04.
```bash
sudo apt install nodejs npm nanopb
```
You need `esp-idf` version 5.4. It might be possible to build with the latest version, but it has not been confirmed.
First, install the necessary tools for esp-idf.
```bash
sudo apt install git wget flex bison gperf python3 python3-pip python3-venv \
cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 \
```
Next, clone the esp-idf tool.
```bash
mkdir -p ~/esp
cd ~/esp
git clone -b release/v5.4 --recursive https://github.com/espressif/esp-idf.git
```
You need to install tools such as a compiler and a debugger.
```bash
cd ~/esp/esp-idf
./install.sh esp32c3
```
Please prepare to build the source by running the shell for using esp-idf.
```bash
. $HOME/esp/esp-idf/export.sh
```
## Build custom firmware based on PowerMate
First, clone the PowerMate source code.
```bash
git clone https://github.com/shinys000114/odroid-powermate.git
```
After connecting the USB Type-C cable to the PowerMate and the host PC, run the command below to build and update PowerMate.
```bash
cd odroid-powermate
idf.py app flash monitor
```
## Create a new project
Create a project with the command below and create your own firmware.
```bash
idf.py create-project proj
cd proj
idf.py set-target esp32c3
```
For a more detailed guide, please refer to the link below.
[https://docs.espressif.com/projects/esp-idf/en/release-v5.4/esp32/get-started/linux-macos-setup.html#](https://docs.espressif.com/projects/esp-idf/en/release-v5.4/esp32/get-started/linux-macos-setup.html#)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 454 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 447 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 498 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 207 KiB

View File

@@ -1,52 +0,0 @@
# Connector and Pin Header Description
## J1 USB-C Connector
This terminal is for uploading firmware and checking program logs.
It is recognized as a serial device and as a `ttyACM` device in Linux.
To view the logs, you can use the command below.
```bash
minicom -D /dev/ttyACM0 -b 115200
```
## J2 UART Pin header
Connected to the `U0RXD`, `U0TXD` system UART of the ESP32-C3. Currently not used on this board.
It can be used as GPIO through appropriate configuration in esp-idf.
## J3 ODROID UART Connector
Connects to the UART debug port of the ODROID.
This connector is `X8821WRS-04`. you can use the [cable from the USB-UART 2 board](https://www.hardkernel.com/shop/usb-uart-2-module-kit-copy/).
## J4 GPIO Output
4 GPIO output pin headers. Used to trigger the power of external devices.
| Pin Number | Function | Function | Pin Number |
|------------|--------------------|--------------------|------------|
| 3 | Reserved | Reserved | 1 |
| 4 | Reset (Open Drain) | Power (Open Drain) | 2 |
The Reset and Power pins can be used on the ODROID-M series and H series.
## J5 DC Input
Supports 9~21v input. You can use the DC power supply sold by Hardkernel.
## J6 DC Out
Outputs the switched power from the J5 input.
## J7 USB Power Out
Switched 5v voltage output.
The output is set to 5.25V considering voltage drop. Please use with caution.
## J8 OLED Display Connector
**Reserved**
SSD1309 OLED Connector
It cannot be used as GPIO for other purposes because it shares the I2C bus with `PCA9557PW`, `INA3221`.

Binary file not shown.

View File

@@ -1,77 +0,0 @@
# Settings
> **Warning**
> Wi-Fi and IP related settings will restart the Wi-Fi service.
> After applying the settings, you may need to reconnect to the page.
>
> Please be careful when applying settings. Incorrect settings may prevent you from connecting to the device.
> If you have problems with the device settings, connect the debug USB-C connector to check the device's logs.
> If necessary, you can re-update the firmware to initialize the device.
## Connect to Wi-Fi
The device boots in APSTA mode by default and services the following AP.
- SSID: powermate
- Password: hardkernel
After connecting to the above AP using a smartphone, etc., you can configure the device by accessing the
`http://192.168.4.1` address.
> **Warning**
> A warning that the AP does not have internet may appear. Please press `Allow connection` to connect to the device.
You can open the settings window by pressing the gear button at the top.
Press the Scan button to see a list of nearby APs.
<img src="img/1000030234.jpg" width="300">
After entering the password, press the Connect button and PowerMate will attempt to connect to the AP.
For public APs, leave the Password blank.
<img src="img/1000030235.jpg" width="300">
<img src="img/1000030236.jpg" width="300">
When Wi-Fi is connected, the green SSID name appears at the top of the page.
<img src="img/1000030237.jpg" width="300">
## Set static ip
You can assign the IP of the device yourself.
You can set the IP directly by turning on the `Use Static IP` toggle in the `Network` tab.
![static.png](img/static.png)
## AP Mode
Configure the AP function of PowerMate.
If you do not need the AP service, it is recommended to disable it.
![apmode.png](img/apmode.png)
## Current Limit
Monitors the current of PowerMate, and if a value higher than the set current is detected, all load switches are turned
off.
![current.png](img/current.png)
## Device
Sets the UART Baudrate. Please match it with the baudrate of the connected ODROID.
| ODROID | Baud rate |
|------------------|----------------------------|
| ODROID-C4 | 115200 |
| ODROID-C5 | 921600 |
| ODROID-M1/M1S/M2 | 1500000 |
| ODROID-H3/4 | According to user settings |
You can reboot the PowerMate. The state of the load switch does not change due to rebooting.
![device.png](img/device.png)

View File

@@ -1,24 +0,0 @@
# UART Terminal
> **Warning**
> Data drop may occur depending on the communication quality.
![uart.png](img/uart.png)
You can see the UART terminal in the Device tab.
You can specify the baud rate in `Setting > Device`, and the supported baud rates are 9600-1500000.
![device.png](img/device.png)
## ANSI Color
Supports the color table of the terminal.
```bash
odroid@server:~$ TERM=xterm-256color /bin/bash
```
![color.png](img/color.png)
![htop.png](img/htop.png)