https://github.com/BuckRogers1965/Pico-IoT-Replacement
1. Introduction & Showcase Project
Showcase: The Advanced Environment Controller
Comprehensive Sensing: Monitors ambient temperature, humidity, barometric pressure, light level, and soil moisture. Dynamic Web UI: A real-time dashboard accessible from any browser on your network, showing all sensor data and controls. Interactive Controls: A slider to set the target humidity for an automated humidifier. A toggle switch for manual override of the main grow light. A push button to trigger a timed "Feed Now" water pump cycle.
Zero-Touch Setup: A captive portal for easy, one-time configuration of WiFi credentials and a unique device name (e.g., "Living Room Terrarium"). Automatic Discovery: The device announces itself on the network via mDNS and is automatically discovered and integrated into Home Assistant by the provided Python bridge script. Live Graphing: Displays a historical graph of temperature, humidity, and light levels. Custom API Endpoint: A special /api/reboot endpoint to remotely restart the device.
2. User Guide: First-Time Device Setup
Power On the Device: Plug your Pico W device into a USB power source for the first time. The device will fail to find any saved WiFi credentials and will automatically enter Configuration Mode. The onboard LED will likely blink in a rapid pattern to indicate this. Connect to the Setup Network: On your phone or laptop, open your WiFi settings. You will see a new, open WiFi network with a name like ProjectName-Setup-XXYYZZ. For our showcase project, this would be AdvEnv-Setup-A1B2C3. Connect to this network. The Captive Portal: As soon as you connect, your device's web browser should automatically open a setup page. (If it doesn't, open a browser and navigate to http://192.168.4.1). Configure Your Device: You will see a simple form: WiFi Network: A dropdown list of nearby networks. Select your home WiFi network. WiFi Password: Enter the password for your home WiFi. Device Name: This is crucial. Give this specific device a unique, descriptive name. For example: Orchid Terrarium .
Save and Reboot: Click the "Save and Reboot" button.
3. Developer's Guide: Building Your Own Project
3.1. Project Structure
MyNewProject.ino: Contains only your project-specific logic. PicoW_IoT_Framework.h: The framework itself. You never need to edit this file.
3.2. The 5 Essential Application Callbacks
app_draw_graph(): You define which data from your history buffer gets plotted and how. This gives you full control over the graph visualization. app_add_api_endpoints(): (Advanced Example) This allows you to add your own custom API endpoints to the web server. Here, we add a simple /api/reboot command.
3.3. Writing the Main Application Task
Read Inputs: Get latest values from physical sensors AND read the current control settings from the registry using IoTFramework::getRegistryValue(). Process Logic: Make decisions. (e.g., if ). Write Outputs: Update physical actuators (relays, PWM) AND write the latest sensor readings back to the registry using IoTFramework::setRegistryValue() so the web UI updates. Update History: Once per second, add relevant data points to the sensor_history buffer for graphing.
4. The Automation Bridge
It continuously scans your network for any device advertising the _iot-framework._tcp service. When it finds one, it connects and queries the /api/identity endpoint to learn its unique name (e.g., "Orchid Terrarium"). It then queries the /api/manifest endpoint to learn all of its sensors and controls. It automatically generates and sends the necessary configuration messages to Home Assistant via MQTT to create all the corresponding entities. It then enters a loop, acting as a gateway to relay data and commands between the Pico and Home Assistant.
No comments:
Post a Comment