4641| 1
|
[项目] IOT-传感发提醒短信给手机 |
物联网时代,IOT将无处不在,这次还是接着上篇的震动传感IOT,更深一步,为它加入事件的手机短信提醒 先简单介绍一下上一篇。 上篇用到的硬件如下 ![]() nodemcu ![]() 震动传感SM-420 ![]() NODEMCU 脚位 ![]() 连线图 ![]() thingspeak.com登录后所见的图表 ![]() thingspeak建立通道 ![]() thingspeak api值 ![]() [mw_shl_code=applescript,true]//--------gada888 撸码------------- #include <ESP8266WiFi.h> String apiKey = "你的apikey"; const char *ssid = "你的WiFi名"; const char *pass = "你的wifi密码"; const char* server = "api.thingspeak.com"; WiFiClient client; //--------------------SETUP--------------- 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"); } //--------------LOOP----------------- void loop(){ float h = analogRead(A0); 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("Noise 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] -------------------- 接下来是pushbullet部分和thingspeak的设置 ![]() PC端登录pushbullet,并从主页下载pushbullet app ![]() ![]() app上选推送,我们先来测试 ![]() pushbullet PC端texting选项下,发送一条短信给手机。手机号码前加国家代号。例如中国是+86,后面跟你的手机号。例如+86186xxxxxxxx 手机上会收到一条你从PC端发的短信。这样证明通讯成功。 ![]() 最后是进行thingspeak和pushbullet的连接。 ![]() 选择thingHTTP ![]() 按照上面来设置HTTP 发送 然后是React来设置应答 ![]() ![]() 设置好保存 ![]() 设置需要的pushbullet token。要保存为txt文件。以备使用。 ![]() 这是手机短信提醒。 提示:震动传感上有个调整旋钮,可以调灵敏度。 |
© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed