编程语言   发布时间:2022-06-22  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了esp8266+http (PlatformIO)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

esp8266 + http

使用esp8266发起http请求
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266httpClient.h>

#define led_1 2

const char *SSID = "优美屋205";
const char *passworD = "18111549";
const char *URL = "http://192.168.124.17:3000/users";

void init_wifi();
void esp8266http(); // http

httpClient httpClient;
WiFiClient client;

void setup() {
  serial.begin(115200);
  pinMode(led_1, OUTPUT);
  init_wifi();
}

void loop() {
  digitalWrite(led_1, LOW);
  delay(500);
  digitalWrite(led_1, HIGH);
  delay(500);
  esp8266http();
}

void init_wifi(){
  serial.println("连接中...");
  serial.println(SSID);

  WiFi.begin(SSID, passworD);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    serial.print(".");
  }

  serial.print("IP:");
  serial.println(WiFi.localIP());
  
}

void esp8266http(){
  httpClient.begin(client, URL);
  int httpResponseCode = httpClient.GET();

  if(httpResponseCode > 0){
    serial.print("http Response code: ");
    serial.println(httpResponseCodE);
    String payload = httpClient.getString();
    serial.println(payload);
  }else{
    serial.print("Error code:");
    serial.println(httpResponseCodE);
  }
  // 结束
  httpClient.end();
}

大佬总结

以上是大佬教程为你收集整理的esp8266+http (PlatformIO)全部内容,希望文章能够帮你解决esp8266+http (PlatformIO)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。