Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
5.1 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. # ESPurna
  2. ESPurna ("spark" in Catalan) is a custom C firmware for ESP8266 based smart switches. It was originally developed with the **[ITead Sonoff][1]** in mind. This device has an ESP8266 on board with a 8Mbit flash memory chip, a mains to 3V3 transformer and a relay (GPIO12). It also features a button (GPIO0), an LED (GPIO13) and an unpopulated header you can use to reprogram it.
  3. You can read about this board and firmware in [my blog][2].
  4. ![Sonoff board - front view](/images/pinout_front.jpg)
  5. ![Sonoff board - back view](/images/pinout_back.jpg)
  6. ## Hardware support
  7. * [ITead Sonoff TH][1]
  8. * [ITead Sonoff RF][8]
  9. * [ITead Slampher][9]
  10. * [ITead S20 Smart Socket][10]
  11. * Tinkerman ESPurna board
  12. ## Features
  13. * **WebServer for configuration** and simple relay toggle
  14. * **Flashing firmware Over-The-Air** (OTA)
  15. * Up to **3 configurable WIFI networks**
  16. * **MQTT support** with configurable host and topic
  17. * Manual switch ON/OFF with button (single click the button)
  18. * AP mode backup (double click the button)
  19. * Visual status of the connection via the LED
  20. * Support for custom **[RF module][2]**
  21. * Support for **automatic over-the-air updates** through the [NoFUSS Library][6]
  22. * Support for **current monitoring** through then [EmonLiteESP Library][7]
  23. * Support for **DHT22** sensors
  24. ## Flashing
  25. The unpopulated header has all the required pins. My board has a 5 pins header in-line with the button. They are (from the button outwards):
  26. * 3V3
  27. * RX
  28. * TX
  29. * GND
  30. * GPIO14
  31. Last one is not necessary. Mind it's a **3V3 device**, if connected to 5V you will probably fry it. Button is connected to GPIO0 on the ESP8266 chip, so to enter flash mode you have to hold the button pressed while powering on the board, then you can realease it again.
  32. The project is ready to be build using [PlatformIO][3].
  33. Please refer to their web page for instructions on how to install the builder. Once installed:
  34. ```bash
  35. > platformio run --target upload -e wire
  36. > platformio run --target uploadfs -e wire
  37. ```
  38. Once you have flashed it you can flash it again over-the-air using the ```ota``` environment:
  39. ```bash
  40. > platformio run --target upload -e ota
  41. > platformio run --target uploadfs -e ota
  42. ```
  43. When using OTA environment it defaults to the IP address of the device in SoftAP mode. If you want to flash it when connected to your home network best way is to supply the IP of the device:
  44. ```bash
  45. > platformio run --target upload -e ota --upload-port 192.168.1.151
  46. > platformio run --target uploadfs -e ota --upload-port 192.168.1.151
  47. ```
  48. You can also use the automatic OTA update feature. Check the [NoFUSS library][6] for more info.
  49. Library dependencies are automatically managed via PlatformIO Library Manager.
  50. ## Usage
  51. On normal boot (i.e. button not pressed) it will execute the firmware. It configures the hardware (button, LED, relay), the SPIFFS memory access, the WIFI, the WebServer and MQTT connection.
  52. Obviously the default values for WIFI network and MQTT will probably not match your requirements. The device will start in Soft AP creating a WIFI SSID named "SONOFF_XXXXXX", where XXXXXX are the last 3 bytes of the radio MAC. Connect with phone, PC, laptop, whatever to that network, password is "fibonacci". Once connected
  53. browse to 192.168.4.1 and you will be presented a configuration page where you will be able to define up to 3 possible WIFI networks and the MQTT configuration parameters.
  54. It will then try to connect to the configure WIFI networks one after the other. If none of the 3 attempts succeed it will default to SoftAP mode again. Once connected it will try to connect the MQTT server. You can also switch to SoftAP mode by long clicking the on board button or reset the board double clicking the it.
  55. The device will publish the relay state to the given topic and it will subscribe to the same topic for remote switching. Don't worry, it avoids infinite loops.
  56. You can also use "{identifier}" as place holder in the topic. It will be translated to your device ID (same as the soft AP network it creates).
  57. ## Troubleshooting
  58. After flashing the firmware via serial do a hard reset of the device (unplug & plug). There is an issue with the ESP.reset() method. Check [https://github.com/esp8266/Arduino/issues/1017][4] for more info.
  59. Current version of ESP8266httpUpdate restarts the modules after SPIFFS update, thus preventing the firmware to be updated too. There is a recent commit fixing that which is not yet pushed to PLatformIO. Check [Fix example for ESP8266httpUpdate][5] for more info. Anyway, current expected behaviour is to not resetting the board from the ESP8266httpUpdate class (comment out line 300 in ```ESP8266httpUpdate.cpp```).
  60. [1]: https://www.itead.cc/sonoff-wifi-wireless-switch.html
  61. [2]: http://tinkerman.cat/adding-rf-to-a-non-rf-itead-sonoff
  62. [3]: http://www.platformio.org
  63. [4]: https://github.com/esp8266/Arduino/issues/1017
  64. [5]: https://github.com/esp8266/Arduino/pull/2251
  65. [6]: https://bitbucket.org/xoseperez/nofuss
  66. [7]: https://bitbucket.org/xoseperez
  67. [8]: https://www.itead.cc/sonoff-rf.html
  68. [9]: https://www.itead.cc/slampher-wifi-wireless-light-holder.html
  69. [10]: https://www.itead.cc/smart-socket-eu.html