所以我一直在努力让这个工作。
我有一个 ESP32,但我无法使用模块上的 wifi(我根本无法使用,因为 ESP 的实施)。
现在,我有一个适用于 arduino 的 W5500 扩展板,但我认为这在 ESP 上应该可以正常工作,因为它通过 SPI 进行通信。
我的代码可以与 ESP 的 Wifi 完美配合,但现在它需要在以太网上运行。
HTTPClient http;
void sendHeartBeat(void *pvParameters) {
// Infinite loop (while true is more risky for some reason)
unsigned long previousMillis = 0;
const long interval = 300000; // 5 minutes
for (;;) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; // reset timer
int httpResponseCode;
http.begin(DIGITAL_HQ_HEARTBEAT_ENDPOINT); // test environment
http.addHeader("Content-Type", "application/json");
http.setUserAgent(DIGITAL_HQ_USER_AGENT);
StaticJsonDocument<128> doc;
doc["mac"] = deviceMacAddress;
doc["key"] = DEVICE_SECRET;
doc["type"] = DIGITAL_HQ_SOFTWARE_TYPE;
String output;
serializeJson(doc, output);
httpResponseCode = http.POST(output);
// If the device was deleted from HQ, re-register it.
if (httpResponseCode == 202) {
registerDevice();
}
http.end();
}
}
}
以上代码在使用 wifi 时在 ESP 上运行良好。现在它不再存在,只会使整个设备崩溃。
这是堆栈跟踪;
16:20:52.874 -> assertion "Invalid mbox" failed: file "/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/api/tcpip.c", line 374, function: tcpip_send_msg_wait_sem
16:20:53.110 -> abort() was called at PC 0x400dced7 on core 1
16:20:53.143 ->
16:20:53.143 -> ELF file SHA256: 0000000000000000
16:20:53.176 ->
16:20:53.176 -> Backtrace: 0x400891f4:0x3ffb1a00 0x4008946d:0x3ffb1a20 0x400dced7:0x3ffb1a40 0x401122bb:0x3ffb1a70 0x40111d55:0x3ffb1aa0 0x40111f08:0x3ffb1ac0 0x40108f10:0x3ffb1b00 0x400d4fbd:0x3ffb1b20 0x400d4cee:0x3ffb1da0 0x400d4e09:0x3ffb1dd0 0x40126337:0x3ffb1df0 0x400d783e:0x3ffb1e10 0x400d78d1:0x3ffb1e40 0x400d7a63:0x3ffb1e90 0x400d7a83:0x3ffb1eb0 0x400d284e:0x3ffb1ed0 0x400d9fd1:0x3ffb1fb0 0x4008a472:0x3ffb1fd0
我做错了什么?我该如何解决这个问题而不会太麻烦?我在任何其他使用过的库(例如 MQTTClient.h
、WiFiClientSecure.h
)上也有这个。我使用的那些,我真的不想为了“我使用 rj45 连接器而不是 wifi”而重新编写所有代码......
编辑:
问题出在 https,但我还需要能够使用 https 网址...当我使用 http 时,请求也不会发生。