码迷,mamicode.com
首页 > Web开发 > 详细

Arduino ESP32 发送HTTP请求

时间:2020-12-31 12:49:50      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:for   nec   tpc   class   div   ret   loop   include   turn   

参考:https://www.qutaojiao.com/8043.html

ESP8266的HTTP请求:http://www.taichi-maker.com/homepage/iot-development/iot-dev-reference/esp8266-c-plus-plus-reference/esp8266httpclient/

Arduino中的示例HTTPClient中的BasicHTTPClient和BasicHTTPSClient可以作为参考

#include <WiFi.h>
#include <HTTPClient.h>
 
const char* ssid = "hg2020";
const char* password =  "12345678";
 
void setup() {
 
  Serial.begin(115200);
  delay(400);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
 
  Serial.println("Connected to the WiFi network");
 
}
 
void loop() {
 
  if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
 
    HTTPClient http;
 
    http.begin("http://quan.suning.com/getSysTime.do"); //Specify the URL
    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(1000);
 
}

  

 

Arduino ESP32 发送HTTP请求

标签:for   nec   tpc   class   div   ret   loop   include   turn   

原文地址:https://www.cnblogs.com/dengziqi/p/14196706.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!