esp8266-01s加人体热释红外探头做的手机远程报警器
材料:1,esp8266-01s一個(gè)或者esp8266miniD1一個(gè)。
2,人體熱釋紅外感應(yīng)探頭一個(gè)
3,杜邦線三根
工作原理:人體熱釋紅外探頭檢測(cè)到人體信號(hào),通過esp8266-01s上傳到巴法云,然后給微信發(fā)送報(bào)警信息,如果你在家門口按裝一個(gè)報(bào)警器,當(dāng)有人進(jìn)入探頭檢測(cè)范圍內(nèi)(3/5米)。報(bào)警器通過esp8266給微信發(fā)送報(bào)警信息,從而實(shí)現(xiàn)遠(yuǎn)程報(bào)警。
源程序:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#define sensor 2 //紅外傳感器輸入口
/******************************************************************************/
#define DEFAULT_STASSID “LP_360-wifi” //WIFI名稱
#define DEFAULT_STAPSW “123456” //WIFI密碼
String uid = “285293a244b640e5d7de1944ee684f”; // 用戶私鑰,巴法云控制臺(tái)獲取
String type = “1”; // 1表示是預(yù)警消息,默認(rèn)即可
String device = “人體紅外傳感器設(shè)備”; // 設(shè)備名稱
String msg = “警告:有人闖入你家”; //發(fā)送的消息
String msg2 = “手機(jī)遠(yuǎn)程報(bào)警器”; //消息備注,可為空
int delaytime = 0; //為了防止被設(shè)備“騷擾”,可設(shè)置賢者時(shí)間,單位是秒,如果設(shè)置了該值,在該時(shí)間內(nèi)不會(huì)發(fā)消息到微信,設(shè)置為0立即推送。
String ApiUrl = “http://ai.bemfa.com/api/wechat/v1/”; //默認(rèn) api 網(wǎng)址
/******************************************************************************/
static uint32_t lastWiFiCheckTick = 0;
//=======================================================================
// WIFI重新連接函數(shù)
//=======================================================================
void startSTA(){
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(DEFAULT_STASSID, DEFAULT_STAPSW);
}
//=======================================================================
// WIFI狀態(tài)檢測(cè)函數(shù),如果WIFI斷開自動(dòng)重連
//=======================================================================
void doWiFiTick()
{
if(WiFi.status() != WL_CONNECTED)
{
if(millis() - lastWiFiCheckTick > 1000)
{
lastWiFiCheckTick = millis();
startSTA();
}
}
}
void setup() {
pinMode(sensor, INPUT); // declare sensor as input
delay(1000);
Serial.begin(115200); //Prevents reconnection issue (taking too long to connect)
delay(1000);
WiFi.mode(WIFI_STA); //This line hides the viewing of ESP as wifi hotspot
WiFi.begin(DEFAULT_STASSID, DEFAULT_STAPSW); //Connect to your WiFi router
Serial.println("");
Serial.print(“Connecting”);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
//If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println(DEFAULT_STASSID);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
}
//=======================================================================
// 主循環(huán)
//=======================================================================
void loop() {
doWiFiTick();
}
//微信消息推送函數(shù)**//
void doHttpStick(){ //微信消息推送函數(shù)
HTTPClient http; //Declare object of class HTTPClient
String postData;
//Post Data
postData = “uid=”+uid+"&type=" + type +"&time="+delaytime+"&device="+device+"&msg="+msg+"&msg2="+msg2;
http.begin(ApiUrl); //Specify request destination
http.addHeader(“Content-Type”, “application/x-www-form-urlencoded”); //Specify content-type header
int httpCode = http.POST(postData); //Send the request
String payload = http.getString(); //Get the response payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
Serial.println(“send success”);
}
//=======================================================================[/mw_shl_code]
總結(jié)
以上是生活随笔為你收集整理的esp8266-01s加人体热释红外探头做的手机远程报警器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (Docker)Centos docke
- 下一篇: 关闭WIN10的wsappx进程服务