c++ - 微雪电子纸ESP32板HTTP客户端管理问题

标签 c++ http arduino httpclient esp32

大家早上好。 我正在开发基于 IDE Arduino 上 ESP32 版本的电子 Waveshare 显示器的应用程序。该指令是在显示器上打印由特定地址的网络服务提供的位图图像。作为初学者,我不清楚如何使用 GxEPD 库打印位图,但这个问题是次要的。 首先,我正在尝试恢复“更简单”网络资源的内容,即由 ESP8266 提供的文本/纯 HTML,其编程方式可充当“基本”网络服务器。在这种情况下,ESP32 必须获取这个简短的测试文本,然后将其显示在显示器上。 但是,有一个缺点我无法解决。 ESP32 对资源的第一次 GET 尝试总是失败;相反,在第二次尝试时,它运行,它获取资源并将其打印在串行输出上,但在将其打印在 Waveshare 显示器上之前,系统崩溃并重新启动。 这是串行输出:

Display initialized!

HTTP began!
Error on HTTP request

HTTP communication ended


HTTP began!
HTTP GET accepted!
200
Welcome! This is a test page of the ESP8266 Web Server.
.
.
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x4015ea54  PS      : 0x00060430  A0      : 0x800d4856  A1      : 0x3ffb1ea0
A2      : 0x3ffb1f10  A3      : 0x00000000  A4      : 0x00000625  A5      : 0x3ffc8eb8
A6      : 0x00000001  A7      : 0x00000175  A8      : 0x00000000  A9      : 0x3ffb1e80
A10     : 0x3ffafe88  A11     : 0x00000000  A12     : 0x00000002  A13     : 0x0000ff00
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000010  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff

Backtrace: 0x4015ea54:0x3ffb1ea0 0x400d4853:0x3ffb1ec0 0x400d48c5:0x3ffb1ee0 0x400d1946:0x3ffb1f00 0x400d8d05:0x3ffb1fb0 0x40088b9d:0x3ffb1fd0

Rebooting...

然后 esp32 重新启动并重新启动,第一个请求失败,然后是第二个成功的请求,并立即使其崩溃并再次重新启动。

在esp32上刷写的代码如下:

#include <GxEPD.h>
#include <GxGDEW075T8/GxGDEW075T8.h>


#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>

#include <GxIO/GxIO.h>
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <WiFi.h>
#include <HTTPClient.h>

GxIO_Class io(SPI, /*CS=5*/ 15, /*DC=*/ 27, /*RST=*/ 26); // arbitrary selection of 17, 16
GxEPD_Class display(io, /*RST=*/ 26, /*BUSY=*/ 25); // arbitrary selection of (16), 4

const char* ssid = "joan";
const char* password = "joan1q2w";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Avvio completato!\n");
  // setup the display
  display.init();
  Serial.println("Display initialized!\n");

  /* ISTRUZIONI SPECIALI PER IL NOSTRO MODELLO DI ESP32 WAVESHARE */
  SPI.end(); // release standard SPI pins, e.g. SCK(18), MISO(19), MOSI(23), SS(5)
  SPI.begin(13, 12, 14, 15); // map and init SPI pins SCK(13), MISO(12), MOSI(14), SS(15)
  /*  FINE ISTRUZIONI SPECIALI */

  WiFi.begin(ssid, password);


}

void loop()
{
  HTTPClient httpclient;

  httpclient.begin("http://172.16.0.104/welcome");
  Serial.println("HTTP began!");

  int httpCode = httpclient.GET();  // Questo in realtà serve per verificare il codice della richiesta e fare error handling. non è la richiesta vera e propria!

  if (httpCode > 0)   // Se la GET va a buon fine, posso fare effettivamente l'acquisizione
  {
    Serial.println("HTTP GET accepted!");
    String payload = httpclient.getString();  // ritorna una String con la risposta.
    Serial.println(httpCode);
    Serial.println(payload);
  }
  else
  {
    Serial.println("Error on HTTP request");
  }

  httpclient.end();

  Serial.println("HTTP communication ended");

  delay(15000);

}

我还想补充一点,我尝试了几个网络资源,ESP32 总是这样;第一次失败,第二次成功但使卡崩溃。 我的想法已经用尽,无法对代码进行进一步的故障排除......

最佳答案

我在 Arduino 库中看不到任何 end() 函数。

而且,正如您在输出中看到的那样,正是这一行会为您提供异常。

因此,IDE 可能使用了错误的库(来自 Arduino 的库,而不是来自 ESP32 的库)。

如果它使用了正确的库,也可能是因为您没有在等待连接!

重要的是等待,直到连接成功。 在设置结束时添加:

while(WiFi.status() != WL_CONNECTED) { 
  delay(500);
  Serial.print(".");
}

关于c++ - 微雪电子纸ESP32板HTTP客户端管理问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59053885/

相关文章:

c# - 重现问题 : The http request was forbidden with client authentication scheme 'anonymous'

c++ - 没有 IDE 的 Arduino DUE 编程 (Linux)

c++ - 将 ino sketch 转换为 C++ 类,无效使用非静态成员函数

c++ - 使用 Qt 解析 JSON 数组

c++ - 如何组织类的成员函数?

java - C++ 中的 typedef 关键字是否有 Java 等效项或方法?

c++ - 三角形中的线段

javascript - 如果用户没有将 http 添加到他们的链接中

python-3.x - 使用 Python 模块 aiohttp 捕获 http 错误连接的正确方法是什么?

http - WifiClient 未连接到 XAMPP 服务器