ESP-NOW: STA interface, notify browser on send failure
- Activate STA interface before ESP-NOW to fix ESP_ERR_ESPNOW_IF - Notify browser on send failure: WebSocket sends error JSON; preset API returns 503 - Use exceptions for failure (not return value) to avoid false errors when send succeeds - presets.js: handle server error messages in WebSocket onmessage Made-with: Cursor
This commit is contained in:
@@ -25,6 +25,18 @@ const getEspnowSocket = () => {
|
||||
espnowPendingMessages = [];
|
||||
};
|
||||
|
||||
espnowSocket.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data && data.error) {
|
||||
console.error('ESP-NOW:', data.error);
|
||||
alert('ESP-NOW send failed. ' + (data.error === 'ESP-NOW send failed' ? 'Check device WiFi/interface.' : data.error));
|
||||
}
|
||||
} catch (_) {
|
||||
// Ignore non-JSON or non-error messages
|
||||
}
|
||||
};
|
||||
|
||||
espnowSocket.onclose = () => {
|
||||
espnowSocketReady = false;
|
||||
espnowSocket = null;
|
||||
|
||||
Reference in New Issue
Block a user