Skip to content

Commit 308a502

Browse files
authored
Merge pull request #74 from chvvkumar/Dev
Dev
2 parents 464e3fd + d3705ef commit 308a502

15 files changed

Lines changed: 874 additions & 40 deletions

ESP32-P4-Allsky-Display.ino

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "web_config.h"
55
#include "system_monitor.h"
66
#include "network_manager.h"
7+
#include "captive_portal.h"
78
#include "display_manager.h"
89
#include "ppa_accelerator.h"
910
#include "mqtt_manager.h"
@@ -225,6 +226,46 @@ void setup() {
225226
// Initialize brightness control
226227
displayManager.initBrightness();
227228

229+
// Check if WiFi is provisioned (first boot or after reset)
230+
if (!configStorage.isWiFiProvisioned()) {
231+
debugPrint("WiFi Setup Required", COLOR_YELLOW);
232+
debugPrint("====================", COLOR_YELLOW);
233+
debugPrint("1. Connect to WiFi:", COLOR_CYAN);
234+
debugPrint(" AllSky-Display-Setup", COLOR_WHITE);
235+
debugPrint("", COLOR_WHITE);
236+
debugPrint("2. Browser opens automatically", COLOR_CYAN);
237+
debugPrint(" If not, visit:", COLOR_CYAN);
238+
239+
// Start captive portal for WiFi configuration
240+
if (captivePortal.begin("AllSky-Display-Setup")) {
241+
debugPrintf(COLOR_GREEN, " http://%s", captivePortal.getAPIP().c_str());
242+
debugPrint(" or http://192.168.4.1", COLOR_GREEN);
243+
244+
// Wait for configuration with timeout
245+
unsigned long portalStartTime = millis();
246+
const unsigned long PORTAL_TIMEOUT = 300000; // 5 minutes timeout
247+
248+
while (!captivePortal.isConfigured() && (millis() - portalStartTime) < PORTAL_TIMEOUT) {
249+
captivePortal.handleClient();
250+
systemMonitor.forceResetWatchdog();
251+
delay(10);
252+
}
253+
254+
if (captivePortal.isConfigured()) {
255+
debugPrint("WiFi configured successfully!", COLOR_GREEN);
256+
debugPrint("Restarting device...", COLOR_YELLOW);
257+
captivePortal.stop();
258+
delay(2000);
259+
ESP.restart();
260+
} else {
261+
debugPrint("Configuration timeout - continuing without WiFi", COLOR_RED);
262+
captivePortal.stop();
263+
}
264+
} else {
265+
debugPrint("ERROR: Failed to start captive portal", COLOR_RED);
266+
}
267+
}
268+
228269
// Initialize WiFi manager
229270
if (!wifiManager.begin()) {
230271
debugPrint("ERROR: WiFi initialization failed!", COLOR_RED);

MANUAL_SETUP.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Manual WiFi Configuration
2+
3+
This guide explains how to manually configure WiFi credentials by editing the source code before compilation. This method is only recommended for advanced users or special deployment scenarios.
4+
5+
**⚠️ NOTE**: For normal use, it's recommended to use the automatic WiFi setup via Access Point mode (see main [README](README.md)).
6+
7+
## Prerequisites
8+
9+
- Arduino IDE or PlatformIO installed
10+
- ESP32-P4 board support configured
11+
- Source code downloaded
12+
13+
## Configuration Steps
14+
15+
### 1. Edit Default WiFi Credentials
16+
17+
Open [`config_storage.cpp`](config_storage.cpp) and locate the `setDefaults()` function:
18+
19+
```cpp
20+
void ConfigStorage::setDefaults() {
21+
// Set hardcoded defaults from original config.cpp
22+
// WiFi credentials are intentionally empty - device will start captive portal on first boot
23+
config.wifiProvisioned = false;
24+
config.wifiSSID = ""; // ← Edit this line
25+
config.wifiPassword = ""; // ← Edit this line
26+
27+
config.mqttServer = "192.168.1.250";
28+
config.mqttPort = 1883;
29+
config.mqttUser = "";
30+
config.mqttPassword = "";
31+
config.mqttClientID = "ESP32_Allsky_Display";
32+
// ... rest of configuration
33+
}
34+
```
35+
36+
**Replace the empty strings with your WiFi credentials:**
37+
38+
```cpp
39+
config.wifiSSID = "YOUR_WIFI_SSID"; // Your network name
40+
config.wifiPassword = "YOUR_WIFI_PASSWORD"; // Your network password
41+
```
42+
43+
### 2. Configure MQTT Settings (Optional)
44+
45+
While in the same function, you can also pre-configure MQTT settings:
46+
47+
```cpp
48+
config.mqttServer = "192.168.1.250"; // MQTT broker IP or hostname
49+
config.mqttPort = 1883; // MQTT port (usually 1883)
50+
config.mqttUser = ""; // MQTT username (if required)
51+
config.mqttPassword = ""; // MQTT password (if required)
52+
config.mqttClientID = "ESP32_Allsky_Display"; // Unique client ID
53+
```
54+
55+
### 3. Configure Default Image Sources (Optional)
56+
57+
Open [`config.cpp`](config.cpp) and locate the `DEFAULT_IMAGE_SOURCES` array:
58+
59+
```cpp
60+
const char* DEFAULT_IMAGE_SOURCES[] = {
61+
"https://i.imgur.com/EsstNmc.jpeg", // Default source 1
62+
"https://i.imgur.com/EtW1eaT.jpeg", // Default source 2
63+
"https://i.imgur.com/k23xBF5.jpeg", // Default source 3
64+
"https://i.imgur.com/BysRDbf.jpeg", // Default source 4
65+
"http://allskypi5.lan/current/resized/image.jpg" // Default source 5
66+
// Add more image URLs here as needed (up to MAX_IMAGE_SOURCES = 10)
67+
};
68+
```
69+
70+
**Replace these with your own image URLs:**
71+
72+
```cpp
73+
const char* DEFAULT_IMAGE_SOURCES[] = {
74+
"http://your-allsky-server.com/resized/image.jpg",
75+
"http://your-camera2.com/image.jpg",
76+
// Add up to 10 total sources
77+
};
78+
```
79+
80+
### 4. Compile and Upload
81+
82+
1. **Arduino IDE**: Click the Upload button (→) in the toolbar
83+
2. **PlatformIO**: Run `pio run --target upload`
84+
85+
### 5. Monitor Serial Output
86+
87+
Open the Serial Monitor (115200 baud) to see:
88+
- WiFi connection status
89+
- Assigned IP address
90+
- Configuration loading status
91+
- System information
92+
93+
### 6. Access Web Interface
94+
95+
Once connected, the device will display its IP address in the serial output. Access the web interface at:
96+
97+
```
98+
http://[device-ip]:8080/
99+
```
100+
101+
From here you can modify all settings without recompiling.
102+
103+
## Important Notes
104+
105+
### First Boot Behavior
106+
107+
- If `config.wifiSSID` is empty, the device will start in Access Point mode
108+
- If `config.wifiSSID` is set, the device will attempt to connect to that network
109+
- After successful configuration via web interface, these hardcoded values are overridden by stored settings
110+
111+
### Resetting to Manual Configuration
112+
113+
To reset the device back to using your hardcoded credentials:
114+
115+
1. Use the Factory Reset button in the web interface, OR
116+
2. Use the reset function in the web API, OR
117+
3. Erase flash memory using `esptool.py erase_flash`
118+
119+
After reset, the device will use the credentials you set in `config_storage.cpp`.
120+
121+
### Security Considerations
122+
123+
**⚠️ WARNING**: Storing WiFi credentials in source code is not recommended for:
124+
- Shared code repositories (credentials will be visible in version control)
125+
- Multi-device deployments with different networks
126+
- Production environments
127+
128+
For these scenarios, use the Access Point mode (default behavior) to configure each device individually.
129+
130+
## Troubleshooting
131+
132+
### Device Won't Connect to WiFi
133+
134+
1. Verify SSID and password are correct (case-sensitive)
135+
2. Check that WiFi network is 2.4GHz (ESP32-P4 may not support 5GHz on all models)
136+
3. Ensure network is in range and operational
137+
4. Monitor serial output for connection errors
138+
139+
### Can't Find IP Address
140+
141+
1. Check your router's DHCP client list
142+
2. Look for device named "ESP32_Allsky_Display" or similar
143+
3. Serial monitor will display the IP address on successful connection
144+
4. Try accessing via mDNS: `http://allskyesp32.lan:8080/` (if supported by your network)
145+
146+
### Need to Reconfigure WiFi
147+
148+
If you need to change WiFi settings after deployment:
149+
150+
**Option 1**: Use the web interface (Network settings page)
151+
152+
**Option 2**: Factory reset and trigger Access Point mode:
153+
1. Access web interface
154+
2. Go to System settings
155+
3. Click "Factory Reset"
156+
4. Device will restart in AP mode for reconfiguration
157+
158+
## Alternative: Access Point Mode (Recommended)
159+
160+
Instead of manual configuration, consider using the automatic Access Point mode:
161+
162+
1. Leave `config.wifiSSID` empty in `config_storage.cpp`
163+
2. Compile and upload firmware
164+
3. Device creates WiFi network: **AllSky-Display-Setup**
165+
4. Connect your phone/computer to this network
166+
5. Captive portal opens automatically
167+
6. Select your WiFi network and enter password
168+
7. Device connects and saves credentials
169+
170+
See main [README](README.md) for detailed instructions on Access Point mode.

README.md

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,50 @@ This project makes your ESP32-P4 touch display into an all-sky camera viewer wit
9494

9595
### Initial Setup
9696

97-
#### 1. Configure WiFi Credentials
97+
#### 1. Compile and Upload Firmware
9898

99-
**⚠️ IMPORTANT**: Edit WiFi settings **before** first upload.
99+
- Click the Upload button in Arduino IDE
100+
- Monitor serial output for status messages
101+
102+
#### 2. WiFi Setup via Access Point Mode
103+
104+
On first boot, the device automatically creates a WiFi access point for easy configuration:
105+
106+
**Connection Steps:**
107+
108+
1. **Find the WiFi Network**
109+
- Network Name: `AllSky-Display-Setup`
110+
- No password required
111+
112+
2. **Connect to the Network**
113+
- Use your phone, tablet, or computer
114+
- Connect to `AllSky-Display-Setup` WiFi
115+
116+
3. **Configure WiFi**
117+
- A configuration page should open automatically (captive portal)
118+
- If not, manually open a browser and go to:
119+
- `http://192.168.4.1`
120+
- Click "Scan for Networks" to see available WiFi networks
121+
- Select your WiFi network from the list
122+
- Enter the WiFi password
123+
- Click "Connect"
124+
125+
4. **Device Connects and Restarts**
126+
- The device will connect to your WiFi network
127+
- After successful connection, it will restart
128+
- The display will show the assigned IP address
100129

101-
Open [`config_storage.cpp`](config_storage.cpp) and modify:
130+
5. **Access Web Interface**
131+
- Note the IP address shown on the display
132+
- Open a browser and go to `http://[device-ip]:8080/`
133+
- Configure additional settings like MQTT, image sources, and display preferences
102134

103-
````cpp
104-
void ConfigStorage::setDefaults() {
105-
// *** EDIT THESE LINES ***
106-
config.wifiSSID = "YOUR_WIFI_SSID"; // Your network name
107-
config.wifiPassword = "YOUR_WIFI_PASSWORD"; // Your password
108-
109-
// MQTT settings (optional, can configure via web later)
110-
config.mqttServer = "192.168.1.250"; // MQTT broker IP
111-
config.mqttPort = 1883;
112-
config.mqttUser = ""; // Optional
113-
config.mqttPassword = ""; // Optional
114-
}
115-
````
135+
**Alternative Setup:**
136+
- If you prefer to manually configure WiFi by editing source code, see [MANUAL_SETUP.md](MANUAL_SETUP.md)
116137

117-
#### 2. Configure Default Image Source (Optional)
138+
#### 3. Configure Default Image Sources (Optional)
118139

119-
In [`config.cpp`](config.cpp), set your default image URLs:
140+
After connecting to WiFi, use the web interface to add image sources, or pre-configure them in [`config.cpp`](config.cpp):
120141

121142
```cpp
122143
const char* DEFAULT_IMAGE_SOURCES[] = {
@@ -126,16 +147,6 @@ const char* DEFAULT_IMAGE_SOURCES[] = {
126147
};
127148
```
128149

129-
#### 3. Compile and Upload
130-
131-
- Click the Upload button in Arduino IDE
132-
- Monitor serial output for IP address and status
133-
134-
#### 4. Access Web Interface
135-
136-
- Open a browser and go to `http://[device-ip]:8080/`
137-
- Configure additional settings like MQTT and image sources
138-
139150
## ⚙️ Configuration
140151

141152
### Web Interface
@@ -224,17 +235,17 @@ The device provides a comprehensive web-based configuration interface accessible
224235

225236
### Configuration Pages
226237

227-
<img src="images/2025-12-03_10-55-20.png" alt="Web Configuration Main Page">
228-
229-
<img src="images/2025-12-03_10-55-31.png" alt="Image Sources Configuration">
230-
231-
<img src="images/2025-12-03_10-55-35.png" alt="Display Settings">
238+
#### Main Dashboard
239+
<img src="images/config-home.png" alt="Web Configuration Main Page">
232240

233-
<img src="images/2025-12-03_10-55-38.png" alt="Network Configuration">
241+
#### Multi-Image Sources
242+
<img src="images/config-multi-image.png" alt="Multi-Image Sources Configuration">
234243

235-
<img src="images/2025-12-03_10-55-42.png" alt="MQTT Configuration">
244+
#### Display Settings
245+
<img src="images/config-display.png" alt="Display Settings">
236246

237-
<img src="images/2025-12-03_10-55-48.png" alt="System Information">
247+
#### MQTT Configuration
248+
<img src="images/config-mqtt.png" alt="MQTT Configuration">
238249

239250
### Home Assistant Integration
240251

0 commit comments

Comments
 (0)