基于blinker,用小爱温湿度查询,程序为何不进入case语句中?-Arduino中文社区 - Powered by Discuz! Archiver

大路附近 发表于 2020-2-19 13:40

基于blinker,用小爱温湿度查询,程序为何不进入case语句中?

我用DHT11做的温湿度计,但是小爱同学一直读取的是switch中的default部分,这是为什么呢?

#define BLINKER_WIFI
#define BLINKER_MIOT_SENSOR
#include <Blinker.h>

#include <DHT.h>

char auth[] = "4a4961b42827";
char ssid[] = "ChinaNet-wxM3";
char pswd[] = "2nm9r5w6";

BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");

#define DHTPIN D3

#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22(AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

float temp_read = 0;
int8_t humi_read = 0;

void miotQuery(int32_t queryCode)//用户自定义设备查询的回调函数
{
    BLINKER_LOG("MIOT Query codes: ", queryCode);

    switch (queryCode)
    {
//      case BLINKER_CMD_QUERY_PM25_NUMBER :
//            BLINKER_LOG("MIOT Query PM25");
//            BlinkerMIOT.pm25(20);
//            BlinkerMIOT.print();
//            break;
      case BLINKER_CMD_QUERY_HUMI_NUMBER :
            BLINKER_LOG("MIOT Query HUMI");
            BlinkerMIOT.humi(humi_read);
            BlinkerMIOT.print();
            break;
      case BLINKER_CMD_QUERY_TEMP_NUMBER :
            BLINKER_LOG("MIOT Query TEMP");
            BlinkerMIOT.temp(temp_read);
            BlinkerMIOT.print();
            break;
//      case BLINKER_CMD_QUERY_TIME_NUMBER :
//            BLINKER_LOG("MIOT Query Time");
//            BlinkerMIOT.time(millis(20));
//            BlinkerMIOT.print();
//            break;
      default :
            BLINKER_LOG("小爱查询了默认数据");
            BlinkerMIOT.temp(temp_read);
            BlinkerMIOT.humi(humi_read);
         //   BlinkerMIOT.pm25(20);
         // BlinkerMIOT.co2(20);
            BlinkerMIOT.print();
            break;
    }
}


void heartbeat()
{
    HUMI.print(humi_read);
    TEMP.print(temp_read);
}

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);
    BlinkerMIOT.attachQuery(miotQuery);
    dht.begin();
}

void loop()
{
    Blinker.run();

    int8_t h = dht.readHumidity();
    float t = dht.readTemperature();

    if (isnan(h) || isnan(t))
    {
      BLINKER_LOG("Failed to read from DHT sensor!");
    }
    else
    {
      BLINKER_LOG("Humidity: ", h, " %");//blinker串口打印函数
      BLINKER_LOG("Temperature: ", t, " *C");
         BLINKER_LOG("----------------");
      humi_read = h;
      temp_read = t;
    }

    Blinker.delay(2000);
}




奈何col 发表于 2020-2-20 01:59

貌似因为小爱发来的就是全部查询指令

大路附近 发表于 2020-2-19 13:45

Humidity: 93 %
Temperature: 18.40 *C
----------------
Got: {"deviceType":"DiyArduino","data":{"get":"state"},"fromDevice":"MIOT","toDevice":"51EA341ECBKJYTFIVRFGS41F"}
data: {"get":"state"}
fromDevice: MIOT
form MIOT
MIOT parse data: {"get":"state"}
MIOT Query codes: 0
小爱查询了默认数据
response to MIOT: {"temp":"18.40","humi":"93"}
isJson: {"data":{"temp":"18.40","humi":"93"},"fromDevice":"51EA341ECBKJYTFIVRFGS41F","toDevice":"MIOT_r","deviceType":"vAssistant"}
MQTT MIOT Publish...
Freeheap: 9352
{"data":{"temp":"18.40","humi":"93"},"fromDevice":"51EA341ECBKJYTFIVRFGS41F","toDevice":"MIOT_r","deviceType":"vAssistant"}
...OK!
Freeheap: 9352
Humidity: 93 %
Temperature: 18.40 *C
----------------
Humidity: 93 %
Temperature: 18.40 *C
----------------

大路附近 发表于 2020-2-19 13:52

为什么小爱查询温度和湿度的MIOT Query codes都是0呢?

Guofuqiang01 发表于 2021-3-23 12:38

:'(一直以为我看不懂串口监视器,群里还有人说我缺少自定义宏。终于看到原来小爱反馈的就都是“0”,不过我通过测试多插孔模式,用void miotQuery(int32_t queryCode,int num)查询不同插孔状态,查询几号插孔num就返回数字几。
页: [1]
查看完整版本: 基于blinker,用小爱温湿度查询,程序为何不进入case语句中?