├── .gitignore ├── .travis.yml ├── README.md ├── images ├── esp01-relay.png ├── info.png ├── main.png └── rename.png ├── include └── README ├── lib └── README ├── platformio.ini ├── src └── main.cpp └── test └── README /.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - '2.7' 4 | sudo: false 5 | cache: 6 | directories: 7 | - "~/.platformio" 8 | install: 9 | - pip install -U platformio 10 | - platformio update 11 | script: 12 | - mkdir build 13 | - platformio ci --keep-build-dir --build-dir ./build --project-conf=platformio.ini 14 | src/main.cpp 15 | before_deploy: 16 | - platformio ci -h 17 | - ls -a 18 | - find . -name "*.bin" 19 | deploy: 20 | provider: releases 21 | api_key: 22 | secure: nBYCWD2QpaR9LQQ1nqkKXezij46nn2AJvcQnpwbYpXGD08Ik5enUucq4h2WNz6moVjWSRyA8Trb5DdLTtYSnCJCxBYueA9G2FP6Z38bUsezgcsrns8qVQT1tzX1Dh4vOOP8TM/2/DAGkW149QmVhD8vU6XD9X9qkzfjbWXShP//VExNpr3nLyp0KvB+L4rh1EtumSMUzwPIMcplFH/9/z4PQnwwJiYLhvOwa0EWMgn7W/LVjHfKYZvYD7UQr5HCJgzWVhQrGEVzCys5Ywhgy40Q/lmeeTwoNlFQqSuswUO1ZzT1TA+fpliE3p9van62kYJ4O4/IRgswk6JREcOv8ekWwngksUlvuW1QAImHjYhX/GsRz++GulRyi5+31gyZbtcJhAQCLeTtof+VqpEF/MA+o47tc3NAxv5ssr4Jbeq8IOTwOv/e9FvLYmvkiTqkzoeiWcmgOE9aSv+mhuSFEvqDKmb+9mTBKNBf1PqrM5BVk1w/qsjuCkCjVzV50zx/LqN4+YkMkRWcL/Xvafnp8Lv2WjgNiXlVF+lU4/J9nnSvK8LSVjThmI/SdwQmjimurP/GwYemEW6BJwJvwO6814C2mUZEFOkqZhn2KOlCqIiXQKgw1VOwcfIyfNr6C4a6xWYw0gSYMsSnDKz/GmGnKWHE7e8B8u+LnsB8hYPlg4LI= 23 | file: "build/.pio/build/d1/firmware.bin" 24 | skip_cleanup: true 25 | on: 26 | repo: IoTDevice/esp8266-switch 27 | tags: true 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esp8266-switch 2 | 开源的esp8266远程开关固件 3 | > ## control with app(使用以下app操控): 4 | > * https://github.com/OpenIoTHub/OpenIoTHub 5 | > * 此程序会自动发现设备,将设备放入智能设备列表 6 | 7 | #### 支持的功能: 8 | - [x] 1.支持设备开关 9 | - [x] 2.支持设备重新命名 10 | 11 | #### 项目使用的硬件 12 | * esp01-relay 13 | ![image](./images/esp01-relay.png) 14 | 15 | #### 界面 16 | * 主界面 17 | ![image](./images/main.png) 18 | * 重新命名 19 | ![image](./images/rename.png) 20 | * 设备详情 21 | ![image](./images/info.png) -------------------------------------------------------------------------------- /images/esp01-relay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IoTDevice/esp8266-switch/4497e4e4886433615c054b13e34a504e87e65e4b/images/esp01-relay.png -------------------------------------------------------------------------------- /images/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IoTDevice/esp8266-switch/4497e4e4886433615c054b13e34a504e87e65e4b/images/info.png -------------------------------------------------------------------------------- /images/main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IoTDevice/esp8266-switch/4497e4e4886433615c054b13e34a504e87e65e4b/images/main.png -------------------------------------------------------------------------------- /images/rename.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IoTDevice/esp8266-switch/4497e4e4886433615c054b13e34a504e87e65e4b/images/rename.png -------------------------------------------------------------------------------- /include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ;PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:d1] 12 | platform = espressif8266 13 | board = esp8285 14 | framework = arduino 15 | upload_speed = 921600 16 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | const int httpPort = 80; 6 | String deviceName = "开关"; 7 | String version = "1.0"; 8 | ESP8266WebServer server(httpPort); 9 | // 看你的继电器是连接那个io,默认gpio0 10 | const int ledPin = 0; 11 | // 开关的状态表示 12 | const int on = 1; 13 | const int off = 0; 14 | // 开关的当前状态 15 | String ledStatus = "off"; 16 | // digitalWrite(led, on); 17 | 18 | // web服务器的根目录 19 | void handleRoot() { 20 | server.send(200, "text/html", "

this is index page from esp8266!

"); 21 | } 22 | // 操作LED开关状态的API 23 | void handleLedStatusChange(){ 24 | String message = "{\"code\":0,\"message\":\"success\"}"; 25 | for (uint8_t i=0; i