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.

197 lines
8.4 KiB

  1. # Flashing guide
  2. ## Tools needed
  3. * Allen key (2mm, 5/64") or torx (T8) screw driver
  4. * Soldering Iron
  5. * Perhaps some sticky tape
  6. * A serial to USB adapter (FTDI)
  7. * Some wires
  8. ## Warning
  9. We have writen these instructions with care, but we will give absolutely no
  10. warranty. Perhaps you will destroy your lamp and your computer.
  11. ## Opening the lamp, to expose the PCB
  12. Remove the rubber pads from the botton of the lamp, to get access to 4
  13. screws that attach the bottom to the rest of the lamp. Note that you don't
  14. have to remove these pads fully. Once you can access the screws, you've
  15. gone far enough.
  16. Unbolt the 4 screws which were hidden under the rubber pads.
  17. ![Photo of the screws](images/screws.jpg "Use an allen key or torx screw driver to remove the screws.")
  18. Detach the bottom from the rest of the lamp, exposing the PCB. This might
  19. take a bit of force. Just pull it up bit by bit until it pops loose.
  20. For some good pictures of disassembling this lamp, take a look [at this
  21. blog post](https://mysku.ru/blog/china-stores/78455.html) It is in Russian,
  22. but the translation by Google works well and moreover, the pictures are the
  23. most important thing here. If you scroll down, you will find them easily.
  24. ## Solder the wires
  25. Many of the serial to USB adapter have some header pins to which you can
  26. connect the wires of a device. Therefore, I find it most useful to take some
  27. dupont wires with a female end to them, and cut off the other end. Strip the
  28. wire on the other and, and solder this end to the board.
  29. Solder the wires to the `RX`, `TX`, `GND` and `GPIO0` debug pads that are
  30. shown in the following photo. It is *not* required to solder a wire to the
  31. `3.3V` debug pad. This pad is not directly connected to the 3.3V Vin of the
  32. ESP32 chip, making it a less than optimal candidate for powering the board
  33. during flashing. Instead, powering the lamp using its own power supply works
  34. best.
  35. ![Soldering points](images/Soldering_points.jpg)
  36. You can use some sticky tape to fixate the cables before soldering.
  37. ## Connect the wires to your serial to USB adapter
  38. The wires must be connected as follows:
  39. | Soldering point| Serial USB Adapter name |
  40. | -------------- |:------------------------:|
  41. | GND | GND |
  42. | TX | RX |
  43. | RX | TX |
  44. | GPIO0 | GND |
  45. To be able to flash the lamp, `GPIO0` must be connected to ground while
  46. the lamp boots up. Therefore, connect these wires *before* plugging in
  47. the lamp's power supply. Flashing will not work if you connect these
  48. wires after the lamp has already been booted up.
  49. ## When you only have one GND pin on your USB Adapter
  50. If your USB Adapter does not have multiple `GND` pins, then you'll have to
  51. find another way to attach `GPIO0` to ground. Some options:
  52. - Use a breadbord, so you can connect the USB Adapter `GND` pin to a row on
  53. the bread bord, and connect the `GND` and `GPIO0` wires of the lamp's
  54. board to that same row.
  55. - Solder a button on the board that connects `GPIO0` to `GND` when pressed.
  56. Then you can hold down this button while plugging in the lamp's power
  57. supply. After booting up, you can release the button (the serial console
  58. will also mention that flash mode is now enabled). This is not the most
  59. practical solution for most people (since only one such flash operation is
  60. needed, from then on OTA - Over The Air - updates are possible), but it
  61. was a great help to me during the initial reverse engineering and firmware
  62. development.
  63. - Manually hold a wire connected to both a GND surface (e.g. the silver pad
  64. on the left of the board) and the `GPIO0` debug pad, while plugging in the
  65. power supply. After booting, the wire can be removed. This is very fiddly
  66. way of doing it (a third hand would be very welcome with this), but it can
  67. be done.
  68. - You could opt for temporarily soldering a lead between `GND` and `GPIO0`
  69. on the board, making `GPIO0` pulled to ground permanently. It is a bit
  70. less flexible than some other options, but if you only need to do the
  71. initial backup and firmware flash of the lamp, then this can be all
  72. that you need. Remove the lead after flashing is done, otherwise the
  73. lamp won't boot in normal mode.
  74. ## Make a backup of the current firmware
  75. Backing up the firmware makes it possible to revert to the original firmware,
  76. in case you have problems with the ESPHome firmware. The backup can be
  77. created using "esptool". Installation instructures can be found here:
  78. https://github.com/espressif/esptool/blob/master/README.md#installation--dependencies
  79. Here's an example on how to backup the original firmware from Linux. First,
  80. unplug your lamp's power supply, then start the esptool read_flash command:
  81. ```
  82. python esptool.py -p /dev/ttyUSB0 read_flash 0x0 0x400000 original-firmware.bin
  83. ```
  84. `/dev/ttyUSB0` is the port of the USB adaper on Linux. You can find what
  85. port is used by the adapter by running `dmesg` after plugging in the USB
  86. device. On Windows this is often `COM1`, `COM2` or `COM3`.
  87. Now plug in the power supply. The output of esptool should now show that it
  88. connects to the lamp and downloads the firmware from it.
  89. **Caution**: You will find the WLAN SSID and Password of the last used
  90. WiFi network in this file. Therefore, keep this backup in a safe place.
  91. ## Restore the backed up firmware
  92. In case you need to rollback to the lamp's original firmware at some
  93. point, here's an example of how to restore the original firmware from
  94. Windows, by fully flashing it back onto the lamp.
  95. First, unplug your lamp's power supply, then start the esptool write_flash
  96. command:
  97. ```
  98. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x00 original-firmware.bin
  99. ```
  100. Make sure that `GPIO0` is connected to GND and plug in the power supply.
  101. The output of esptool should now show that it connects to the lamp and
  102. uploads the firmware to it. Be patient after the upload reaches 100%. The
  103. output is silent for a while, but esptool tool is verifying if the firmware
  104. was uploaded correctly.
  105. After the firmware upload completes, unplug the power, disconnect `GPIO0`
  106. from GND and reconnect the power supply to boot into the restored firmware.
  107. ## Flash new ESPHome firmware
  108. Setup an ESPHome Project (see [README.md](../README.md)),compile the firmware
  109. for the lamp and download the `firmware.bin` file to the device to which
  110. the serial adapter is connected.
  111. You can flash the lamp using esphome or esptool. I would recommend using
  112. the [esphome-flasher](https://github.com/esphome/esphome-flasher) tool,
  113. which is a very easy to use GUI utility app for flashing ESPHome devices:
  114. - In the app, select the COM port of your serial adapter.
  115. - Also select the firmware.bin file to flash onto the lamp.
  116. - Power up the lamp with `GPIO0` connected to GND.
  117. - Click the "Flash ESP" button to flash the firmware.
  118. If you want to flash with esptool, you can use:
  119. ```
  120. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x1000 <path\to\yourfirmware.bin>
  121. ```
  122. After flashing, power down the lamp, disconnect `GPIO0` from GND and
  123. reconnect the power to boot into the new ESPHome firmware.
  124. From here on, it is possible to flash the lamp OTA (over the air, which
  125. means that the firmware is uploaded over WiFi) from ESPHome. Therefore, it
  126. is now time to tuck away or remove those soldered wires and add the bottom
  127. cover back on.
  128. ## Troubleshooting flash
  129. If you have **A fatal error occurred: MD5 of file does not match data in
  130. flash!**, then make sure you are powering the board using the lamp's own
  131. power adapter. We've seen these errors when trying to power the board using
  132. the 3.3V debug pad.
  133. After seeing this error, user @tabacha was able to successfully flash his
  134. lamp using the regular power adapter and the tasmota boot loader using
  135. the following command:
  136. ```
  137. python esptool.py --chip esp32 -p /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dout --flash_freq 40m --flash_size detect 0x1000 bootloader_dout_40m.bin 0x8000 partitions.bin 0xe000 boot_app0.bin 0x10000 ~/Downloads/schlafzimmerbedlight.bin
  138. ```
  139. You will find the missing tasmota boot files here:
  140. https://github.com/arendst/Tasmota/tree/firmware/firmware/tasmota32/ESP32_needed_files
  141. *Note: user @tabacha was not able to use tasmota with the Bedside Lamp 2.*
  142. (remember that the [esphome-flasher](https://github.com/esphome/esphome-flasher)
  143. will give you a bit less of a hard-core experience during flashing)