Arduino ESP8266 SDK固件版本API差异说明

Arduino ESP8266 SDK固件版本API差异说明
如果还没更新Arduino IDE里面的esp8266固件包的,建议还是不要更新,(目前的版本是3.0.2现在发表文章时的版本。)为什么?因为最新的版本改动很大,很多esp8266库里面的函数,做了很大的变动,直接贸然升级,可能导致原来的程序编译报错。
  • 之前发表的文章,所使用的Arduino esp8266 SDK固件版本都是2.7.4版本,请留意,后续所发布示例程序文章,将会通通备注说明使用的固件版本,至于以前的将不再添加说明了。

🔰举例说明差异

  • 获取网络数据
  • 🌿 2.7.4版本
#include <ESP8266HTTPClient.h>
  ......省略内容......
  HTTPClient http;
  http.begin(url);
  
  • 🌿现在的版本(3.0.2)
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>//新增
  ......省略内容......
  WiFiClient client;//新增
  HTTPClient http;
  http.begin(client,url);//新增形参

📝完整获取网络时间(3.0.2版本的支持库)

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>//新增

const char*ssid="CMCC-DyVv";
const char*password="pba5ayzk";
long int Time;
String Time_api = "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp";
 void setup(){
  Serial.begin(115200);
  WiFi.begin(ssid, password);
    while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }
Serial.printf("WiFi name:%s\n IP Address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());   
}


void loop()
{
 Time = getTimestamp(Time_api); //nowapi时间API
  Serial.println(Time);
  delay(6000);
}

long int getTimestamp(String url)
{
  String Time = "";
  long long Time1;
    WiFiClient client;//新增
  HTTPClient http;
  http.begin(client,url);//新增形参

 // http.begin(url);

  // start connection and send HTTP headerFFF
  int httpCode = http.GET();

  // httpCode will be negative on error
  if (httpCode > 0)
  {
    // file found at server
    if (httpCode == HTTP_CODE_OK)
    {
      String payload = http.getString();
      int pos = (payload.indexOf("data"));
      Time = payload.substring(pos + 12, payload.length() - 6);
      Serial.println(payload.substring(pos + 12, payload.length() - 6));
    }
  }
  else
  {
    Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }
  http.end();
  
  return atoll(Time.c_str());
}


📌更多修改的地方可去国内镜像查看修改的地方

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值