我正在使用 ArduinoIDE 对 ESP32 进行编程,并且遇到了 HTTP GET 问题。我在做什么:
这是我用于 HTTP GET 调用的代码:
static WiFiClient wifi;
HttpClient wlanHttp=HttpClient(wifi,"my.server.tld");
wlanHttp.get("/setpos.php?id=DEADBEEF"); // -> this fails with error code -1
wlanHttp.responseStatusCode(); // follow-up error -1
wlanHttp.stop();
Run Code Online (Sandbox Code Playgroud)
知道这里出了什么问题吗?
我遇到的问题是,由于 Access-Control-Allow-Origin 错误,我无法从创建的 .json 中 fetch() 。我发现我必须创建某种标头,但我不知道这样的命令在我使用的库中是什么样子以及必须选择哪些参数。我希望您能帮助我对此代码进行必要的添加。
\n#include <ArduinoJson.h>\n#include <WiFi.h>\n#include <WebServer.h>\n#include <DHT.h>\n\n#define DHTPIN 13\n#define DHTTYPE DHT11\n\nDHT dht(DHTPIN, DHTTYPE);\n\nconst char *ssid = "XXX";\nconst char *pwd = "XXX";\n\nStaticJsonDocument<250> jsonDocument;\nchar buffer[250];\n\nfloat temperature;\nfloat humidity;\n\nWebServer server(80);\n\nvoid setup() {\ndht.begin();\nSerial.begin(9600);\nSerial.println(WiFi.localIP()); \nSerial.print("Connect to: ");\nSerial.println(ssid);\nWiFi.begin(ssid, pwd);\n while (WiFi.status() != WL_CONNECTED){\n Serial.print(".");\n delay(500);\n }\nSerial.print("Connected. IP: ");\nSerial.println(WiFi.localIP());\nsetup_routing();\n}\n\nvoid setup_routing(){\n server.on("/sensor", getEnv);\n sendHeader()\n server.begin();\n}\n\nvoid create_json(char *tag, float value, char *unit){\n jsonDocument.clear();\n jsonDocument["type"] = tag;\n jsonDocument["value"] = value;\n jsonDocument["unit"] = unit;\n serializeJson(jsonDocument, buffer);\n}\n\nvoid add_json_object(char *tag, float value, char *unit){\n JsonObject obj = jsonDocument.createNestedObject();\n …Run Code Online (Sandbox Code Playgroud) 我正在研究 esp32 MQTT。当我从云向微控制器发布消息时,我收到了一条基于 msg 程序的 MQTT 消息,在处理完成后,我使用 MQTT 发送确认。发送确认后,esp 崩溃了。所以我想知道这个错误是什么意思?我收到错误的可能原因是什么?
DEBUG: [mqtt.c:800:handleMqttPayload] ------------------------>line
DEBUG: [mqtt.c:472:_mqttSubscriptionCallback] ------------------------>line
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400957b6 PS : 0x00060933 A0 : 0x80085160 A1 : 0x3ffe2120
0x400957b6: is_free at /home/horsemann/Desktop/WorkSpace/TestingRepo/vendors/espressif/esp-idf/components/heap/multi_heap.c:380
(inlined by) multi_heap_malloc_impl at /home/horsemann/Desktop/WorkSpace/TestingRepo/vendors/espressif/esp-idf/components/heap/multi_heap.c:432
A2 : 0x3ffb9a20 A3 : 0x00000074 A4 : 0x3ffb9bc2 A5 : 0x3ffc24f4
A6 : 0x00000000 A7 : 0x3ffc1930 A8 : 0x62df42e6 A9 : 0x00003ffb
A10 : 0x00000001 A11 : …Run Code Online (Sandbox Code Playgroud) 我的系统需要处于深度睡眠模式并每秒唤醒一次,我如何预测并使启动时间尽可能短?我对 ESP32 的低功耗模式的糟糕表现感到有点惊讶,150 uA 深度睡眠,然后强制重启对我来说听起来很疯狂,我错过了什么吗?
esp32 ×4
arduino-ide ×2
embedded ×1
freertos ×1
http ×1
http-get ×1
iot ×1
javascript ×1
webserver ×1
wifi ×1