blinker接入小爱调节亮度失败-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1725|回复: 3

[已解答] blinker接入小爱调节亮度失败

[复制链接]
发表于 2020-8-15 17:57 | 显示全部楼层 |阅读模式
灯的开关没有问题,小爱可以操作,但是调节亮度的时候小爱提示“哎呀,这个灯不能这么操作哦”

源码:
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET

#include <Blinker.h>

char auth[] = "Your Device Secret Key";//
char ssid[] = "Your WiFi network SSID or name";//
char pswd[] = "Your WiFi network WPA password or WEP key";//

bool oState = false;

void miotPowerState(const String & state)
{
    BLINKER_LOG("need set power state: ", state);

    if (state == BLINKER_CMD_ON) {
        digitalWrite(LED_BUILTIN, HIGH);

        BlinkerMIOT.powerState("on");
        BlinkerMIOT.print();

        oState = true;
    }
    else if (state == BLINKER_CMD_OFF) {
        digitalWrite(LED_BUILTIN, LOW);

        BlinkerMIOT.powerState("off");
        BlinkerMIOT.print();

        oState = false;
    }
}
void miotBright(const String & bright)

{

    BLINKER_LOG("need set brightness: ", bright);

colorW = bright.toInt();
analogWrite(LED_BUILTIN,1023-colorW*10);

    BLINKER_LOG("now set brightness: ", colorW);

    BlinkerMIOT.brightness(colorW);    BlinkerMIOT.print();

}
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.powerState(oState ? "on" : "off");
            BlinkerMIOT.print();
            break;
        case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
            BLINKER_LOG("MIOT Query Power State");
            BlinkerMIOT.powerState(oState ? "on" : "off");
            BlinkerMIOT.print();
            break;
        default :
            BlinkerMIOT.powerState(oState ? "on" : "off");
            BlinkerMIOT.print();
            break;
    }
}

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

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

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.attachPowerState(miotPowerState);
  BlinkerMIOT.attachBrightness(miotBright)
;

    BlinkerMIOT.attachQuery(miotQuery);
}

void loop()
{
    Blinker.run();
}
 楼主| 发表于 2020-8-15 20:04 | 显示全部楼层
我有定义了colorW的,这里忘补进去了
发表于 2020-8-15 23:20 | 显示全部楼层
#define BLINKER_MIOT_OUTLET
是将设备设置为插座

请使用灯的例程
 楼主| 发表于 2020-8-16 13:36 | 显示全部楼层
#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT
#define BLINKER_PRINT Serial

#include <Blinker.h>

char auth[] = "***********";
char ssid[] = "*************";
char pswd[] = "************";

BlinkerButton Button1("btn");
void miotBright(const String & bright)
{
    int colorW;
    BLINKER_LOG("need set brightness: ", bright);

    colorW = bright.toInt();
   
    analogWrite(LED_BUILTIN,1023-colorW*10);
   
    BLINKER_LOG("now set brightness: ", colorW);

    BlinkerMIOT.brightness(colorW);
    BlinkerMIOT.print();
}
void miotPowerState(const String & state)
{
    BLINKER_LOG("need set power state: ", state);

    if (state == BLINKER_CMD_ON) {
        digitalWrite(LED_BUILTIN, LOW);

        BlinkerMIOT.powerState("on");
        BlinkerMIOT.print();
    }
    else if (state == BLINKER_CMD_OFF) {
        digitalWrite(LED_BUILTIN, HIGH);

        BlinkerMIOT.powerState("off");
        BlinkerMIOT.print();
    }
}

void button1_callback(const String & state) {
    BLINKER_LOG("get button state: ", state);
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

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

void setup() {

    Serial.begin(115200);

    #if defined(BLINKER_PRINT)
        BLINKER_DEBUG.stream(BLINKER_PRINT);
    #endif


    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);
    // 初始化blinker
    Blinker.begin(auth, ssid, pswd);
    Blinker.attachData(dataRead);
    Button1.attach(button1_callback);
    BlinkerMIOT.attachPowerState(miotPowerState);
    BlinkerMIOT.attachBrightness(miotBright);
}

void loop() {
    Blinker.run();
}D:\Users\48809\Desktop\微信图片_20200816133249.jpg
微信图片_20200816133249.jpg
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 11:55 , Processed in 0.195576 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表