#define BLINKER_WIFI
#define BLINKER_MIOT_SENSOR //小爱同学定义为传感器设备
#include <Blinker.h>
#include "SparkFun_SHTC3.h"
char auth[] = "72290821bdd3"; //设备key
char ssid[] = "CMCC-QR9a"; //wifi ssid
char pswd[] = "un98pchd"; //wifi 密码
BlinkerNumber HUMI("humi"); //定义湿度数据键名
BlinkerNumber TEMP("temp"); //定义温度数据键名
SHTC3 mySHTC3;
float humi_read = 0, temp_read = 0;
void dataStorage()
{
Blinker.dataStorage("temp", temp_read);
Blinker.dataStorage("humi", humi_read);
}
void heartbeat()
{
HUMI.print(humi_read); //给blinkerapp回传湿度数据
TEMP.print(temp_read); //给blinkerapp回传温度数据
}
void miotQuery(int32_t queryCode) //小爱同学语音命令反馈
{
BLINKER_LOG("MIOT Query codes: ", queryCode);
int humi_read_int=humi_read; //去掉湿度浮点
BlinkerMIOT.humi(humi_read_int); //小爱接收湿度
BlinkerMIOT.temp(temp_read); //小爱接收温度
BlinkerMIOT.print();
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);//数据上传
Blinker.attachDataStorage(dataStorage);//图表上传
Wire.begin();
errorDecoder(mySHTC3.begin());
BlinkerMIOT.attachQuery(miotQuery);//小爱
}
void loop()
{
Blinker.run();
float h = mySHTC3.toPercent();
float t = mySHTC3.toDegC();
if (isnan(h) || isnan(t))
{
BLINKER_LOG("无法读取DHT数据!");
}
else
{
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
humi_read = h;
temp_read = t;
}
SHTC3_Status_TypeDef result = mySHTC3.update();
Blinker.delay(2000);
}
void errorDecoder(SHTC3_Status_TypeDef message)
{
switch(message)
{
case SHTC3_Status_Nominal : Serial.print("Nominal"); break;
case SHTC3_Status_Error : Serial.print("Error"); break;
case SHTC3_Status_CRC_Fail : Serial.print("CRC Fail"); break;
default : Serial.print("Unknown return code"); break;
}
}
配置文件
{¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨light¨¨background¨{¨img¨¨assets/img/bg/2.jpg¨}}¨dashboard¨|{¨type¨¨num¨¨t0¨¨湿度¨¨ico¨¨fal fa-question¨¨clr¨¨#389BEE¨¨min¨É¨max¨¢1c¨uni¨´%´¨bg¨É¨cols¨Í¨rows¨Í¨key¨¨humi¨´x´É´y´Ð¨speech¨|÷¨lstyle¨Ë}{ß9ßAßB¨温度¨ßDßEßF¨#EA0909¨ßHÉßIº0ßJ´℃´ßKÉßLÍßMÍßN¨temp¨´x´Í´y´ÐßP|÷ßQË}{ß9¨deb¨¨mode¨ÉßKÉßLÑßMÍßN¨debug¨´x´É´y´¤CßP|÷ßQÊ}{ß9¨cha¨ßKɨsty¨¨line¨ßF¨#076EEF¨¨sty1¨ßZ¨clr1¨ßS¨sty2¨ßZ¨clr2¨ßGßLÑßMÍßNßO´x´É´y´ËßP|÷ßQÊßBßC¨key1¨ßT¨t1¨ßR}÷¨actions¨|¦¨cmd¨¦¨switch¨‡¨text¨‡¨on¨¨打开?name¨¨off¨¨关闭?name¨—÷¨triggers¨|{¨source¨ßj¨source_zh¨¨开关状态¨¨state¨|ßlßn÷¨state_zh¨|¨打开¨¨关闭¨÷}÷}