Giter Site home page Giter Site logo

changyou68 / switchbota Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kendallgoto/switchbota

0.0 0.0 0.0 102 KB

Replaces the factory firmware on the SwitchBot Plug Mini via OTA, enabling the use of Tasmota without disassembling the unit.

License: GNU General Public License v3.0

JavaScript 23.84% C 73.53% Makefile 0.83% CMake 1.80%

switchbota's Introduction

SwitchbOTA

Replaces the default firmware on the SwitchBot Plug Mini via OTA, enabling the use of Tasmota without disassembling the unit.

Similar to Espressif2Arduino.

Compatible Versions

SwitchbOTA has been tested to work on the two current existing US plug revisions:

  • W1901400 (Original US Plug Mini, March 2022)
  • W1901401 (HomeKit US Plug Mini, June 2022)

Running SwitchbOTA has been tested on v1.4 and lower. You may want to downgrade to V1.4 or lower before starting the process.

Disclaimer

Writing to the bootloader over OTA is dangerous and not normally done for good reason. If your device loses power or somehow flashes corrupted data, the device will be bricked and require disassembly to reprogram the device. Only perform this process if you are comfortable disassembling your plug to fix it if it breaks! Of course, do not unplug or otherwise disturb the plug while it is performing the OTA.

This is a proof of concept and provided with no warranty.

Pre-reqs

In order to have the factory firmware download our custom firmware, you'll need to modify your local DNS to serve the desired binary. Specifically, www.wohand.com should point to a local machine running the included web server. If you don't know what this means, read here for more information. A DNS server is included in the server applet as well, however, you still must configure your local router to serve the correct address. See the server/ README for more information.

Install

  1. Setup the web server to serve the desired OTA binaries to your device.
  2. Build the ESP-IDF binary or download the Release binary to flash the device.
  3. Trigger an update via the product's app.
  4. Connect to the Tasmota hotspot and configure!

Tasmota Setup

Currently, Tasmota's support for the ESP32-C3 is unofficial. However, power monitoring and MQTT delivery works effectively with the following template:

{"NAME":"W1901400","GPIO":[0,0,32,0,0,0,224,320,321,0,0,0,0,0,0,0,0,0,2720,2656,2624,0],"FLAG":0,"BASE":1}

More Template information

How to use a template?

Process

The included ESP-IDF code is a lightweight OTA client that directly writes to the embedded flash chip, enabling the install of non-app level code, including modfiying the bootloader and partiton table.

  1. The update is triggered by the app with a BLE message.
  2. The device fetches http://www.wohand.com/version/wocaotech/firmware/WoPlugUS/WoPlugUS_VXX.bin for the firmware.
  3. The request is intercepted and served by our web server, which downloads the espressif binary
  4. The factory firmware installs the binary to ota_0 or ota_1, depending on past usage.
  5. The binary runs from its OTA partition. If it's on ota_1, it skips to step 6. Otherwise, it performs another OTA, downloading itself into ota_1 and rebooting.
  6. Once on OTA_1, the device fetches http://www.wohand.com/payload.bin for OTA.
  7. The request is intercepted and served by our web server, delivering our desired payload.
  8. The espressif binary wipes the internal flash and flashes the payload. It performs two checksums, one of the downloaded binary and another of the flashed binary. It will continue to retry without restarting until the checksums are valid.

Troubleshooting

WiFi configuration is read from the device's NVS memory by the Espressif binary. This should be configured in the SwitchBot app prior to the process. If, for whatever reason, it is lost, the binary will make a fallback connection to SSID switchbota, password switchbota. You may need to create this SSID to recover the device.

If you're already on the latest version of the official firmware, you won't be able to begin the OTA process from the app. If this is the case, you can manually start the process by sending bluetooth signals directly to the plug. Read here for more information.

Donations

To support my work, consider making a purchase from SwitchBot using my affiliate link. Alternatively, please see my sponsor page here.

switchbota's People

Contributors

kendallgoto avatar linagee avatar cossid avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.