[英]ESP32 attempt reconnect to when network drops without halting loop (Arduino)
[英]ESP32 Arduino httpSecureClient -1 error at core 0 without reason why
我遇到了 Arduino IDE 中 ESP 的 httpsecureclient 库的问题。
我尝试将 http 请求发送到 https 域(不会改变)并且可以正常工作很多次。
就像我做一些 HTTP 调用来获取某些数据让 ESP 做它的事情。 但是当我想让 ESP 使用WiFiClientSecure
和HTTPClient
将有效负载发布到服务器时,它有时可以正常工作,但突然之间,它停止工作并向我抛出众所周知的-1
响应代码。 ..
我用来发送心跳的代码如下;
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
WiFiClientSecure ApiClient;
HTTPClient ApiHttpClient;
StaticJsonDocument<256> doc;
doc["mac"] = deviceMacAddress;
doc["key"] = DEVICE_SECRET;
doc["type"] = DIGITAL_HQ_SOFTWARE_TYPE;
String heartbeatData;
serializeJson(doc, heartbeatData);
ApiClient.setInsecure(); //skip verification of SSL cert
Serial.println("Sending Heartbeat");
ApiHttpClient.begin(ApiClient, DIGITAL_HQ_HEARTBEAT_ENDPOINT);
ApiHttpClient.addHeader("Content-Type", "application/json");
ApiHttpClient.setUserAgent(DIGITAL_HQ_USER_AGENT);
int responseCode = ApiHttpClient.POST(heartbeatData); // just post, Don't care about the response.
if (responseCode != 200) {
failedApiCalls ++;
}
Serial.print("ResponseCode from heartbeat: ");
Serial.println(responseCode);
// Free resources
ApiHttpClient.end();
此代码通过以下函数在核心 0 上运行; xTaskCreatePinnedToCore(sendHeartBeat, "Send Heartbeat", 20000, NULL, 25, &heartBeatTask, 0);
我确实在主核心中调用了一次心跳,然后它可以工作,但是在第二个核心上,它有时会,但有时却不会。
这没有什么太花哨的,我想而且我似乎真的无法弄清楚这个......
边注:
有一个 MQTT 连接运行到核心 1 上的 AWS IoT 中心,我没有任何问题。
我目前在更新库后遇到了同样的问题,esp32 http 客户端的旧代码停止工作,出现相同的症状。
我可以通过切换到仅使用 HTTPClient 而没有 WiFiClientSecure 来解决这个问题。 它适用于 https。
#include <HTTPClient.h>
#include <Arduino_JSON.h>
void getPricesFromKraken(){
String url = "https://api.kraken.com/0/public/Ticker?pair=DOGEUSD,XBTUSD";
HTTPClient http;
JSONVar data;
http.begin(url.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String payload = http.getString();
data = JSON.parse(payload);
Serial.println(data);
}
else {
Serial.printf("http response code: %d\n", httpResponseCode);
}
http.end();
}
我想知道您是否确实找到了解决问题的方法。 我目前在更新库后遇到了同样的问题,esp32 http 客户端的旧代码停止工作,出现相同的症状。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.