web - wolfen351/public-micropython-iot-platform GitHub Wiki
Web Module Documentation
Overview
The Web module provides a responsive web-based user interface for interacting with the device. It allows users to monitor telemetry, configure settings, and control the device through a browser. The module integrates with other components of the system, such as telemetry providers and command processors, to present a unified interface.
Features
- Responsive Web UI: Accessible from any modern browser, the UI adapts to different screen sizes.
- Telemetry Display: Real-time telemetry data is displayed in a user-friendly format.
- Configuration Management: Allows users to configure device settings, such as the device name and status LED.
- Command Execution: Provides endpoints for executing commands like rebooting the device or toggling the status LED.
- Dynamic Panels: Supports dynamically loading panels contributed by other modules.
- RESTful API: Exposes telemetry and command endpoints for programmatic access.
UI
The main UI is served from web_index.html
. It includes:
- Main Status: Displays the device name and status LED state.
- Panels: Dynamically loaded panels for module-specific telemetry and controls.
- Navigation Buttons: Links to other module-specific pages, such as Home Assistant, Thingsboard, and MQTT.
Example UI Features:
- Editable Device Name: Users can edit the device name directly in the UI.
- Real-Time Updates: Telemetry data is updated every second using JavaScript.
- Switch Controls: Toggle switches for features like the status LED.
Hardware / Pinout
This module does not directly interact with hardware pins. However, it can control hardware indirectly through commands (e.g., toggling the status LED).
Configuration
The Web module uses preferences stored in prefs.json
for configuration:
- Device Name: Configurable via the
web.name
preference. - Status LED: Controlled by the
web.statusLedEnabled
preference.
Example Configuration:
{ "web": { "name": "MyDevice", "statusLedEnabled": true } }
Telemetry Provided
The Web module provides the following telemetry data:
- name: The device name.
- onboard/led: The status of the onboard LED (Enabled or Disabled).
Example Telemetry
{
"name": "MyDevice",
"onboard/led": "Enabled"
}
Telemetry Consumed
The Web module does not consume telemetry from other modules directly. However, it can display telemetry provided by other modules through dynamically loaded panels.
Commands Provided
The Web module provides the following commands via HTTP endpoints:
- /reboot: Reboots the device.
- /saveName: Saves a new device name.
- /switchLed: Toggles the status LED.
Example Command Usage:
- Reboot: GET /reboot
- Save Name: GET /saveName?name=NewDeviceName
- Toggle LED: GET /switchLed
Commands Consumed
The Web module does not consume commands from other modules directly. However, it can relay commands to other modules through the UI.
Additional Notes
- Dynamic Panels: Other modules can contribute panels to the Web UI by registering them using the setPanels method in the WebProcessor class.
- RESTful API: The module's endpoints can be used programmatically for integration with external systems.
- Reboot Behavior: The /reboot endpoint triggers a device reset using the machine.reset() function.