Skip to content

PoE / Ethernet Network API ​

Overview ​

This document describes the RESTful APIs for PoE/Ethernet network management, for frontend development reference.

Base path: /api/v1/system/network/poe

Authentication: all endpoints require authentication (require_auth: true)

Content-Type: application/json


Unified Response Format ​

Success response ​

json
{
  "success": true,
  "message": "Operation success message",
  "data": {
    // actual business data
  }
}

Failure response ​

json
{
  "success": false,
  "error_code": "ERROR_CODE_STRING",
  "message": "Error description"
}

Response fields ​

FieldTypeRequiredDescription
successbooleanyeswhether the operation succeeded
error_codestringnoerror code string (present only on failure)
messagestringnoresult message (optional)
dataobjectnobusiness data (present only on success)

Error codes (error_code) ​

Error codeValueDescription
INVALID_REQUEST400invalid request
UNAUTHORIZED401unauthorized
FORBIDDEN403forbidden
NOT_FOUND404not found
METHOD_NOT_ALLOWED405method not allowed
TIMEOUT408timeout
TOO_MANY_REQUESTS429too many requests
INTERNAL_ERROR500internal error
BAD_GATEWAY502bad gateway
SERVICE_UNAVAILABLE503service unavailable
GATEWAY_TIMEOUT504gateway timeout

PoE Status Codes ​

CodeNameDescription
0POE_STATUS_OFFLINEPoE offline / not powered
1POE_STATUS_LINK_DOWNEthernet cable not connected
2POE_STATUS_CONNECTINGconnecting (DHCP in progress)
3POE_STATUS_CONNECTEDconnected, valid IP
4POE_STATUS_DHCP_FAILEDfailed to obtain IP via DHCP
5POE_STATUS_STATIC_CONFIG_ERRORstatic IP configuration error
6POE_STATUS_IP_CONFLICTIP address conflict
7POE_STATUS_GATEWAY_UNREACHABLEgateway unreachable
8POE_STATUS_DNS_ERRORDNS resolution error
9POE_STATUS_ERRORgeneric error

1. Get PoE Status ​

Request ​

http
GET /api/v1/system/network/poe/status

Success response ​

json
{
  "success": true,
  "message": "PoE status retrieved successfully",
  "data": {
    "available": true,
    "status": "Connected",
    "ip_address": "192.168.60.100",
    "connected": true
  }
}

data fields ​

FieldTypeDescription
availablebooleanwhether the PoE/Ethernet module is available
statusstringconnection status: Unavailable, Disconnected, Connecting, Connected, Failed, Switching
ip_addressstringcurrent IP address (valid only when connected)
connectedbooleanwhether connected

Response when the module is unavailable ​

json
{
  "success": true,
  "message": "PoE status retrieved successfully",
  "data": {
    "available": false,
    "status": "unavailable",
    "message": "PoE/Ethernet module not available"
  }
}

2. Get PoE Detailed Information ​

Request ​

http
GET /api/v1/system/network/poe/info

Success response ​

json
{
  "success": true,
  "message": "PoE info retrieved successfully",
  "data": {
    "available": true,
    "network_status": "Connected",
    "status_code": 3,
    "status_message": "Connected",
    "ip_mode": "dhcp",
    "ip_address": "192.168.60.100",
    "netmask": "255.255.255.0",
    "gateway": "192.168.60.1",
    "dns_primary": "8.8.8.8",
    "dns_secondary": "223.5.5.5",
    "hostname": "aicam-poe",
    "mac_address": "00:11:22:33:44:55",
    "interface_name": "wn",
    "link_up": true,
    "poe_powered": true,
    "connection_duration_sec": 3600,
    "connection_start_time": 1703318400,
    "dhcp_lease_time": 86400,
    "dhcp_lease_remaining": 43200,
    "connect_count": 5,
    "disconnect_count": 2,
    "dhcp_fail_count": 0,
    "last_error_code": 0
  }
}

data fields ​

FieldTypeDescription
availablebooleanwhether the PoE module is available
network_statusstringnetwork status text
status_codenumberstatus code (see the PoE status code table)
status_messagestringmessage for the status code
ip_modestringIP mode: dhcp or static
ip_addressstringIPv4 address
netmaskstringsubnet mask
gatewaystringdefault gateway
dns_primarystringprimary DNS server
dns_secondarystringsecondary DNS server
hostnamestringhostname
mac_addressstringMAC address
interface_namestringnetwork interface name
link_upbooleanphysical link state
poe_poweredbooleanPoE power state
connection_duration_secnumberconnection duration (seconds)
connection_start_timenumberconnection start timestamp
dhcp_lease_timenumberDHCP lease time (seconds)
dhcp_lease_remainingnumberremaining DHCP lease time (seconds)
connect_countnumberconnection attempts
disconnect_countnumberdisconnections
dhcp_fail_countnumberDHCP failures
last_error_codenumberlast error code

