amazon-web-services - 使用 Esp8266 ( aws ) 发出 Http 发布请求
问题描述
嗨,我正在尝试从 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秒发送一个请求
}
解决方案
推荐阅读
- android - 如何创建一次性活动
- php - 如何将数组内容日期从当前日期过滤为..?
- java - 将运算符应用于数字的数字以获得所需的数字
- python - 评估列中唯一值的 True 百分比
- ios - 如何检查卡片是否为 Apple Wallet 中的默认支付卡?
- java - NoClassDefFoundError 静态飞行
- maven - 声纳扫描可以作为常规 maven 构建命令的一部分触发,例如“mvn build”吗?
- c# - 如何获取 BIML 脚本中的输出列列表 - 基于列的生成
- ansible - Ansible - 如何在剧本中运行多个任务
- reactjs - 刷新后Material-ui崩溃