|
楼主 |
发表于 2020-8-19 19:34
|
显示全部楼层
本帖最后由 Nicetrip 于 2020-8-19 19:42 编辑
奈何col你好, 你所说的向其他KEY存数据我没能理解。所谓的5个《数据存储 独立设备 共计5个Key》 是账号下所有设备的数据字段数量之和不能超过5个还是 每个设备的数据字段数量不能超过5个?
奈何col你好, 你所说的向其他KEY存数据我没能理解。所谓的5个《数据存储 独立设备 共计5个Key》 是账号下所有设备的数据字段数量之和不能超过5个还是 每个设备的数据字段数量不能超过5个? 下边的代码除了密钥不同外,被刷入连个相同的设备,这样会引起数据存储冲突吗?
/*
*/
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_SENSOR
#define BLINKER_PRINT Serial
#include <Blinker.h>
#include <DHT.h>
char auth[] = "xxxxxxxx";//
char ssid[] = "xxxxxxxx";
char pswd[] = "xxxxxxxx";
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
BlinkerNumber GZ("sv");
BlinkerNumber TR("turang");
BlinkerButton Button1("btn-01");
BlinkerNumber Number1("num-01");
BlinkerButton Button2("btn-02");
BlinkerNumber Number2("num-02");//blinker-APP按键要与引号中的字符相同
BlinkerButton Button3("btn-03");
BlinkerNumber Number3("num-03");//blinker-APP按键要与引号中的字符相同
int counter = 0;
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
void button2_callback(const String & b) {
BLINKER_LOG("get button state: ", b);
digitalWrite(21, !digitalRead(21));
}
void button3_callback(const String & aaa) {
BLINKER_LOG("get button state: ", aaa);
digitalWrite(22, !digitalRead(22));
}
#define DHTPIN 17 //ARDUINO D1板直接接到 D9
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
float humi_read = 0, temp_read = 0,sv_read = 0,turang_read=0;
void heartbeat()
{
HUMI.print(humi_read);
TEMP.print(temp_read);
GZ.print(sv_read);
TR.print(turang_read);
}
void dataStorage()
{
Blinker.dataStorage("temp", temp_read);
Blinker.dataStorage("humi", humi_read);
Blinker.dataStorage("sv",sv_read);
Blinker.dataStorage("turang",turang_read);
}
void aligenieQuery(int32_t queryCode)
{
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("AliGenie Query All");
BlinkerAliGenie.temp(temp_read);
BlinkerAliGenie.humi(humi_read);
// Blinker.dataStorage(sv_read);
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_TEMP_NUMBER :
BlinkerAliGenie.temp(temp_read);
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_HUMI_NUMBER :
BlinkerAliGenie.humi(humi_read);
BlinkerAliGenie.print();
break;
default :
BlinkerAliGenie.temp(20);
BlinkerAliGenie.humi(20);
BlinkerAliGenie.print();
break;
}
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
BlinkerAliGenie.attachQuery(aligenieQuery);
Blinker.attachDataStorage(dataStorage);
dht.begin();
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
pinMode(21, OUTPUT);
pinMode(22, OUTPUT);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
}
void loop()
{
Blinker.run();
float h = dht.readHumidity();
float t = dht.readTemperature();
int tr = analogRead(A3);
int s = analogRead(A0);
s=2600-s;
if (isnan(h) || isnan(t))
{
BLINKER_LOG("Failed to read from DHT sensor!");
}
else
{
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
BLINKER_LOG("RG: ", s);
BLINKER_LOG("TR: ", tr);
humi_read = h;
temp_read = t;
sv_read=s;
turang_read=tr;
}
Blinker.delay(2000);
}
|
|