首页 > 解决方案 > 使用 Esp8266 ( aws ) 发出 Http 发布请求

问题描述

这就是我在 postmaster 中所做的请求

嗨,我正在尝试从 esp8266 发出 http post 请求。我想要做的是将两个密钥,即序列号和电源输出发送到 aws 服务器并获得响应。当我使用 postmaster 做同样的事情时,一切正常,但是当我使用我的 nodemcu 时,它以 httpcode 响应:-1。我正在使用的代码附在下面。任何帮助表示赞赏

#include <ESP8266HTTPClient.h>

#include <ESP8266WiFi.h>

无效设置(){

序列号.开始(115200);//串口连接 WiFi.begin("Jinhit_Entertainment", "10813ad0908"); //WiFi连接

while (WiFi.status() != WL_CONNECTED) { //等待 WiFi 连接完成

delay(500);
Serial.println("Waiting for connection");

}

}

无效循环(){

if (WiFi.status() == WL_CONNECTED) { //检查 WiFi 连接状态

HTTPClient http;    //Declare object of class HTTPClient

http.begin("https://uczj81sy9d.execute-api.us-east-1.amazonaws.com/prod/inverterdata");      //Specify request destination
http.addHeader("Content-Type", "text/plain");  //Specify content-type header

int httpCode = http.POST("serialnumber: 4001, poweroutput: 4.1");   //Send the request
String payload = http.getString();                  //Get the response payload

Serial.println(httpCode);   //Print HTTP return code
Serial.println(payload);    //Print request response payload

http.end();  //Close connection

} 别的 {

Serial.println("Error in WiFi connection");

}

延迟(30000);//每30秒发送一个请求

}

标签: amazon-web-servicesarduinohttp-postnodemcuarduino-c++

解决方案


推荐阅读