3. Get PoE Configuration ​

Request ​

http
GET /api/v1/system/network/poe/config

Success response ​

json
{
  "success": true,
  "message": "PoE config operation completed",
  "data": {
    "ip_mode": "dhcp",
    "ip_address": "192.168.60.232",
    "netmask": "255.255.255.0",
    "gateway": "192.168.60.1",
    "dns_primary": "8.8.8.8",
    "dns_secondary": "223.5.5.5",
    "hostname": "aicam-poe",
    "dhcp_timeout_ms": 30000,
    "dhcp_retry_count": 3,
    "dhcp_retry_interval_ms": 5000,
    "power_recovery_delay_ms": 5000,
    "auto_reconnect": true,
    "persist_last_ip": true,
    "validate_gateway": true,
    "detect_ip_conflict": true
  }
}

data fields ​

FieldTypeDescription
ip_modestringIP mode: dhcp or static
ip_addressstringstatic IPv4 address
netmaskstringsubnet mask
gatewaystringdefault gateway
dns_primarystringprimary DNS server
dns_secondarystringsecondary DNS server
hostnamestringhostname
dhcp_timeout_msnumberDHCP timeout (ms)
dhcp_retry_countnumberDHCP retry count
dhcp_retry_interval_msnumberDHCP retry interval (ms)
power_recovery_delay_msnumberpower-on recovery delay (ms)
auto_reconnectbooleanauto-reconnect toggle
persist_last_ipbooleanpersist the last IP
validate_gatewaybooleanvalidate gateway reachability
detect_ip_conflictbooleandetect IP conflicts

4. Set PoE Configuration ​

Request ​

http
POST /api/v1/system/network/poe/config
Content-Type: application/json

Request body ​

json
{
  "ip_mode": "static",
  "ip_address": "192.168.60.200",
  "netmask": "255.255.255.0",
  "gateway": "192.168.60.1",
  "dns_primary": "8.8.8.8",
  "dns_secondary": "223.5.5.5",
  "hostname": "my-device",
  "dhcp_timeout_ms": 30000,
  "dhcp_retry_count": 3,
  "auto_reconnect": true,
  "validate_gateway": true,
  "detect_ip_conflict": true
}

Note: all fields are optional - send only the fields to change. Omitted fields keep their current values.

Request fields ​

FieldTypeRequiredDescription
ip_modestringnodhcp or static
ip_addressstringnostatic IPv4 address
netmaskstringnosubnet mask
gatewaystringnodefault gateway
dns_primarystringnoprimary DNS server
dns_secondarystringnosecondary DNS server
hostnamestringnohostname (max 31 chars)
dhcp_timeout_msnumbernoDHCP timeout (ms)
dhcp_retry_countnumbernoDHCP retry count
auto_reconnectbooleannoauto-reconnect toggle
validate_gatewaybooleannovalidate gateway reachability
detect_ip_conflictbooleannodetect IP conflicts

Success response ​

json
{
  "success": true,
  "message": "PoE config operation completed",
  "data": {
    "message": "PoE configuration updated successfully",
    "ip_mode": "static"
  }
}

5. Validate a Static IP Configuration ​

Request ​

http
POST /api/v1/system/network/poe/validate
Content-Type: application/json

Request body ​

json
{
  "ip_address": "192.168.60.200",
  "netmask": "255.255.255.0",
  "gateway": "192.168.60.1",
  "dns_primary": "8.8.8.8",
  "dns_secondary": "223.5.5.5",
  "hostname": "my-device",
  "check_gateway": true,
  "check_conflict": true
}

Request fields ​

FieldTypeRequiredDescription
ip_addressstringyesIPv4 address to validate
netmaskstringyessubnet mask
gatewaystringyesdefault gateway
dns_primarystringnoprimary DNS server
dns_secondarystringnosecondary DNS server
hostnamestringnohostname
check_gatewaybooleannowhether to check gateway reachability
check_conflictbooleannowhether to check for IP conflicts

Success response (validation passed) ​

json
{
  "success": true,
  "message": "PoE configuration validation completed",
  "data": {
    "valid": true,
    "errors": [],
    "warnings": [],
    "gateway_reachable": true,
    "ip_conflict": false
  }
}

Response when validation fails ​

json
{
  "success": true,
  "message": "PoE configuration validation completed",
  "data": {
    "valid": false,
    "errors": [
      "Invalid IP address format",
      "IP address conflict detected"
    ],
    "warnings": [
      "Gateway may not be reachable"
    ],
    "gateway_reachable": false,
    "ip_conflict": true
  }
}

