-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_minimal.cpp
More file actions
94 lines (82 loc) · 2.73 KB
/
Copy pathtest_minimal.cpp
File metadata and controls
94 lines (82 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Minimal heap-stress test — WiFi + HTTP GET + JSON parse, NO display.
*
* Build: pio run -e esp32-s3-radar --target upload
* Then copy this file over src/main.cpp, or create a separate env.
*
* If this runs stable for 50+ iterations, the crash is caused by the
* GDMA/display interaction with the PSRAM heap. If it crashes here
* too, the issue is more fundamental (power, module defect, etc.).
*/
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#define WIFI_SSID "Gramy Things"
#define WIFI_PASSWORD "thisismypassphraseblah"
#define HOST "192.168.68.109"
#define PORT 8080
#define PATH "/data/aircraft.json"
static int iteration = 0;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("\n=== Minimal heap-stress test ===");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("WiFi connecting");
int retries = 0;
while (WiFi.status() != WL_CONNECTED && retries < 60) {
delay(500); Serial.print("."); retries++;
}
if (WiFi.status() != WL_CONNECTED) {
Serial.println("\nWiFi FAILED"); return;
}
Serial.println("\nWiFi OK: " + WiFi.localIP().toString());
}
void loop() {
/* Retry WiFi if it never connected in setup() */
if (WiFi.status() != WL_CONNECTED) {
Serial.print("WiFi reconnecting");
WiFi.reconnect();
int r = 0;
while (WiFi.status() != WL_CONNECTED && r < 30) {
delay(500); Serial.print("."); r++;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\nWiFi reconnected: " + WiFi.localIP().toString());
} else {
Serial.println(" still down");
delay(2000);
return;
}
}
iteration++;
char url[128];
snprintf(url, sizeof(url), "http://%s:%d%s", HOST, PORT, PATH);
HTTPClient http;
http.begin(url);
http.setConnectTimeout(3000);
http.setTimeout(5000);
unsigned long t0 = millis();
int code = http.GET();
unsigned long dt = millis() - t0;
if (code == 200) {
String payload = http.getString();
http.end();
JsonDocument doc;
DeserializationError err = deserializeJson(doc, payload);
if (!err) {
JsonArray arr = doc["aircraft"].as<JsonArray>();
int count = arr ? arr.size() : 0;
Serial.printf("[%4d] OK %d aircraft %lu ms heap=%u\n",
iteration, count, dt,
ESP.getFreeHeap());
} else {
Serial.printf("[%4d] JSON err: %s\n", iteration, err.c_str());
}
} else {
http.end();
Serial.printf("[%4d] HTTP %d (%lu ms)\n", iteration, code, dt);
}
delay(1000);
}