Skip to content

Commit

Permalink
第一版
Browse files Browse the repository at this point in the history
  • Loading branch information
qlwz committed Feb 22, 2020
0 parents commit 964625d
Show file tree
Hide file tree
Showing 53 changed files with 7,158 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
/firmware.map
/mklink.bat
/output
67 changes: 67 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#


#
# Template #1: General project. Test it using existing `platformio.ini`.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run


#
# Template #2: The project is intended to be used as a library with examples.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files.associations": {
"functional": "cpp",
"cmath": "cpp",
"string": "cpp",
"*.tcc": "cpp",
"sstream": "cpp",
"array": "cpp"
}
}
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# ESP COVER
**杜亚KT82TV/W窗帘电机个人固件.**

> ### 作者声明
>
> 注意: 本项目主要目的为作者本人自己学习及使用杜亚KT82TV/W窗帘电机而开发,本着开源精神及造福网友而开源,仅个人开发,可能无法做到完整的测试,所以不承担他人使用本项目照成的所有后果。
>
> **严禁他人将本项目用户用于任何商业活动。个人在非盈利情况下可以自己使用,严禁收费代刷等任何盈利服务、**
>
> 有需要请联系作者:[email protected]
# 重要说明

- 杜亚电机型号:向日葵KT82TV/W电机
- 原贴:[KT82TV/W WIFI电机硬改ESP MQTT输出 NRF24-MYS 协议](https://bbs.iobroker.cn/t/topic/847)
- PCB:[KT82TV/W WIFI电机硬改ESP MQTT输出(附带pcb)](https://bbs.iobroker.cn/t/topic/852)
- PCB版权所有:Huex

## 特性

本固件使用杜亚KT82TV/W窗帘电机+硬改ESP硬件为基础,实现以下功能:

- [x] 控制窗帘电机
- [x] 自动设置行程
- [x] WEB配置页面
- [x] MQTT服务器连接控制
- [x] 通过MQTT连入Home Assistant


## 如何配网

1、第一次使用自动进入配网模式

2、以后通过长按【按键】进入配网模式

## 如何编译
Visual Studio Code + PlatformIO ID 开发 [安装](https://www.jianshu.com/p/c36f8be8c87f)

## 已支持接入的开源智能家居平台
以下排序随机,不分优劣。合适自己的就好。

### 1、Home Assistant
Home Assistant 是一款基于 Python 的智能家居开源系统,支持众多品牌的智能家居设备,可以轻松实现设备的语音控制、自动化等。
- [官方网站](https://www.home-assistant.io/)
- [国内论坛](https://bbs.hassbian.com/)

#### 接入方法
WEB页面开启**MQTT自动发现**

### 2、ioBroker
ioBroker是基于nodejs的物联网的集成平台,为物联网设备提供核心服务、系统管理和统一操作方式。
- [官方网站](http://www.iobroker.net)
- [中文资料可以参考这里](https://doc.iobroker.cn/#/_zh-cn/)
- [国内论坛](https://bbs.iobroker.cn)
#### 接入方法
ioBroker相关接入问题可以加QQ群776817275咨询

### 3、其他支持mqtt的平台
理论上来说,只要是支持MQTT的平台都可以实现接入。

#### 接入方法
添加对应的topic

# 固件截图

![image](https://github.com/qlwz/esp_cover/blob/master/file/images/tab1.png?raw=true)
![image](https://github.com/qlwz/esp_cover/blob/master/file/images/tab2.png?raw=true)
![image](https://github.com/qlwz/esp_cover/blob/master/file/images/tab3.png?raw=true)
![image](https://github.com/qlwz/esp_cover/blob/master/file/images/tab4.png?raw=true)



## 拆机接线及烧录固件相关

### 接线方法

PCB板有标明RX TX GPIO0

### 工具/固件下载

确认硬件连接正常后,下载以下软件:

烧录软件: flash_download_tools_vX.zip [点这里下载](https://www.espressif.com/zh-hans/support/download/other-tools)

完整固件: cover.bin [点这里下载](https://github.com/qlwz/esp_cover/releases)

### 开始烧录

将flash_download_tools_vX.zip解压,打开目录下的flash_download_tools_vX.exe,选择ESP8266 DownloadTool,根据以下截图做配置,

![image](https://github.com/qlwz/esp_dc1/blob/master/file/flash/flash1.png?raw=true)

将与主控板连接的usbTTL连接上电脑(确保主控io0必需短接gnd后再上电,以进入刷机模式),根据自己的实际串口号设置.,点击START按钮即可开始烧录.


稍等片刻,出现![FINISH_S](https://github.com/qlwz/esp_dc1/blob/master/file/flash/FINISH_S.bmp?raw=true)即为烧录超过


注意:部分发现烧录完成后可能出现问题无法使用.可以尝试用以上烧录软件ERASE擦除一次后重新烧录.

进入烧录模式后点ERASE,显示完成即为擦除超过.再将主控板重新上电并再次进入刷机模式,重新点START烧录即可



## 致谢
以下排名不分先后,为随机。
- Huex:提供硬改方案

感谢各位使用本方法的玩家,欢迎加入QQ群776817275

## 免责申明
以上纯属个人爱好,因为使用上述方法造成的任何问题,不承担任何责任。

部分图片来源于网络,如果涉及版权,请通知删除。
Binary file added file/images/tab1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added file/images/tab2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added file/images/tab3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added file/images/tab4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added file/杜亚KT82TV窗帘电机.rar
Binary file not shown.
85 changes: 85 additions & 0 deletions include/Cover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Cover.h
#ifndef _COVER_h
#define _COVER_h

#include <SoftwareSerial.h>
#include "Module.h"
#include "CoverConfig.pb.h"

#define MODULE_CFG_VERSION 1502 //1501 - 2000

const char HASS_DISCOVER_COVER[] PROGMEM =
"{\"name\":\"%s\","
"\"cmd_t\":\"%s\","
"\"pl_open\":\"OPEN\","
"\"pl_cls\":\"CLOSE\","
"\"pl_stop\":\"STOP\","
"\"pos_t\":\"%s\","
"\"set_pos_t\":\"%s\","
"\"position_open\":100,"
"\"position_closed\":0,"
"\"avty_t\":\"%s\","
"\"pl_avail\":\"online\","
"\"pl_not_avail\":\"offline\"}";

class Cover : public Module
{
private:
uint8_t operationFlag = 0; // 0每秒

CoverConfigMessage config;

boolean getPositionState = false;
SoftwareSerial *softwareSerial; // RX, TX
uint8_t softwareSerialBuff[20]; // 定义缓冲buff
uint8_t softwareSerialPos = 0; // 收到的字节实际长度
unsigned long softwareSerialTime = 0; // 记录读取最后一个字节的时间点
boolean autoStroke = false; // 是否自动设置行程

// 按键
int buttonDebounceTime = 50;
int buttonLongPressTime = 2000; // 2000 = 2s
boolean buttonTiming = false;
unsigned long buttonTimingStart = 0;
int buttonAction = 0; // 0 = 没有要执行的动作, 1 = 执行短按动作, 2 = 执行长按动作

uint8_t getInt(String str, uint8_t min, uint8_t max);
void httpPosition(ESP8266WebServer *server);
void httpDo(ESP8266WebServer *server);
void httpSetting(ESP8266WebServer *server);
void httpReset(ESP8266WebServer *server);
void httpHa(ESP8266WebServer *server);

void doPosition(uint8_t position, uint8_t command);
void doSoftwareSerialTick(uint8_t *buf, int len);

void readSoftwareSerialTick();
void getPositionTask();
void checkButton();

void reportPosition();

public:
void init();
String getModuleName() { return F("cover"); }
String getModuleCNName() { return F("杜亚KT82TV/W窗帘电机"); }
String getModuleVersion() { return F("2020.02.22.2100"); }
String getModuleAuthor() { return F("情留メ蚊子"); }
bool moduleLed();

void loop();
void perSecondDo();

void readConfig();
void resetConfig();
void saveConfig(bool isEverySecond);

void mqttCallback(String topicStr, String str);
void mqttConnected();
void mqttDiscovery(boolean isEnable = true);

void httpAdd(ESP8266WebServer *server);
void httpHtml(ESP8266WebServer *server);
String httpGetStatus(ESP8266WebServer *server);
};
#endif
71 changes: 71 additions & 0 deletions include/CoverConfig.pb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.3.9.4 at Sat Feb 22 19:19:51 2020. */

#ifndef PB_COVERCONFIG_PB_H_INCLUDED
#define PB_COVERCONFIG_PB_H_INCLUDED
#include <pb.h>

/* @@protoc_insertion_point(includes) */
#if PB_PROTO_HEADER_VERSION != 30
#error Regenerate this file with the current version of nanopb generator.
#endif

#ifdef __cplusplus
extern "C" {
#endif

/* Struct definitions */
typedef struct _CoverConfigMessage {
uint8_t position;
uint8_t direction;
uint8_t hand_pull;
uint8_t weak_switch;
uint8_t power_switch;
uint16_t report_interval;
uint8_t led;
uint8_t pin_rx;
uint8_t pin_tx;
uint8_t pin_led;
uint8_t pin_btn;
/* @@protoc_insertion_point(struct:CoverConfigMessage) */
} CoverConfigMessage;

/* Default values for struct fields */

/* Initializer values for message structs */
#define CoverConfigMessage_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
#define CoverConfigMessage_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

/* Field tags (for use in manual encoding/decoding) */
#define CoverConfigMessage_position_tag 1
#define CoverConfigMessage_direction_tag 2
#define CoverConfigMessage_hand_pull_tag 3
#define CoverConfigMessage_weak_switch_tag 4
#define CoverConfigMessage_power_switch_tag 5
#define CoverConfigMessage_report_interval_tag 6
#define CoverConfigMessage_led_tag 7
#define CoverConfigMessage_pin_rx_tag 20
#define CoverConfigMessage_pin_tx_tag 21
#define CoverConfigMessage_pin_led_tag 22
#define CoverConfigMessage_pin_btn_tag 23

/* Struct field encoding specification for nanopb */
extern const pb_field_t CoverConfigMessage_fields[12];

/* Maximum encoded size of messages (where known) */
#define CoverConfigMessage_size 70

/* Message IDs (where set with "msgid" option) */
#ifdef PB_MSGID

#define COVERCONFIG_MESSAGES \


#endif

#ifdef __cplusplus
} /* extern "C" */
#endif
/* @@protoc_insertion_point(eof) */

#endif
Loading

0 comments on commit 964625d

Please sign in to comment.