wemos|物联网-wemos D1 Mini (esp8266)实验三 --- WeMos D1Mini 连接 thingSpeak实时显示室内co2(MQ - 135)浓度
【wemos|物联网-wemos D1 Mini (esp8266)实验三 --- WeMos D1Mini 连接 thingSpeak实时显示室内co2(MQ - 135)浓度】
文章图片
文章图片
#include
#include int CO2Value = https://www.it610.com/article/0;
//MQ135测量到的数值
String UrlString;
//thingSpeak网站发送get请求的url
HTTPClient _httpClient;
//实例一个httpClientint _httpGET(String url) {
_httpClient.end();
_httpClient.begin(url);
return _httpClient.GET();
}void setup() {
pinMode(A0, INPUT);
WiFi.begin(u8"XXXXXXXXXX", u8"XXXXXXXXXXXXXXX");
//接入公网的WiFi的账号密码
while (!(WiFi.status() == WL_CONNECTED)) {
delay(1000);
}}void loop() {
CO2Value = https://www.it610.com/article/analogRead(A0);
//读取MQ135的数据
UrlString = String(u8"http://api.thingspeak.com/update?api_key=XXXXXXXXXXX&field1=") + String(CO2Value);
//XXXX替换为你的APIKeys
if (_httpGET(UrlString) > 0) {
delay(15000);
//thinkSpeak网站限制上传频率 所以这里延时15s
}}
其中appkey在下图这个位置查找
文章图片