[Arduino物联网开发实战2]数据反馈-Arduino中文社区 - Powered by Discuz! Archiver

奈何col 发表于 2020-5-7 18:55

huanglecheg 发表于 2020-5-7 17:26
你好,请问Button1.print("on");这个具体是什么意思,开发文档里面写的是发送按键当前的状态(多用于开关模 ...

向app反馈该button组件状态为on

xbdbox 发表于 2020-5-21 18:48

goodstudy 发表于 2019-4-21 14:38
希望解答一下,多谢了。

LOW不是关灯,是低电平,低电平开灯。

aotmhhh 发表于 2020-5-29 18:10


数据传过去了但是组件没反应怎么回事...
In file included from D:\Arduino\libraries\blinker-library-master\src/BlinkerSerialBLE.h:25:0,

               from D:\Arduino\libraries\blinker-library-master\src/Blinker.h:21,

               from C:\Users\Administrator\Desktop\sketch_may29a\sketch_may29a.ino:4:

D:\Arduino\libraries\blinker-library-master\src/Adapters/BlinkerSerial.h: In member function 'virtual char* BlinkerSerial::lastRead()':

D:\Arduino\libraries\blinker-library-master\src/Adapters/BlinkerSerial.h:36:75: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

         char * lastRead()   { if (isFresh) return streamData; else return ""; }

                                                                           ^~

In file included from D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h:83:0,

               from D:\Arduino\libraries\blinker-library-master\src/BlinkerSerialBLE.h:26,

               from D:\Arduino\libraries\blinker-library-master\src/Blinker.h:21,

               from C:\Users\Administrator\Desktop\sketch_may29a\sketch_may29a.ino:4:

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerProtocol.h: In member function 'char* BlinkerProtocol::dataParse()':

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerProtocol.h:234:86: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

         char* dataParse()       { if (canParse) return conn->lastRead(); else return ""; }

                                                                                    ^~

In file included from D:\Arduino\libraries\blinker-library-master\src/BlinkerSerialBLE.h:26:0,

               from D:\Arduino\libraries\blinker-library-master\src/Blinker.h:21,

               from C:\Users\Administrator\Desktop\sketch_may29a\sketch_may29a.ino:4:

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h: At global scope:

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h:777:97: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

         BlinkerWidgets_string _BUILTIN_SWITCH = BlinkerWidgets_string(BLINKER_CMD_BUILTIN_SWITCH);

                                                                                                 ^

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h: In member function 'char* BlinkerApi::widgetName_str(uint8_t)':

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h:7012:17: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   else return "";

               ^~

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h: In member function 'char* BlinkerApi::widgetName_joy(uint8_t)':

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h:7019:21: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

         else return "";

                     ^~

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h: In member function 'char* BlinkerApi::widgetName_rgb(uint8_t)':

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h:7026:17: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   else return "";

               ^~

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h: In member function 'char* BlinkerApi::widgetName_int(uint8_t)':

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h:7032:17: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   else return "";

               ^~

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h: In member function 'char* BlinkerApi::widgetName_tab(uint8_t)':

D:\Arduino\libraries\blinker-library-master\src/Blinker/BlinkerApi.h:7038:17: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   else return "";

               ^~

C:\Users\Administrator\Desktop\sketch_may29a\sketch_may29a.ino: At global scope:

C:\Users\Administrator\Desktop\sketch_may29a\sketch_may29a.ino:6:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

BlinkerNumber HUMI("humi");

                        ^

C:\Users\Administrator\Desktop\sketch_may29a\sketch_may29a.ino:7:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

BlinkerNumber TEMP("temp");

                        ^

dillonning 发表于 2020-6-8 12:21

谢谢分享,学习了

molun 发表于 2020-7-12 21:31

这两个的差异是?
#define BLINKER_WIFI
#define BLINKER_MIOT_SENSOR

#include <Blinker.h>

char auth[] = "93******83"; // Blinker APP中添加设备时生成的Secret Key
char ssid[] = "ty****op"; // WIFI名称
char pswd[] = "********"; // WIFI密码

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

// Download Adafruit DHT-sensor-library library here:
// https://github.com/adafruit/DHT-sensor-library
#include <DHT.h>

#define DHTPIN 2

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

DHT dht(DHTPIN, DHTTYPE);

uint32_t read_time = 0;

float humi_read, temp_read;

void miotQuery(int32_t queryCode)
{
    BLINKER_LOG("MIOT Query codes: ", queryCode);

    switch (queryCode)
    {
      case BLINKER_CMD_QUERY_ALL_NUMBER :
            BLINKER_LOG("MIOT Query All");
            BlinkerMIOT.temp(20);
            BlinkerMIOT.humi(20);
            BlinkerMIOT.pm25(20);
            BlinkerMIOT.co2(20);
            BlinkerMIOT.print();
            break;
      default :
            BlinkerMIOT.temp(20);
            BlinkerMIOT.humi(20);
            BlinkerMIOT.pm25(20);
            BlinkerMIOT.co2(20);
            BlinkerMIOT.print();
            break;
    }
}

void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);

    Blinker.vibrate();
   
    uint32_t BlinkerTime = millis();
   
    Blinker.print("millis", BlinkerTime);
}

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

void setup()
{
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);

    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);

    Blinker.begin(auth, ssid, pswd);
    Blinker.attachData(dataRead);

    BlinkerMIOT.attachQuery(miotQuery);

    Blinker.attachHeartbeat(heartbeat);
   
    dht.begin();
}

void loop()
{
    Blinker.run();
   
    if (read_time == 0 || (millis() - read_time) >= 2000)
    {
      read_time = millis();

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

      if (isnan(h) || isnan(t)) {
            BLINKER_LOG("Failed to read from DHT sensor!");
            return;
      }

      float hic = dht.computeHeatIndex(t, h, false);

      humi_read = h;
      temp_read = t;

      BLINKER_LOG("Humidity: ", h, " %");
      BLINKER_LOG("Temperature: ", t, " *C");
      BLINKER_LOG("Heat index: ", hic, " *C");
    }
}

molun 发表于 2020-7-12 21:32

molun 发表于 2020-7-12 21:31
这两个的差异是?

这个小爱同学查询不到是什么情况?

molun 发表于 2020-7-12 21:33

    else if (state == BLINKER_CMD_ON) {
      BLINKER_LOG("Toggle on!");

      Button1.icon("fal fa-light-switch-on");
      Button1.color("#0000FF");
      Button1.text("ON");
      Button1.print("on");

// 心跳包函数
void heartbeat() {
    Button1.icon("fas fa-lightbulb");
    Button1.color("#fddb00");
    Button1.text("关灯","打开啦");
    Button1.print("on");
}


这两地方效果有啥不一样?

奈何col 发表于 2020-7-12 22:36

molun 发表于 2020-7-12 21:33
这两地方效果有啥不一样?

第一个是响应开关动作,第二个是响应心跳查询

molun 发表于 2020-7-12 23:11

奈何col 发表于 2020-7-12 22:36
第一个是响应开关动作,第二个是响应心跳查询

感谢解答

13580445117 发表于 2020-7-13 18:24

楼主,没加心跳包可以,加了之后没反应
页: 1 2 3 4 5 6 [7] 8 9 10 11 12 13 14
查看完整版本: [Arduino物联网开发实战2]数据反馈