### Start Tuya-Convert Session on Pi Zero W Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-a-Raspberry-Pi This sequence of commands is used when setting up a Raspberry Pi Zero W using only Wi-Fi. It involves starting a `screen` session to maintain the process, running the `start_flash.sh` script, and then reconnecting to the Pi after it creates its own AP. ```bash screen start_flash.sh # Connect to the vtrust-flash AP and SSH to 10.42.42.1 screen -r screen -r -d [screen id] ``` -------------------------------- ### Install Tuya-Convert Prerequisites Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-Only-a-Stock-Raspberry-Pi-ZeroW-and-USB-Cable Installs necessary packages like git and clones the Tuya-Convert repository, then runs the prerequisite installation script. ```bash sudo apt-get update && sudo apt-get -y upgrade sudo apt-get install git git clone https://github.com/ct-Open-Source/tuya-convert cd tuya-convert ./install_prereq.sh ``` -------------------------------- ### Starting the Flashing Process Source: https://github.com/ct-open-source/tuya-convert/blob/master/README.md Initiates the firmware flashing process using the start_flash.sh script. This script installs a flash loader, connects to a Wi-Fi access point, and backs up the original firmware. ```bash ./start_flash.sh ``` -------------------------------- ### Prerequisite Installation Source: https://github.com/ct-open-source/tuya-convert/blob/master/README.md Clones the tuya-convert repository and executes the installation script for prerequisites. Ensure you have git installed. ```bash git clone https://github.com/ct-Open-Source/tuya-convert cd tuya-convert ./install_prereq.sh ``` -------------------------------- ### Setup Pass-through Access Point with create_ap Source: https://github.com/ct-open-source/tuya-convert/wiki/Collaboration-document-for-PSK-Identity-02 Installs the create_ap script and sets up a pass-through Wi-Fi access point. This is a prerequisite for capturing network traffic from devices connecting to this AP. It requires root privileges for installation and AP setup. ```bash git clone https://github.com/oblique/create_ap cd create_ap sudo make install cd .. sudo create_ap wlan0 wlan0 MyAccessPoint MyPassPhrase ``` -------------------------------- ### Start Tuya-Convert Flashing Script Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-Only-a-Stock-Raspberry-Pi-ZeroW-and-USB-Cable Navigates to the tuya-convert directory and executes the start_flash.sh script to begin the device flashing process. ```bash cd tuya-convert ./start_flash.sh ``` -------------------------------- ### Install Prerequisites Source: https://github.com/ct-open-source/tuya-convert/blob/master/README.md This script is responsible for installing all the necessary dependencies required for TUYA-CONVERT to function correctly. It ensures that the environment is set up with the tools needed for flashing firmware. ```bash #!/bin/bash # Example: Install necessary packages sudo apt-get update sudo apt-get install -y python3 python3-pip git hostapd dnsmasq iptables # Example: Install Python dependencies pip3 install -r requirements.txt ``` -------------------------------- ### Docker Setup and Execution Source: https://github.com/ct-open-source/tuya-convert/blob/master/README.md Instructions for building and running the Tuya-Convert Docker container. This includes cloning the repository, setting up environment variables, and executing the container for flashing Tuya devices. ```bash git clone https://github.com/ct-Open-Source/tuya-convert cd tuya-convert git pull cp .env-template .env # Adjust .env file as needed docker-compose build && docker-compose run --rm tuya ``` -------------------------------- ### Docker Troubleshooting Commands Source: https://github.com/ct-open-source/tuya-convert/blob/master/README.md Common troubleshooting commands for the Tuya-Convert Docker setup. This includes options for rebuilding the image without cache, running the container without automatic deletion, and starting the container with a bash shell. ```bash # Rebuild without cache docker-compose build --no-cache # Run without removing container on exit docker-compose run --entrypoint bash tuya # Start container and get into bash shell docker-compose run --entrypoint bash tuya ``` -------------------------------- ### Proxmox LXC Setup Script Source: https://github.com/ct-open-source/tuya-convert/wiki/Additional-Resources This script configures a Proxmox LXC container by disabling the commercial repository, adding the community repository, and removing the subscription nag from the Proxmox UI. It ensures the container is ready for Tuya-Convert operations. ```bash # Disable Commercial Repo sed -i "s/^deb/\#deb/" /etc/apt/sources.list.d/pve-enterprise.list apt-get update # Add PVE Community Repo echo "deb http://download.proxmox.com/debian/pve $(grep \"VERSION=\" /etc/os-release | sed -n 's/.*(\(.*\)).*/\1/p') pve-no-subscription" > /etc/apt/sources.list.d/pve-no-enterprise.list apt-get update # Remove nag echo "DPkg::Post-Invoke { \"dpkg -V proxmox-widget-toolkit | grep -q '/proxmoxlib.js$'; if [ \$? -eq 1 ]; then { echo 'Removing subscription nag from UI...'; sed -i '/data.status/{s/!//;s/Active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; }; fi\"; };" > /etc/apt/apt.conf.d/no-nag-script apt --reinstall install proxmox-widget-toolkit ``` -------------------------------- ### Disable Wi-Fi via Configuration File Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-a-Raspberry-Pi This method involves editing the `wpa_supplicant.conf` file to remove Wi-Fi network configurations. After saving the changes, a reboot is required for the modifications to take effect. This is an alternative to using `killall`. ```shell sudo nano /etc/wpa_supplicant/wpa_supplicant.conf # Delete the wifi network block including network={} # Close the file (ctrl x, y, enter) sudo reboot ``` -------------------------------- ### Raspberry Pi Serial Gadget System Services Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-Only-a-Stock-Raspberry-Pi-ZeroW-and-USB-Cable Commands to manage and verify the status of the serial getty service on the Raspberry Pi. ```APIDOC systemctl enable getty@ttyGS0.service - Enables the getty service for the ttyGS0 serial port, allowing logins. - Output: Created symlink /etc/systemd/system/getty.target.wants/getty@ttyGS0.service → /lib/systemd/system/getty@.service. systemctl is-active getty@ttyGS0.service - Checks if the getty service for ttyGS0 is currently active. - Output: active (if running) ``` -------------------------------- ### Enabling SSH on Raspberry Pi SD Card Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-Only-a-Stock-Raspberry-Pi-ZeroW-and-USB-Cable Instructions for enabling SSH access on a Raspberry Pi by creating an empty 'ssh' file on the boot partition of the SD card. ```bash C:\> d: copy nul ssh ``` ```bash $ cd /Volumes/boot $ touch ssh ``` -------------------------------- ### Connecting via Serial Terminal Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-Only-a-Stock-Raspberry-Pi-ZeroW-and-USB-Cable Commands and configurations for connecting to the Raspberry Pi via a serial terminal emulator. ```bash screen -L /dev/cu.usbmodemXXXX 115200 ``` -------------------------------- ### Raspberry Pi Serial Gadget Configuration Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-Only-a-Stock-Raspberry-Pi-ZeroW-and-USB-Cable Configuration steps for enabling the Raspberry Pi ZeroW as a USB Serial Gadget. This involves modifying system files and creating specific configuration files. ```bash dtoverlay=dwc2 ``` ```bash rootwait modules-load=dwc2,g_serial ``` ```bash ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=US network={ id_str="HOTSPOT NAME" ssid="SSID" psk="PASSWORD" key_mgmt=WPA-PSK } ``` ```bash wpa_passphrase "SSID" "PASSWORD" | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null ``` ```bash sudo systemctl enable getty@ttyGS0.service ``` ```bash sudo systemctl is-active getty@ttyGS0.service ``` ```bash sudo shutdown now ``` -------------------------------- ### Tasmota Device Template Example Source: https://github.com/ct-open-source/tuya-convert/wiki/Flashing-of-WiFi-Switch-with-a-Raspberry-Pi A JSON template for configuring a Tasmota device, specifying GPIO pin assignments and device flags. This template is used to define the behavior of the device, such as button presses. ```json {"NAME":"Switch","GPIO":[0,0,0,0,0,17,0,0,21,0,0,0,0],"FLAG":0,"BASE":18} ``` -------------------------------- ### Tuya Convert Troubleshooting Table Source: https://github.com/ct-open-source/tuya-convert/wiki/Troubleshooting This table outlines common symptoms encountered during the Tuya device conversion process, along with their likely reasons and recommended solutions. It covers issues related to device firmware, network connectivity, and script execution. ```markdown |Symptom|Reason|Recommendation| |-------|------|--------------| |Dots never end|Too many possible reasons|Open your logs and try other troubleshooting or seek support by filing a new issue| |Device button unresponsive|Device is not running stock firmware|Check if the device is running intermediate firmware, or configure custom firmware| |Device appears bricked|It may be running intermediate firmware or hasn't been configured yet|Check for `sonoff-****` or `vtrust-recovery` and proceed to troubleshooting| |Device does not take IP `10.42.42.42`|Device is not running intermediate firmware|Do not alter the script, try other troubleshooting or seek support by filing a new issue| |Port 6668 is open or device does not respond on port 80|Device is still running stock firmware|Try other troubleshooting or seek support by filing a new issue| |`Smartlife-****` SSID is visible or device is blinking slowly|Device is in AP config mode|Device must be in EZ config mode (blinking quickly). Hold button for 5 seconds or turn on and off 3 times| |`sonoff-****` SSID is visible|Device is running Tasmota|Connect to the AP and configure your device at `192.168.4.1`| |`vtrust-recovery` SSID is visible|Device is running intermediate firmware but could not connect to `vtrust-flash`|Make sure `start_flash` is running and `vtrust-flash` is visible, then unplug and plug your device back in, wait a minute for script to continue| |`KeyboardInterrupt` exception in log|You ran `stop_flash` or otherwise stopped the script|Nothing, this is not an issue| |`wlan0: Could not connect to kernel driver` in wifi log||Not an issue| |`Socket error on client P1, disconnecting` in mqtt log|Older versions of `tuya-convert` do not disconnect from the broker properly|Not an issue, will not impact the process whatsoever| |`WARNING: it appears this device does not use an ESP82xx and therefore cannot install ESP based firmware` in web log|Device uses a different microcontroller|Nothing else we can do, return the device or use it as is. You will not be able to flash Tasmota or other ESP based firmware, even over wire.| |`vtrust-flash` rejects subsequent connections after the first|`hostapd` is broken on some Raspberry Pi builds ([#241](https://github.com/ct-Open-Source/tuya-convert/issues/241))|See [raspberrypi/firmware#1117](https://github.com/raspberrypi/firmware/issues/1117)| |Repeated requests for `tuya.device.dynamic.config.get` in the web log|Device may be rejecting the fake `schema`|Try to obtain the real schema using `tuyapi` or by capturing the official registration through `tcpdump` and open an issue with this information| |`[SSL: NO_SHARED_CIPHER] no shared cipher` in psk log|Your phone is trying to make HTTPS connections to the outside internet, but we are capturing all HTTPS requests|It will not impact flashing, safe to ignore| |`start_flash` stalls at `Starting AP...` when running over SSH|You are getting disconnected when the wireless interface is used to create the AP|Connect through some other means, secondary wifi, ethernet, USB or control directly| |`vtrust-flash` WLAN does not give devices an IP|firewall blocks DHCP reaching dnsmasq|temporarily turn off firewall| |`vtrust-flash` WLAN does not give devices an IP and logs tell `dnsmasq[2744]: failed to create listening socket for 127.0.0.1: Address already in use`|another service is listening on the device|temporarily disable the other DNS-server, or (if the other service is dnsmasq as well) add `except-interface`| |Backup Times Out|Unknown|This can happen on some devices, and may leave it in an unresponsive state until power cycled. You may need to stop the backup process from occuring to successfully flash ``` -------------------------------- ### Write Firmware with Esptool Source: https://github.com/ct-open-source/tuya-convert/wiki/Flashing-of-WiFi-Switch-with-a-Raspberry-Pi Command to write the Tasmota firmware to an ESP device using esptool.py. This command specifies the serial port, flash mode, and the starting address for the firmware. ```python esptool.py --port /dev/ttyS0 write_flash -fm dout 0x0 tasmota.bin ``` -------------------------------- ### Tuya-Convert Required PIP Packages Source: https://github.com/ct-open-source/tuya-convert/wiki/Failed-attempts-and-tracked-requirements Specifies the Python packages that need to be installed via pip for the Tuya-Convert tool. These include libraries for MQTT communication, asynchronous networking, and cryptographic operations. ```python paho-mqtt==1.5.1 tornado==6.1 pycryptodomex==3.10.1 ``` -------------------------------- ### Disable Wi-Fi via SSH/Terminal Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-a-Raspberry-Pi This command forcefully terminates the `wpa_supplicant` process, effectively disabling the Wi-Fi connection on the Raspberry Pi. Ensure you have an alternative connection method like Ethernet or USB Gadget mode before executing this. ```bash sudo killall wpa_supplicant ``` -------------------------------- ### Disable SSH Service Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-Only-a-Stock-Raspberry-Pi-ZeroW-and-USB-Cable Stops the SSH service and disables it from starting on boot for both Buster and Stretch Raspbian versions. ```bash sudo service ssh stop sudo systemctl disable sshd.service (Buster) sudo systemctl disable ssh.service (Stretch) ``` -------------------------------- ### Ubuntu 16.04 LTS Prerequisite Packages (APT) Source: https://github.com/ct-open-source/tuya-convert/wiki/Failed-attempts-and-tracked-requirements Lists the essential APT packages required for the Tuya-Convert flashing process on Ubuntu 16.04 LTS. These packages include development tools, networking utilities, and Python-related libraries. ```bash git=1:1.2.7.4-0ubuntu1.10 iw=3.17-1 dnsmasq=2.75-1ubuntu0.16.04.10 rfkill=0.5-1ubuntu3.1 hostapd=1:2.4-0ubuntu6.8 screen=4.3.1-2ubuntu0.1 curl=7.47.0-1ubuntu2.19 build-essential=12.1ubuntu2 python3-pip=8.1.1-2ubuntu0.6 python3-setuptools=20.7.0-1 python3-wheel=0.29.0-1 python3-dev=3.5.1-3 mosquitto=1.4.8-1ubuntu0.16.04.7 haveged=1.9.1-3 net-tools=1.60-26ubuntu1 libssl-dev=1.0.2g-1ubuntu4.19 ``` -------------------------------- ### Tasmota Initial Configuration Source: https://github.com/ct-open-source/tuya-convert/blob/master/README.md Instructions for configuring a device flashed with Tasmota firmware. Connect to the 'tasmota-xxxx' AP and access 192.168.4.1 via a browser to set Wi-Fi credentials. ```markdown Connect to the `tasmota-xxxx` access point (AP). Open your browser to `192.168.4.1`. Configure the device's Wi-Fi credentials, ensuring accuracy before saving. ``` -------------------------------- ### Generic 4 gang WiFi Switch (No Neutral) Tasmota Setup Source: https://github.com/ct-open-source/tuya-convert/wiki/Compatible-devices-(HTTPS-firmware) This entry confirms successful flashing of a Generic 4 gang WiFi Switch (No Neutral) and its setup in TuyaMCU mode with Tasmota. ```en Device: Generic 4 gang WiFi Switch (No Neutral) Success: Yes GPIOs: TuyaMCU Notes: Flash completed successfully, set up Tasmota in TuyaMCU mode. ``` -------------------------------- ### ESPurna Initial Configuration Source: https://github.com/ct-open-source/tuya-convert/blob/master/README.md Instructions for configuring a device flashed with ESPurna firmware. Connect to the 'ESPURNA-XXXXXX' AP using the password 'fibonacci' and access 192.168.4.1 via a browser. ```markdown Connect to the `ESPURNA-XXXXXX` access point (AP) with the password `fibonacci`. Open your browser to `192.168.4.1`. Follow the initial configuration instructions, then configure Wi-Fi credentials or upgrade firmware. ``` -------------------------------- ### Properly Shut Down Raspberry Pi Source: https://github.com/ct-open-source/tuya-convert/wiki/Using-Only-a-Stock-Raspberry-Pi-ZeroW-and-USB-Cable Executes the command to safely shut down the Raspberry Pi. ```bash sudo shutdown now ``` -------------------------------- ### Miscellaneous Devices Source: https://github.com/ct-open-source/tuya-convert/wiki/Compatible-devices-(HTTP-firmware) Details on various smart home devices including LED mosquito killers, infrared transceivers, and Wi-Fi enabled fans. Includes vendor, area, device ID, GPIO assignments, and notes on flashing with Tasmota or Esphome. ```markdown |Vendor|Area|Device Name|Vendors device ID|GPIOs|Notes|2nd MCU|Flash size/mode |---------|:--------------:|:-----------:|:---------:|:------------:|:-------------------:|:-----------:|:------------:| |[Oittm](https://www.aliexpress.com/item/Oittm-USB-Smart-WiFi-LED-Mosquito-Killer-Light-Trap-Zapper-Works-with-Alexa-Google-Assistant/32879811540.html)|CN|Smart Mosquito Killer|MK-01|GPIO2=Button1, GPIO15=Led1i (Blue LED), GPIO5=Fan, GPIO12=UV LEDs, GPIO16=White LEDs|Tasmota Generic Module|no|1M QIO |Auvisio|EU|Infrared Transceiver|[NX-4519-675](https://www.pearl.de/a-NX4519-3103.shtml?vid=675)|GPIO4=Led1,GPIO5=IRrecv,GPIO14=IRSend|Tasmota Generic Module|?|1M |[SZMDLX IR Hub](https://www.amazon.com/SZMDLX-Universal-Compatible-Automation-Controlled/dp/B082R44LJM)|Global|Infrared Transceiver|?|GPIO4=Led1(green),GPIO5=IRrecv,GPIO13=Button,GPIO14=IRSend|Used Tasmota Generic to flash Esphome|no|? |[Technical Pro](https://smile.amazon.com/Technical-Pro-Standing-Oscillating-Compatible/dp/B07RM6XQ4L)|US|WIFI Enabled 16 Inch Standing Fan|FXA16(W)|GPIO1=TuyaMCU TX, GPIO3=TuyaMCU RX||Yes|1M ``` -------------------------------- ### Smart Plug GPIO Configurations Source: https://github.com/ct-open-source/tuya-convert/wiki/Compatible-devices-(HTTP-firmware) This section lists various smart plug models and their corresponding GPIO pin assignments for controlling LEDs, buttons, and relays. It also indicates the recommended firmware or module type for flashing. ```APIDOC BN-LINK Smart WiFi Outlet: GPIO2: Led1i GPIO3: Button1 GPIO13: Led2i GPIO14: Relay1 Epicka Smart Plug (WP100): GPIO4: LED1i(Blue) GPIO5: LED2i(Red) GPIO12: Relay1 GPIO13: Button1 Firmware: Tasmota Generic EVA LOGIK Mini Smart Plug (NWF001): GPIO1: Button1 GPIO13: Led1 GPIO14: Relay1 Heygo 02 Wi-Fi Smart Plug: GPIO Mapping: ? Firmware: Espurna 1.13.5 HY02 KING-LINK Outdoor Smart Plug (C128): GPIO04: Relay2 GPIO12: Relay1 GPIO14: Button1 GPIO15: Relay3 GPIO16: Led1i Firmware: Generic Config OxaOxe Wi-Fi Smart Plug (NX-SM800/NX-SP201): Module 18 gpio0 57 gpio12 21 gpio13 17 gpio15 52 gpio4 131 gpio5 134 gpio14 132 Slitinto WiFi Dual Smart Plug (NX-SP201): GPIO0: Led1i GPIO4: Button1 GPIO5: HLW-8012 CF GPIO12: Relay1 GPIO13: Button2 GPIO14: HLW-BL CF1 GPIO15: Relay2 GPIO16: HLW-BL SEL Firmware: Generic Module - Developer Branch Tasmota 02052019 Yeron Wifi Smart Plug (US101): GPIO03: Button1 GPI04: HLW-812 CF GPIO5: HLW-BL CF1 GPIO12: HLW-BL SELi GPIO13: LED1i GPIO14: Relay1 Firmware: Generic Module - Developer Branch Tasmota 02052019 3stone Smart Plug Mini: pin 1: button (low=pressed) pin 13: LED (low=on) pin 14: relay (high=closed) Aicliv Outdoor Smart Socket (AS2100): GPIO3: Relay3 GPIO4: Led2 GPIO12: Relay1 GPIO13: Button2 GPIO14: Relay2 Firmware: Tasmota Generic Albohes Outdoor Smart Socket Dual (PS-1602/PS-1606): GPIO0: Button1 GPIO5: Relay2 GPIO9: Button2 GPIO12: Relay1 Firmware: Tasmota Generic Aneken Smart Socket (SWA5): GPIO15: Relay1 GPIO13: Button1 GPIO2: LED1i Firmware: Tasmota Generic ANIKUV Mini Smart Outlet (YM-WS-1): GPIO12: LED1i GPIO13: Button1 GPIO15: Relay1 Firmware: Wifi-Smart-Plug-ANIKUV-Outlet (Tasmota Generic Module) Bestek Smart Plug (MJR1011): GPIO4: led1i(56) GPIO12: Relay1(21) GPIO13: Button1(17) Firmware: Tasmota Generic BlitzWolf Smart Socket (BW-SHP3): GPIO Mapping: ? Firmware: Tasmota Template (https://blakadder.github.io/templates/blitzwolf_SHP3.html) Blue Shark Wifi Mini Plug (W-US003, MPV2RQ-US): pin 0: blue LED (low=on) pin 13: button (low = pressed) pin 15: relay (high = on) WARNING: not UL/ETL listed! Potentially unsafe. GDTech WiFi Mini Plug (MPV2RO-US): GPIO1: Button1 GPIO13: LED1 (Inverted) GPIO14: Relay1 Geekbes Mini Smart Socket (YM-WS-1): GPIO1: Button1 GPIO13: LED1 GPIO14: Relay1 Firmware: Works with Tasmota Generic Module Gosund Smart Plug (WP3): Firmware: Tasmota Template (https://blakadder.github.io/templates/gosund_wp3.html) Gosund Smart Plug (WP5): GPIO4: Switch1 GPIO12: LED2i GPIO13: LED1i GPIO14: Relay1 Notes: Switch1 / Button1 are interchangeable. Use pins 4, 12, 13, and 14 in an Arduino sketch. HoveBeaty WiFi Smart Outlet (SM-PW701U): GPIO2: LED1i(bright blue) GPIO4: LED2i(dim blue) GPIO12: Relay1 GPIO13: Button1 Red LED tied to relay (no GPIO control) Firmware: Tasmota Generic HugoAI Mini Smart Socket (AWP02L-N): GPIO0: LED2i GPIO2: LED1i GPIO13: Button1 GPIO15: Relay1 Firmware: Tasmota Generic Module KMC 4 Outlet WiFi: GPIO 13: Relay 2 GPIO 14: Relay 3 GPIO 15: Relay 1 GPIO 16: Button Luntak Wifi Smart Plug: GPIO02: LED GPIO13: Button GPIO15: Relay Firmware: Tasmota Generic MartinJerry mini Smart Plug: GPIO04: Led1i GPIO12: Relay1 GPIO13: Button1 Firmware: Tasmota Generic Merkury Outdoor Wifi Smart Plug (MI-OW101-101W): GPIO0: Button1 GPIO5: LED1i GPIO13: LED2 GPIO14: Relay1 Firmware: Same As Geeni GN-OW101-101 Omoton Wifi Smart Socket (W-US002): GPIO1: Button1 GPIO13: Led1 GPIO14: Relay1 Firmware: - ```