点灯科技blinker通过esp8266远程控制美的空调开关的Arduino代码

美的空调代码臭又长,不好弄。由于路由器绑定网卡MAC,使用了set_mac函数更新了esp8266的mac地址,不需要的话setup了注释掉,auth,路由器名字密码改成自己的就行。冷热开机更换button里的sendRaw函数内容即可。

/* *****************************************************************
 *
 * Download latest Blinker library here:
 * https://github.com/blinker-iot/blinker-library/archive/master.zip
 * 
 * 
 * Blinker is a cross-hardware, cross-platform solution for the IoT. 
 * It provides APP, device and server support, 
 * and uses public cloud services for data transmission and storage.
 * It can be used in smart home, data monitoring and other fields 
 * to help users build Internet of Things projects better and faster.
 * 
 * Make sure installed 2.7.4 or later ESP8266/Arduino package,
 * if use ESP8266 with Blinker.
 * https://github.com/esp8266/Arduino/releases
 * 
 * Make sure installed 1.0.5 or later ESP32/Arduino package,
 * if use ESP32 with Blinker.
 * https://github.com/espressif/arduino-esp32/releases
 * 
 * Docs: https://diandeng.tech/doc
 *       
 * 
 * *****************************************************************
 * 
 * Blinker 库下载地址:
 * https://github.com/blinker-iot/blinker-library/archive/master.zip
 * 
 * Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
 * 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
 * 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
 * 
 * 如果使用 ESP8266 接入 Blinker,
 * 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
 * https://github.com/esp8266/Arduino/releases
 * 
 * 如果使用 ESP32 接入 Blinker,
 * 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
 * https://github.com/espressif/arduino-esp32/releases
 * 
 * 文档: https://diandeng.tech/doc
 *       
 * 
 * *****************************************************************/

#define BLINKER_WIFI

#include <Blinker.h>
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
uint8_t newMACAddress[] = {0xA8, 0x15, 0x4D, 0xE2, 0x3B, 0xB0};
const uint16_t kIrLed = 4;  // ESP8266 GPIO pin to use. Recommended: 4 (D2).

IRsend irsend(kIrLed);  // Set the GPIO to be used to sending the message.

