esp01s改造老旧吸尘器连入天猫精灵语音控制
esp01s改造老旧吸尘器连入天猫精灵语音控制
利用esp01s加红外遥控二极管,实现天猫精灵语音控制扫地机(科沃斯CEN540)启动、回充
1、用到的元器件
- esp01s模块
- 红外led灯
- NPN三极管s8050,1个
- 限流电阻200——500Ω均可,2个
2、电路
s8050发射极接esp01s的GND,基极接限流电阻后接esp01s的3脚(RXD),集电极接限流电阻,再接led负极回到esp01s的VCC,esp01s模块从扫地机内esp_wroom模块取电。
3、代码
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_OUTLET
#define BLINKER_WIFI_MULTI
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <Blinker.h>char auth[] = "xxx";
char ssid[] = "TP-LINK_46AB";
char pswd[] = "xxx..";char ssid1[] = "TP_LINK_820F";
char pswd1[] = "xxx";char ssid2[] = "sxbctvnet-ehh24";
char pswd2[] = "xxx";const uint16_t kIrLed = 3; // RXD.IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.//红外遥控指令
//上
uint16_t upData[67] = {9014, 4538, 634, 498, 554, 572, 554, 596, 534, 596, 534, 576, 552, 596, 534, 1708, 550, 596, 532, 1750, 508, 598, 530, 1726, 532, 598, 530, 1728, 542, 586, 542, 1738, 526, 602, 528, 576, 554, 1730, 532, 574, 556, 1728, 534, 594, 534, 1724, 534, 594, 534, 1724, 538, 1722, 532, 596, 532, 1752, 508, 596, 532, 1726, 532, 598, 530, 1750, 506, 598, 550}; // NEC 2AA55AA
//下
uint16_t downData[67] = {9010, 4526, 572, 556, 572, 578, 550, 578, 550, 558, 572, 558, 570, 558, 570, 1708, 550, 562, 568, 1736, 524, 606, 524, 1734, 522, 582, 548, 1734, 526, 580, 550, 1734, 498, 630, 500, 628, 502, 1758, 546, 1688, 574, 556, 574, 578, 550, 1708, 550, 1710, 550, 580, 550, 1692, 568, 562, 568, 580, 548, 1736, 524, 1736, 524, 606, 524, 606, 522, 1712, 524}; // NEC 2AA6699
//左
uint16_t leftData[67] = {9018, 4542, 556, 594, 534, 596, 534, 594, 534, 594, 534, 594, 534, 576, 554, 1726, 532, 596, 534, 1750, 506, 622, 508, 1728, 530, 620, 506, 1728, 530, 598, 546, 1714, 550, 576, 554, 600, 528, 576, 554, 1708, 554, 1704, 556, 574, 556, 572, 556, 1724, 534, 1704, 554, 1724, 534, 1750, 506, 622, 506, 622, 508, 1726, 532, 1728, 530, 598, 530, 622, 524}; // NEC 2AA33CC
//右
uint16_t rightData[67] = {9016, 4564, 532, 574, 554, 574, 554, 596, 532, 576, 552, 578, 552, 596, 534, 1726, 532, 596, 532, 1750, 506, 598, 530, 1752, 506, 622, 506, 1728, 524, 604, 524, 1756, 526, 578, 550, 578, 552, 1706, 556, 574, 554, 574, 556, 572, 558, 1702, 558, 596, 532, 572, 556, 1726, 530, 578, 552, 1726, 532, 1752, 506, 1726, 530, 600, 530, 1730, 528, 1748, 524}; // NEC 2AA44BB
//CLEAN
uint16_t clearData[67] = {8990, 4538, 558, 596, 534, 594, 534, 576, 554, 596, 534, 576, 554, 596, 534, 1726, 534, 596, 534, 1750, 508, 598, 530, 1752, 508, 598, 532, 1750, 500, 628, 520, 1738, 526, 578, 552, 600, 528, 576, 554, 1706, 554, 596, 534, 572, 558, 594, 534, 1724, 534, 596, 532, 1704, 554, 1706, 550, 596, 534, 1726, 530, 1750, 508, 1726, 530, 622, 508, 1750, 524}; // NEC 2AA22DD
//PLAN
//uint16_t rawData[99] = {9020, 4566, 532, 596, 534, 596, 534, 596, 534, 576, 552, 576, 556, 594, 534, 1726, 534, 580, 550, 596, 534, 1730, 530, 622, 508, 1728, 532, 622, 508, 1728, 546, 584, 546, 1736, 528, 578, 554, 600, 530, 600, 530, 600, 532, 574, 556, 574, 556, 572, 558, 570, 558, 1726, 534, 1728, 534, 1726, 534, 1726, 532, 1752, 508, 1730, 530, 1754, 506, 1726, 544, 1740, 526, 578, 552, 602, 528, 576, 552, 600, 530, 576, 554, 576, 554, 574, 556, 1704, 556, 1726, 534, 596, 534, 1706, 556, 576, 552, 1728, 532, 1752, 508, 1730, 530}; // UNKNOWN 9AF51A45
//延边
uint16_t roundData[67] = {8996, 4568, 534, 576, 552, 578, 554, 598, 530, 598, 530, 578, 552, 598, 532, 1728, 532, 598, 530, 1734, 528, 600, 530, 1756, 506, 602, 528, 1732, 526, 604, 526, 1734, 548, 606, 526, 582, 548, 1710, 554, 1708, 552, 1706, 554, 578, 552, 1710, 550, 1730, 530, 1732, 530, 1754, 504, 600, 532, 600, 528, 600, 528, 1730, 528, 600, 530, 602, 526, 604, 524}; // NEC 2AA7788
//回充
uint16_t gohomeData[67] = {9020, 4544, 554, 576, 554, 596, 532, 576, 554, 578, 552, 598, 532, 596, 532, 1728, 532, 598, 532, 1726, 532, 622, 506, 1728, 530, 624, 508, 1750, 500, 628, 500, 1734, 548, 582, 548, 1734, 532, 574, 554, 598, 530, 598, 532, 1728, 532, 596, 532, 596, 532, 598, 532, 596, 536, 1722, 532, 1726, 532, 1728, 530, 622, 506, 1732, 528, 1754, 506, 1732, 548}; // NEC 2AA8877
//定点
uint16_t rawData[67] = {9018, 4566, 530, 576, 554, 578, 552, 598, 532, 576, 554, 598, 532, 598, 532, 1710, 548, 598, 532, 1732, 526, 624, 506, 1754, 504, 626, 504, 1754, 504, 602, 524, 1756, 526, 602, 526, 1708, 550, 580, 552, 576, 554, 1706, 554, 1728, 532, 598, 532, 598, 532, 1706, 554, 596, 532, 1728, 532, 1730, 530, 600, 530, 602, 528, 1732, 528, 1754, 504, 626, 502}; // NEC 2AA9966BlinkerButton ButtonUp("btn-up");
BlinkerButton ButtonDown("btn-down");
BlinkerButton ButtonLeft("btn-left");
BlinkerButton ButtonRight("btn-right");
BlinkerButton ButtonClear("btn-clear");
BlinkerButton ButtonRound("btn-round");
BlinkerButton ButtonGohome("btn-gohome");
BlinkerButton ButtonRaw("btn-raw");
BlinkerNumber Number1("num-abc");int counter = 0;void buttonup_callback(const String & state)
{irsend.sendRaw(upData, 67, 38);BLINKER_LOG("up");
}
void buttondown_callback(const String & state)
{irsend.sendRaw(downData, 67, 38);BLINKER_LOG("down");
}
void buttonleft_callback(const String & state)
{irsend.sendRaw(leftData, 67, 38);BLINKER_LOG("left");
}
void buttonright_callback(const String & state)
{irsend.sendRaw(rightData, 67, 38);BLINKER_LOG("right");
}
void buttonclear_callback(const String & state)
{irsend.sendRaw(clearData, 67, 38);BLINKER_LOG("clear");
}
void buttonround_callback(const String & state)
{irsend.sendRaw(roundData, 67, 38);BLINKER_LOG("round");
}
void buttongohome_callback(const String & state)
{irsend.sendRaw(gohomeData, 67, 38);BLINKER_LOG("gohome");
}
void buttonraw_callback(const String & state)
{irsend.sendRaw(rawData, 67, 38);BLINKER_LOG("raw");
}void dataRead(const String & data)
{BLINKER_LOG("Blinker readString: ", data);counter++;Number1.print(counter);
}void aligeniePowerState(const String & state)
{BLINKER_LOG("need set power state: ", state);if (state == BLINKER_CMD_ON) {irsend.sendRaw(clearData, 67, 38);//发送启动指令BLINKER_LOG("on");BlinkerAliGenie.powerState("on");BlinkerAliGenie.print();delay(10000);irsend.sendRaw(downData, 67, 38);//开启强力模式BLINKER_LOG("max");}else if (state == BLINKER_CMD_OFF) {irsend.sendRaw(gohomeData, 67, 38);//发送回充指令BlinkerAliGenie.powerState("off");BlinkerAliGenie.print();BLINKER_LOG("off");}
}void heartbeat()
{BLINKER_LOG("heartbeat!");
}void setup(){Serial.begin(115200);BLINKER_DEBUG.stream(Serial);BLINKER_DEBUG.debugAll();irsend.begin(); digitalWrite(2,HIGH);//关闭板载LEDBlinker.addAP(ssid2, pswd2);Blinker.addAP(ssid1, pswd1);Blinker.begin(auth, ssid, pswd);Blinker.attachData(dataRead);ButtonUp.attach(buttonup_callback);ButtonDown.attach(buttondown_callback);ButtonLeft.attach(buttonleft_callback);ButtonRight.attach(buttonright_callback);ButtonClear.attach(buttonclear_callback);ButtonRound.attach(buttonround_callback);ButtonGohome.attach(buttongohome_callback);ButtonRaw.attach(buttonraw_callback);Blinker.attachHeartbeat(heartbeat);BlinkerAliGenie.attachPowerState(aligeniePowerState);
}void loop(){Blinker.run();
}