#define BLINKER_WIFI
#define BLINKER_ALIGENIE_SENSOR
//数据存储
#include <Blinker.h>
#define FIRE_Pin A0 // 火焰传感器管脚
char auth[] = "bb2646fb426f";
char ssid[] = "1248L";
char pswd[] = "84491998";
float tempresult = 2000;BlinkerNumber TEMP("temp");
// 新建组件对象
BlinkerButton Button1("btn-111");
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("触发远程关门 ", state);
digitalWrite(D5, !digitalRead(D5));
//查看D5引脚的电平,
并且根据现有电平提高或降低电平,
从而达到控制磁锁的目的
Blinker.vibrate();
}
void heartbeat()
{
TEMP.print(tempresult); //心跳包,用于定时发送数据
}
void dataStorage()
{
Blinker.dataStorage("temp", tempresult);//存储功能的标识
}
void aligenieQuery(int32_t queryCode) //数据查询
{
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("AliGenie Query All");
BlinkerAliGenie.temp(tempresult);
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_TEMP_NUMBER :
BlinkerAliGenie.temp(tempresult);
BlinkerAliGenie.print();
break;
default :
BlinkerAliGenie.temp(20);
BlinkerAliGenie.print();
break;
}
}
void setup() {
// 初始化串口
Serial.begin(9600);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// 初始化wifi
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);
Blinker.attachHeartbeat(heartbeat); //心跳包,用于定时发送数据
BlinkerAliGenie.attachQuery(aligenieQuery); //查询
Blinker.attachDataStorage(dataStorage); //数据存储
pinMode(FIRE_Pin, INPUT);
pinMode(D5, OUTPUT);
digitalWrite(D5,HIGH);
}
void loop() {
Blinker.run();
int val = analogRead(FIRE_Pin); //读取A0口的电压值并赋值digitalRead
tempresult = 2000/val;
if(val > 700)
{
Serial.print("D0: ");
Serial.println(val);
Serial.println(" ");
Serial.println(tempresult);
delay(1500);
} |