// Example of data captured by IRrecvDumpV2.ino
const uint16_t HotOnData[299] = {4440, 4396,  534, 1622,  534, 546,  574, 1580,  534, 1622,  534,
 544,  534, 546,  574, 1582,  576, 504,  532, 544,  534, 1622,  534, 546,  532, 544,  534, 
 1622,  578, 1580,  534, 546,  530, 1622,  576, 502,  574, 504,  534, 1622,  578, 1578, 
  534, 1622,  578, 1578,  534, 1622,  572, 1584,  580, 1578,  534, 1622,  534, 546,  572,
   504,  574, 502,  532, 544,  534, 544,  576, 504,  532, 1622,  570, 506,  574, 1582,  
   534, 1622,  534, 1622,  536, 1622,  576, 502,  534, 546,  532, 546,  576, 1580,  534, 
   546,  574, 502,  578, 500,  534, 546,  572, 1582,  570, 1586,  534, 5226,  4402, 4438, 
    576, 1580,  578, 502,  578, 1576,  578, 1580,  532, 548,  530, 544,  534, 1622,  534, 
    544,  576, 502,  574, 1582,  534, 544,  534, 544,  576, 1580,  534, 1622,  534, 544,  
    578, 1576,  576, 504,  532, 546,  578, 1576,  576, 1580,  578, 1580,  534, 1624,  578,
     1578,  570, 1586,  578, 1580,  578, 1578,  574, 506,  576, 500,  580, 498,  578, 500, 
      576, 502,  578, 500,  576, 1578,  578, 500,  580, 1574,  534, 1622,  578, 1578,  578,
       1578,  576, 502,  578, 500,  532, 544,  578, 1578,  574, 504,  582, 496,  578, 500, 
        578, 498,  576, 1578,  534, 1622,  574, 5188,  4444, 4394,  534, 1622,  580, 1576,
          580, 500,  578, 1576,  578, 502,  576, 1580,  578, 500,  580, 1576,  580, 500,  
          580, 1574,  580, 1576,  576, 502,  578, 500,  580, 1576,  582, 496,  580, 498, 
           576, 502,  576, 502,  578, 498,  580, 498,  578, 498,  580, 498,  580, 498,  580,
            498,  580, 496,  576, 504,  576, 500,  578, 502,  578, 498,  582, 498,  580, 1576,
              582, 496,  580, 498,  578, 500,  580, 500,  578, 498,  580, 498,  580, 498, 
               578, 498,  578, 498,  582, 498,  578, 500,  576, 1580,  582, 1576,  580, 1576, 
                580, 498,  580, 1576,  580, 1576,  576}; 

 const uint16_t CoolOnData[299] ={4450, 4390,  582, 1576,  608, 494,  558, 1574,
  582, 1576,  582, 520,  556, 522,  558, 1578,  576, 520,  558, 520, 
   556, 1600,  556, 526,  552, 552,  524, 1604,  552, 1606,  550, 530,
     550, 1604,  550, 1604,  576, 504,  550, 1604,  552, 1604,  554, 1602,
       554, 1602,  552, 1604,  554, 1606,  550, 528,  550, 1606,  552, 528, 
        550, 528,  574, 504,  572, 506,  548, 530,  574, 504,  570, 1582, 
         550, 1606,  552, 528,  548, 530,  548, 528,  550, 530,  548, 528,  
         550, 528,  550, 530,  548, 530,  572, 1582,  550, 1606,  550, 1606, 
          576, 1580,  550, 1606,  550, 1606,  550, 5208,  4420, 4420,  574, 1582,  
          550, 528,  576, 1578,  576, 1582,  550, 530,  550, 528,  550, 1606,  550,
           528,  550, 526,  574, 1582,  550, 528,  550, 528,  572, 1582,  552, 1606,  
           550, 530,  548, 1604,  552, 1606,  552, 528,  550, 1604,  576, 1582,  548, 
           1606,  576, 1580,  578, 1578,  552, 1606,  550, 528,  550, 1606,  550, 528,  
           550, 526,  548, 530,  548, 530,  550, 528,  572, 506,  576, 1578,  552, 1604,  
           550, 528,  550, 528,  548, 528,  572, 506,  552, 526,  548, 530,  550, 528, 
            550, 528,  548, 1606,  550, 1604,  574, 1582,  550, 1608,  550, 1606,  574, 
            1584,  552, 5210,  4418, 4420,  550, 1606,  552, 1604,  550, 530,  548, 1606, 
             574, 506,  550, 1604,  552, 526,  552, 1602,  552, 528,  548, 1606,  552, 1606, 
              550, 528,  550, 528,  572, 1584,  550, 1608,  548, 530,  548, 530,  550, 528,  550, 528, 
               550, 528,  574, 502,  552, 528,  548, 528,  552, 526,  572, 504,  550, 528,  572, 506,
                 574, 504,  550, 528,  550, 528,  572, 506,  560, 516,  552, 528,  572, 506,  572, 504, 
                  550, 528,  550, 530,  550, 526,  574, 506,  550, 528,  574, 506,  574, 502,  550, 1604,
                    552, 1606,  574, 1584,  550, 528,  572, 1584,  572, 1586,  550}; 

// Example Samsung A/C state captured from IRrecvDumpV2.ino
uint16_t HotOffData[199] = {4404, 4444,  526, 1646,  510, 568,  510, 1622,  536, 1630,  526, 
                          544,  534, 566,  510, 1622,  536, 544,  534, 546,  532, 1626,  530, 
                          544,  534, 568,  510, 1646,  512, 1624,  532, 548,  530, 1630,  526,
                           568,  512, 1620,  534, 1646,  510, 1630,  526, 1622,  534, 546,  532, 
                           1628,  528, 1628,  530, 1628,  528, 552,  524, 568,  510, 552,  526,
                            550,  528, 1630,  526, 568,  510, 546,  532, 1634,  524, 1622,  534, 
                            1626,  530, 550,  528, 544,  532, 568,  510, 550,  528, 550,  528, 550,  
                            528, 548,  530, 566,  512, 1626,  530, 1632,  526, 1646,  510, 1646,  510, 
                            1628,  530, 5234,  4394, 4440,  532, 1624,  534, 568,  510, 1620,  536, 1624, 
                             532, 542,  536, 542,  536, 1622,  534, 568,  510, 568,  510, 1628,  528, 
                             544,  534, 546,  532, 1628,  528, 1624,  532, 552,  526, 1626,  532, 554,  
                             568, 1584,  530, 1626,  530, 1624,  532, 1628,  528, 546,  532, 1624,  534, 
                             1622,  534, 1624,  532, 544,  534, 550,  530, 552,  524, 546,  532, 1624,  
                             532, 544,  534, 548,  530, 1628,  528, 1624,  534, 1630,  524, 546,  532, 548, 
                              528, 548,  530, 546,  532, 548,  530, 544,  532, 544,  534, 546,  532, 1644,  
                              512, 1628,  528, 1624,  532, 1644,  514, 1624,  530};
