2019-12-28 23:23:34 [显示全部楼层]
2031浏览
查看: 2031|回复: 1

[项目] 无论何时何地查看家里的煤气值

[复制链接]
这是个物联网IOT时代,万物互联的一天一定会到来。

今天介绍的是一个煤气IOT项目。

用到的模块如下
无论何时何地查看家里的煤气值图1
ESP8266
无论何时何地查看家里的煤气值图2
MQ7烟雾模块

无论何时何地查看家里的煤气值图3
连线图
代码部分
[mw_shl_code=applescript,true]//-----------gada888----------
#include <ESP8266WiFi.h>
String apiKey = "";
const char *ssid = "";
const char *pass = "";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
float h = analogRead(A0);
if (isnan(h))
{
Serial.println("Failed to read from MQ-5 sensor!");
return;
}

if (client.connect(server, 80))
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(h/1023*100);
postStr += "r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Gas Level: ");
Serial.println(h/1023*100);
Serial.println("Data Send to Thingspeak");
}
client.stop();
Serial.println("Waiting...");

// thingspeak needs minimum 15 sec delay between updates.
delay(1500);
}[/mw_shl_code]

-------------
String apiKey = ""; ----------thingspeak API密码
const char *ssid = ""; --------wifi名
const char *pass = "";---------wifi密码
------------以上三项要填个人的信息
无论何时何地查看家里的煤气值图4
无论何时何地查看家里的煤气值图5
thingspeak.com注册账号
无论何时何地查看家里的煤气值图6
上图是在网站注册后看到的页面。


无论何时何地查看家里的煤气值图7
记得这个号,在下面的手机app段有用到。
无论何时何地查看家里的煤气值图8
下载这个安卓app
无论何时何地查看家里的煤气值图10add chanell里填入你的channel id。六位数字,以及你的readable API(读取API)
这是手机app页面的实时Gas读数。
无论何时何地查看家里的煤气值图9

这时候只要项目通电,那么你在任何有wifi的地方就可以通过手机看到气体传感的读数。



kylinpoet  初级技神

发表于 2020-2-18 16:57:33

楼主强大,多谢分享。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail