Arduino ESP8266 SDK固件版本API差异说明
如果还没更新Arduino IDE里面的esp8266固件包的,建议还是不要更新,(目前的版本是3.0.2现在发表文章时的版本。)为什么?因为最新的版本改动很大,很多esp8266库里面的函数,做了很大的变动,直接贸然升级,可能导致原来的程序编译报错。
- 之前发表的文章,所使用的Arduino esp8266 SDK固件版本都是2.7.4版本,请留意,后续所发布示例程序文章,将会通通备注说明使用的固件版本,至于以前的将不再添加说明了。
🔰举例说明差异
#include <ESP8266HTTPClient.h>
......省略内容......
HTTPClient http;
http.begin(url);
#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);
Serial.println(Time);
delay(6000);
}
long int getTimestamp(String url)
{
String Time = "";
long long Time1;
WiFiClient client;
HTTPClient http;
http.begin(client,url);
int httpCode = http.GET();
if (httpCode > 0)
{
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());
}
📌更多修改的地方可去国内镜像查看修改的地方