data fields ​

FieldTypeDescription
validbooleanwhether the configuration is valid
errorsarraylist of error messages
warningsarraylist of warning messages
gateway_reachablebooleanwhether the gateway is reachable
ip_conflictbooleanwhether an IP conflict exists

6. Apply PoE Configuration ​

Applies the currently saved configuration and connects to the network.

Request ​

http
POST /api/v1/system/network/poe/apply

Success response ​

json
{
  "success": true,
  "message": "PoE configuration applied successfully",
  "data": {
    "success": true,
    "status": "Connected",
    "ip_mode": "dhcp"
  }
}

Failure response ​

json
{
  "success": false,
  "error_code": "INTERNAL_ERROR",
  "message": "Failed to apply PoE configuration"
}

data fields ​

FieldTypeDescription
successbooleanwhether the operation succeeded
statusstringcurrent network status
ip_modestringcurrent IP mode

7. Save PoE Configuration ​

Persists the current configuration to NVS; it is restored automatically after reboot.

Request ​

http
POST /api/v1/system/network/poe/save

Success response ​

json
{
  "success": true,
  "message": "PoE configuration saved successfully",
  "data": {
    "success": true
  }
}

Failure response ​

json
{
  "success": false,
  "error_code": "INTERNAL_ERROR",
  "message": "Failed to save PoE configuration"
}

8. Connect to the PoE Network ​

Request ​

http
POST /api/v1/system/network/poe/connect

Success response ​

json
{
  "success": true,
  "message": "PoE connection initiated",
  "data": {
    "success": true,
    "status": "Connecting"
  }
}

Failure response ​

json
{
  "success": false,
  "error_code": "INTERNAL_ERROR",
  "message": "Failed to connect PoE network"
}

9. Disconnect from the PoE Network ​

Request ​

http
POST /api/v1/system/network/poe/disconnect

Success response ​

json
{
  "success": true,
  "message": "PoE disconnected successfully",
  "data": {
    "success": true,
    "status": "Disconnected"
  }
}

Failure response ​

json
{
  "success": false,
  "error_code": "INTERNAL_ERROR",
  "message": "Failed to disconnect PoE network"
}

Common Error Responses ​

Service not running ​

json
{
  "success": false,
  "error_code": "SERVICE_UNAVAILABLE",
  "message": "Communication service is not running"
}

PoE module unavailable ​

json
{
  "success": false,
  "error_code": "SERVICE_UNAVAILABLE",
  "message": "PoE/Ethernet module not available"
}

Wrong request method ​

json
{
  "success": false,
  "error_code": "METHOD_NOT_ALLOWED",
  "message": "Only GET method is allowed"
}

Request body parse error ​

json
{
  "success": false,
  "error_code": "INVALID_REQUEST",
  "message": "Invalid JSON request body"
}

Frontend Integration Examples ​

TypeScript type definitions ​

typescript
// unified response type
interface ApiResponse<T = any> {
  success: boolean;
  error_code?: string;
  message?: string;
  data?: T;
}

// PoE status
interface PoeStatus {
  available: boolean;
  status: string;
  ip_address?: string;
  connected?: boolean;
  message?: string;
}

// PoE detailed information
interface PoeDetailInfo {
  available: boolean;
  network_status: string;
  status_code: number;
  status_message: string;
  ip_mode: 'dhcp' | 'static';
  ip_address: string;
  netmask: string;
  gateway: string;
  dns_primary: string;
  dns_secondary: string;
  hostname: string;
  mac_address: string;
  interface_name: string;
  link_up: boolean;
  poe_powered: boolean;
  connection_duration_sec: number;
  connection_start_time: number;
  dhcp_lease_time: number;
  dhcp_lease_remaining: number;
  connect_count: number;
  disconnect_count: number;
  dhcp_fail_count: number;
  last_error_code: number;
}

// PoE configuration
interface PoeConfig {
  ip_mode: 'dhcp' | 'static';
  ip_address: string;
  netmask: string;
  gateway: string;
  dns_primary: string;
  dns_secondary: string;
  hostname: string;
  dhcp_timeout_ms: number;
  dhcp_retry_count: number;
  dhcp_retry_interval_ms: number;
  power_recovery_delay_ms: number;
  auto_reconnect: boolean;
  persist_last_ip: boolean;
  validate_gateway: boolean;
  detect_ip_conflict: boolean;
}

// validation result
interface ValidationResult {
  valid: boolean;
  errors: string[];
  warnings: string[];
  gateway_reachable: boolean;
  ip_conflict: boolean;
}

Request wrapper ​

