【问题标题】:Cannot fetch data from AWS Lambda service with ESP32 HTTPS无法使用 ESP32 HTTPS 从 AWS Lambda 服务获取数据
【发布时间】:2021-05-04 05:02:59
【问题描述】:

谁能告诉我为什么我无法使用 ESP32 微控制器 (Arduino C) 成功创建对我的 AWS Lambda 函数的 GET 请求?

  • 我使用无服务器框架创建了 AWS Lambda 服务。
  • 我为 Raspberry Pi 创建了 python 脚本,它将 GET 请求(获取设置)发送到 AWS Lambda,然后 RPI 开始将测量数据发送到同一个 API。一切正常。
  • 但现在我尝试使用 ESP32 和 Arduino C 重现此功能,但无法正常工作。

使用以下软件成功创建请求:

  • 带有“请求”库的 Python 脚本
  • 带有“node-fetch”库的 NodeJS 应用程序
  • 邮递员
  • VS 代码 Rest-client 扩展
  • Atom Rest-客户端扩展

不工作:

  • Arduino 库 (HTTPClient.h || ArduinoHTTPClient.h)

那么这些有什么区别呢?在 GET 请求中缺少一些标头?

ESP32 出现以下错误:

  • -2(原始状态码?)
  • 发送标头失败(HTTPClient.h 状态码 ENUM)

我在创建 ESP32 代码时使用了本指南:
https://medium.com/@sanghviyash6/migrating-any-http-request-to-https-on-esp32-5545a6de7845

我缺少哪些内置于所有其他方法的部分?

#include <WiFi.h>
#include <HTTPClient.h>
 
const char* ssid = "yourNetworkName";
const char* password =  "yourNetworkPass";
 
void setup() {
 
  Serial.begin(115200);
  delay(1000);
 
  WiFi.begin(ssid, password); 
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
 
  Serial.println("Connected to the WiFi network");
}
 
const char* root_ca= \
"-----BEGIN CERTIFICATE-----\n" \
"BAUwAwEB/zAKBggqhkjOPQQDAwNoADBlAjEA7wNbeqy3eApyt4jf/7VGFAkK+qDm\n" \
"fQjGGoe9GKhzvSbKYAydzpmfz1wPMOG+FDHqAjAU9JM8SaczepBGR7NjfRObTrdv\n" \
"GDeAU/7dIOA1mjbRxwG55tzd8/8dLDoWV9mSOdY=\n" \
"-----END CERTIFICATE-----\n";
 
void loop() {
 
  if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
 
    HTTPClient http;
 
    http.begin("https://aws/function", root_ca); //Specify the URL and certificate
    int httpCode = http.GET(); //Make the request
 
    if (httpCode > 0) { //Check for the returning code
 
        String payload = http.getString();
        Serial.println(httpCode);
        Serial.println(payload);
      }
 
    else {
      Serial.println("Error on HTTP request");
    }
 
    http.end(); //Free the resources
  }
 
  delay(10000);
}

以上代码原因:

  • httpCode: = -2

如果您需要更多信息,请告诉我。

【问题讨论】:

  • 分享演示您的问题的代码,您可能会得到一些帮助。否则,您是在要求我们猜测您做错了什么。
  • 你没看我的帖子?
  • 我确实阅读了您的帖子。提供一个演示问题的minimal, viable, complete 示例可以使您的帖子对其他有类似问题的人有价值。这也意味着如果您链接到的页面消失了,您的问题仍然有意义。这意味着我们正在调试您实际运行的代码,而不是查看您复制和修改的示例代码,而不告诉我们您所做的更改。如果您需要帮助,请发布代码。

标签: amazon-web-services https aws-lambda esp32 arduino-esp8266


【解决方案1】:

如果您使用的是this HttpClient 库,那么它期望接收一个实现 TLS 层的 WiFiClientSecure 实例。

【讨论】:

    猜你喜欢
    • 2020-12-25
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 2017-01-19
    • 1970-01-01
    • 2019-02-24
    • 2014-01-21
    相关资源
    最近更新 更多