const uint16_t CoolOffData[199] = {4452, 4386,  584, 1572,  584, 518,  560, 1572,  584, 1572,  584, 520,  558, 518,  582, 1552,
  604, 496,  580, 498,  580, 1576,  582, 498,  578, 502,  574, 1578,  578, 1578,  578, 504,  572, 1582,  576, 504,  574, 1578,
    576, 1582,  574, 1582,  574, 1582,  576, 504,  574, 1578,  578, 1580,  574, 1582,  574, 506,  572, 506,  574, 504,  574, 506, 
     572, 1580,  576, 504,  572, 506,  574, 1580,  576, 1582,  576, 1580,  574, 506,  574, 504,  572, 506,  572, 504,  574, 504,  
     574, 502,  574, 506,  572, 504,  574, 1582,  576, 1580,  576, 1582,  574, 1580,  576, 1582,  574, 5186,  4446, 4396,  576, 1582, 
      574, 504,  572, 1582,  574, 1582,  576, 504,  574, 502,  574, 1580,  576, 504,  572, 504,  574, 1580,  576, 504,  574, 504,  574, 1582, 
       574, 1582,  576, 504,  574, 1582,  574, 506,  572, 1580,  576, 1580,  576, 1582,  574, 1582,  574, 504,  576, 1580,  576, 1582,  576, 1580,
         576, 504,  574, 506,  572, 504,  574, 502,  576, 1582,  574, 504,  576, 504,  572, 1582,  576, 1580,  576, 1582, 
          574, 504,  574, 504,  574, 504,  574, 504,  574, 504,  574, 504,  574, 502,  574, 502,  576, 1582,  574, 1580,  574, 1582, 
           576, 1582,  576, 1580,  576};
char auth[] = "";
char ssid[] = "";
char pswd[] = "";

// 新建组件对象
BlinkerButton ButtonOn("btn-on");
BlinkerButton ButtonOff("btn-off");

int counter = 0;
void set_mac()
{
  WiFi.mode(WIFI_STA);
  Serial.print("Old MAC :  ");
  Serial.println(WiFi.macAddress());
  wifi_set_macaddr(STATION_IF,&newMACAddress[0]);
  Serial.print("New MAC :  ");
  Serial.println(WiFi.macAddress());
}
// 按下按键即会执行该函数
void buttonOn_callback(const String & state)
{
    BLINKER_LOG("blink led: ", state);
    digitalWrite(2, 0);
    Serial.println("a Medi A/C on from IRrecvDumpV2");
    irsend.sendRaw(CoolOnData, 299, 38);  // Send a raw data capture at 38kHz.
    delay(2000);
}

void buttonOff_callback(const String & state)
{
    BLINKER_LOG("blink led: ", state);
    digitalWrite(2, 1);
    Serial.println("a Samsung A/C off from IRrecvDumpV2");
    irsend.sendRaw(CoolOffData, 199, 38);
    delay(2000);
}


// 如果未绑定的组件被触发,则会执行其中内容

void setup()
{
    // 初始化串口
    Serial.begin(115200);
    set_mac();
    BLINKER_DEBUG.stream(Serial);
    BLINKER_DEBUG.debugAll();
    
    // 初始化有LED的IO
    pinMode(2, OUTPUT);
    digitalWrite(2, HIGH);
    // 初始化blinker
    Blinker.begin(auth, ssid, pswd);
    

    ButtonOn.attach(buttonOn_callback);
    ButtonOff.attach(buttonOff_callback);

     irsend.begin();
#if ESP8266
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
#else  // ESP8266
  Serial.begin(115200, SERIAL_8N1);
#endif  // ESP8266
}

void loop() {
    Blinker.run();
}

  • 9
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值