通过 智能插座 + 控控A2 + KVM切换器 基本实现了多台服务器的远程控制,
唯一存在问题是KVM切换器是按键进行切换不同机器,无法远程控制,
通过使用ESP8266-01S+点灯科技 将KVM切换器开关 改造为可远程控制
界面配置
- {¨version¨¨2.0.0¨¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨«}}¨dashboard¨|{¨type¨¨tex¨¨t0¨¨KVM¨¨t1¨¨文本2¨¨bg¨Ë¨ico¨´´¨cols¨Í¨rows¨Ê¨key¨¨tex_1¨´x´É´y´É¨speech¨|÷¨lstyle¨Ê¨clr¨¨#FFF¨}{ßC¨num¨ßE¨当前设备号¨ßJ¨fad fa-server¨ßQ¨#389BEE¨¨min¨É¨max¨¢1c¨uni¨´´ßIÉßKÍßLËßM¨num_index¨´x´É´y´ÊßO|÷ßPʨrt¨«}{ßC¨btn¨ßJ¨fad fa-circle¨¨mode¨ÉßE¨设备一¨ßGßHßIÉßKËßLËßM¨btn_1st¨´x´É´y´ÍßPÉ}{ßCßbßJßcßdÉßE¨设备二¨ßGßHßIÉßKËßLËßM¨btn_2nd¨´x´Ë´y´Í}{ßCßbßJßcßdÉßE¨设备三¨ßGßHßIÉßKËßLËßM¨btn_3rd¨´x´Í´y´ÍßPÉ}{ßCßbßJßcßdÉßE¨设备四¨ßGßHßIÉßKËßLËßM¨btn_4th¨´x´É´y´Ï}{ßCßbßJßcßdÉßE¨设备五¨ßGßHßIÉßKËßLËßM¨btn_5th¨´x´Ë´y´Ï}{ßCßbßJßcßdÉßE¨设备六¨ßGßHßIÉßKËßLËßM¨btn_6th¨´x´Í´y´Ï}{ßCßbßJ¨fad fa-repeat-alt¨ßdÉßE¨切换¨ßGßHßIÉßKÊßLÊßM¨btn_sw¨´x´Í´y´ËßPÍßQ¨#FBA613¨}{ßC¨deb¨ßdÊßIÉßKÑßLÌßM¨debug¨´x´É´y´Ò}÷¨actions¨|¦¨cmd¨¦¨switch¨‡¨text¨‡´on´¨打开?name¨¨off¨¨关闭?name¨—÷¨triggers¨|{¨source¨ßz¨source_zh¨¨开关状态¨¨state¨|´on´ß12÷¨state_zh¨|´打开´´关闭´÷}÷ßa|÷}
复制代码
代码
- #define BLINKER_PRINT Serial
- #define BLINKER_WIFI
- #include <Blinker.h>
- char auth[] = "******";
- char ssid[] = "******";
- char pswd[] = "******";
- BlinkerNumber Number1("num_index");
- BlinkerButton Button10("btn_sw");
- BlinkerButton Button1("btn_1st");
- BlinkerButton Button2("btn_2nd");
- BlinkerButton Button3("btn_3rd");
- BlinkerButton Button4("btn_4th");
- BlinkerButton Button5("btn_5th");
- BlinkerButton Button6("btn_6th");
- // 可切换的设备数
- int maxIndex = 6;
- // 当前工作中的设备编号
- int deviceIndex = 1;
- // 当前选择的设备编号
- int selectedIndex = 1;
- // 定义GPIO口用于控制继电器
- int GPIO = 0;
- void switchButton(int index) {
- int step;
- index = ( index > 6) ? 1 : index;
- BLINKER_LOG("index: ", index);
- BLINKER_LOG("deviceIndex: ", deviceIndex);
- BLINKER_LOG("button ", index, " tap!");
- if ( index > deviceIndex ) {
- step = index - deviceIndex;
- } else if ( index < deviceIndex ) {
- step = (maxIndex - deviceIndex) + index;
- } else {
- step = 0;
- }
- deviceIndex = selectedIndex = index;
- Number1.print(deviceIndex);
- for ( ; step > 0; step-- ) {
- BLINKER_LOG("step: ", step);
- delay(500);
- digitalWrite(GPIO, HIGH);
- delay(200);
- digitalWrite(GPIO, LOW);
- }
- }
- void button10_callback(const String & state) {
- if (state == BLINKER_CMD_BUTTON_TAP) {
- switchButton(selectedIndex+1);
- }
- }
- void button1_callback(const String & state) {
- if (state == BLINKER_CMD_BUTTON_TAP) {
- switchButton(1);
- }
- }
- void button2_callback(const String & state) {
- if (state == BLINKER_CMD_BUTTON_TAP) {
- switchButton(2);
- }
- }
- void button3_callback(const String & state) {
- if (state == BLINKER_CMD_BUTTON_TAP) {
- switchButton(3);
- }
- }
- void button4_callback(const String & state) {
- if (state == BLINKER_CMD_BUTTON_TAP) {
- switchButton(4);
- }
- }
- void button5_callback(const String & state) {
- if (state == BLINKER_CMD_BUTTON_TAP) {
- switchButton(5);
- }
- }
- void button6_callback(const String & state) {
- if (state == BLINKER_CMD_BUTTON_TAP) {
- switchButton(6);
- }
- }
- void setup() {
- Serial.begin(115200);
- BLINKER_DEBUG.stream(BLINKER_PRINT);
- pinMode(GPIO, OUTPUT);
- Blinker.begin(auth, ssid, pswd);
-
- Button10.attach(button10_callback);
- Button1.attach(button1_callback);
- Button2.attach(button2_callback);
- Button3.attach(button3_callback);
- Button4.attach(button4_callback);
- Button5.attach(button5_callback);
- Button6.attach(button6_callback);
- Number1.print(deviceIndex);
- }
- void loop() {
- Blinker.run();
- }
复制代码
|