typescript
const API_BASE = '/api/v1/system/network/poe';

async function request<T>(
  endpoint: string,
  options: RequestInit = {}
): Promise<ApiResponse<T>> {
  const response = await fetch(`${API_BASE}${endpoint}`, {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${getToken()}`
    },
    ...options
  });
  return response.json();
}

// API functions
export const poeApi = {
  // get status
  getStatus: () => request<PoeStatus>('/status'),

  // get detailed info
  getInfo: () => request<PoeDetailInfo>('/info'),

  // get configuration
  getConfig: () => request<PoeConfig>('/config'),

  // set configuration
  setConfig: (config: Partial<PoeConfig>) =>
    request<{ message: string; ip_mode: string }>('/config', {
      method: 'POST',
      body: JSON.stringify(config)
    }),

  // validate configuration
  validate: (config: {
    ip_address: string;
    netmask: string;
    gateway: string;
    dns_primary?: string;
    dns_secondary?: string;
    hostname?: string;
    check_gateway?: boolean;
    check_conflict?: boolean;
  }) => request<ValidationResult>('/validate', {
    method: 'POST',
    body: JSON.stringify(config)
  }),

  // apply configuration
  apply: () => request<{ success: boolean; status: string; ip_mode: string }>('/apply', {
    method: 'POST'
  }),

  // save configuration
  save: () => request<{ success: boolean }>('/save', {
    method: 'POST'
  }),

  // connect
  connect: () => request<{ success: boolean; status: string }>('/connect', {
    method: 'POST'
  }),

  // disconnect
  disconnect: () => request<{ success: boolean; status: string }>('/disconnect', {
    method: 'POST'
  })
};

Usage ​

typescript
// load PoE detailed information
async function loadPoeInfo() {
  const res = await poeApi.getInfo();
  if (res.success && res.data) {
    console.log('IP address:', res.data.ip_address);
    console.log('Connection status:', res.data.network_status);
    console.log('PoE powered:', res.data.poe_powered);
  } else {
    console.error('Failed to load:', res.message);
  }
}

// set a static IP and save it
async function setStaticIP(config: {
  ip: string;
  netmask: string;
  gateway: string;
  dns1: string;
  dns2: string;
}) {
  // 1. validate the configuration
  const validateRes = await poeApi.validate({
    ip_address: config.ip,
    netmask: config.netmask,
    gateway: config.gateway,
    dns_primary: config.dns1,
    dns_secondary: config.dns2,
    check_gateway: true,
    check_conflict: true
  });

  if (!validateRes.success) {
    throw new Error(validateRes.message || 'Validation request failed');
  }

  if (!validateRes.data?.valid) {
    throw new Error(validateRes.data?.errors.join(', ') || 'Invalid configuration');
  }

  // 2. set the configuration
  const setRes = await poeApi.setConfig({
    ip_mode: 'static',
    ip_address: config.ip,
    netmask: config.netmask,
    gateway: config.gateway,
    dns_primary: config.dns1,
    dns_secondary: config.dns2
  });

  if (!setRes.success) {
    throw new Error(setRes.message || 'Failed to set configuration');
  }

  // 3. apply the configuration
  const applyRes = await poeApi.apply();
  if (!applyRes.success || !applyRes.data?.success) {
    throw new Error(applyRes.message || 'Failed to apply configuration');
  }

  // 4. persist to storage
  const saveRes = await poeApi.save();
  if (!saveRes.success || !saveRes.data?.success) {
    console.warn('Failed to save to NVS; the configuration may be lost after reboot');
  }

  return applyRes.data;
}

// switch to DHCP mode
async function switchToDHCP() {
  const setRes = await poeApi.setConfig({ ip_mode: 'dhcp' });
  if (!setRes.success) throw new Error(setRes.message);

  const applyRes = await poeApi.apply();
  if (!applyRes.success) throw new Error(applyRes.message);

  const saveRes = await poeApi.save();
  if (!saveRes.success) console.warn('Failed to save');
}

Typical Workflows ​

1. On page load ​

GET /poe/info     → current status and configuration
GET /poe/config   → full configuration (to populate the form)

2. User changes the static IP configuration ​

POST /poe/validate  → validate the configuration (optional)
POST /poe/config    → save the configuration to memory
POST /poe/apply     → apply the configuration
POST /poe/save      → persist to NVS

3. User switches DHCP/static mode ​

POST /poe/config { "ip_mode": "dhcp" }
POST /poe/apply
POST /poe/save

4. Polling for status updates ​

GET /poe/status   → lightweight status query (recommended every 5 s)
GET /poe/info     → full information (only when details are needed)

Version Information ​

  • API version: v1
  • Document updated: 2024-12-23

Released under the MIT License.