|
| 1 | +#include <InkplateMotion.h> |
| 2 | + |
| 3 | +#define WIFI_SSID "" |
| 4 | +#define WIFI_PASS "" |
| 5 | +#define REMOTE_IP "" |
| 6 | +#define REMOTE_PORT 5005 |
| 7 | +#define LOCAL_PORT 5005 |
| 8 | + |
| 9 | +Inkplate inkplate; |
| 10 | +WiFiUDP udp; |
| 11 | + |
| 12 | +uint32_t attempts = 0; |
| 13 | +uint32_t successes = 0; |
| 14 | +uint32_t failures = 0; |
| 15 | +bool diagnosed = false; |
| 16 | + |
| 17 | +void setup() |
| 18 | +{ |
| 19 | + Serial.begin(115200); |
| 20 | + inkplate.begin(INKPLATE_1BW); |
| 21 | + WiFi.init(); |
| 22 | + |
| 23 | + WiFi.setMode(INKPLATE_WIFI_MODE_STA); |
| 24 | + WiFi.begin(WIFI_SSID, WIFI_PASS); |
| 25 | + while (!WiFi.connected()) { Serial.print('.'); delay(1000); } |
| 26 | + |
| 27 | + IPAddress ip; |
| 28 | + unsigned long ipWaitStart = millis(); |
| 29 | + do |
| 30 | + { |
| 31 | + delay(500); |
| 32 | + ip = WiFi.localIP(); |
| 33 | + } while (ip == IPAddress(0, 0, 0, 0) && millis() - ipWaitStart < 10000); |
| 34 | + Serial.print("Inkplate IP: "); |
| 35 | + Serial.println(ip); |
| 36 | + |
| 37 | + udp.setConnectionTimeout(10000); |
| 38 | + |
| 39 | + Serial.println("Starting beginPacket() stress test (full begin/setHost/beginPacket/end cycle each attempt)..."); |
| 40 | +} |
| 41 | + |
| 42 | +void loop() |
| 43 | +{ |
| 44 | + attempts++; |
| 45 | + |
| 46 | + bool beginOk = udp.begin(LOCAL_PORT); |
| 47 | + bool hostOk = beginOk && udp.setHost(REMOTE_IP, REMOTE_PORT); |
| 48 | + bool ok = hostOk && udp.beginPacket(); |
| 49 | + |
| 50 | + if (ok) |
| 51 | + successes++; |
| 52 | + else |
| 53 | + failures++; |
| 54 | + |
| 55 | + // Dump whatever raw text the ESP32 last sent back, once, right when the failure pattern |
| 56 | + // first appears - so we know if it's an AT "ERROR", a timeout (stale/empty buffer), or |
| 57 | + // something else, instead of just true/false. |
| 58 | + if (!ok && !diagnosed) |
| 59 | + { |
| 60 | + diagnosed = true; |
| 61 | + Serial.println("=== FIRST FAILURE - raw AT buffer follows ==="); |
| 62 | + Serial.print("begin failed: "); Serial.println(!beginOk); |
| 63 | + Serial.print("setHost failed: "); Serial.println(beginOk && !hostOk); |
| 64 | + Serial.print("beginPacket failed: "); Serial.println(hostOk && !ok); |
| 65 | + Serial.println(WiFi.getDataBuffer()); |
| 66 | + Serial.println("=== end raw AT buffer ==="); |
| 67 | + } |
| 68 | + |
| 69 | + Serial.print("attempt="); Serial.print(attempts); |
| 70 | + Serial.print(" begin="); Serial.print(beginOk ? "OK" : "FAIL"); |
| 71 | + Serial.print(" setHost="); Serial.print(hostOk ? "OK" : "FAIL"); |
| 72 | + Serial.print(" beginPacket="); Serial.print(ok ? "OK" : "FAIL"); |
| 73 | + Serial.print(" successes="); Serial.print(successes); |
| 74 | + Serial.print(" failures="); Serial.print(failures); |
| 75 | + Serial.print(" rate="); Serial.print((100.0 * successes) / attempts, 1); |
| 76 | + Serial.println("%"); |
| 77 | + |
| 78 | + udp.end(); |
| 79 | + delay(200); |
| 80 | +} |
0 commit comments