Flashing Tuya WT5 dimmer with openbeken

Here is a flashing adventure for WT5 dimmers with opensource OpenBeken firmware.

preparation

Will flash openbeken firmware which is similar to Tasmota, but for chips used in Tuya devices. Got OpenBK7231N_QIO_1.17.451.bin.

I’ve found two flashers:

Here I would use python script, but I have also built a GUI.

Preparing tools.

console flasher

Initialize virtualenv for python flasher and install it.

Full log
 ~/projects/src/github.com/OpenBekenIOT/hid_download_py  λ  python3 -m venv .venv                                                                                                                                                                                                                                         ✖ 2
 ~/projects/src/github.com/OpenBekenIOT/hid_download_py  λ  source ./.venv/bin/activate.fish                                                                                                                                                                                                                        (3s 381ms)
(.venv)  ~/projects/src/github.com/OpenBekenIOT/hid_download_py  λ  pip install -r requirements.txt
Collecting hid (from -r requirements.txt (line 1))
  Using cached hid-1.0.5-py3-none-any.whl
Collecting pyserial (from -r requirements.txt (line 2))
  Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Collecting tqdm (from -r requirements.txt (line 3))
  Obtaining dependency information for tqdm from https://files.pythonhosted.org/packages/00/e5/f12a80907d0884e6dff9c16d0c0114d81b8cd07dc3ae54c5e962cc83037e/tqdm-4.66.1-py3-none-any.whl.metadata
  Using cached tqdm-4.66.1-py3-none-any.whl.metadata (57 kB)
Using cached tqdm-4.66.1-py3-none-any.whl (78 kB)
Installing collected packages: pyserial, hid, tqdm
Successfully installed hid-1.0.5 pyserial-3.5 tqdm-4.66.1

[notice] A new release of pip is available: 23.2.1 -> 24.0
[notice] To update, run: pip install --upgrade pip
(.venv)  ~/projects/src/github.com/OpenBekenIOT/hid_download_py  λ  pip install .                                                                                                                                                                                                                                      (836ms)
Processing /home/user/projects/src/github.com/OpenBekenIOT/hid_download_py
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: hid_downloader
  Building wheel for hid_downloader (pyproject.toml) ... done
  Created wheel for hid_downloader: filename=hid_downloader-1.0-py3-none-any.whl size=27196 sha256=863b8b7d4cefd01dc50c74d31c9576f1f0e4078f3677e11e2f280caf0aafb52d
  Stored in directory: /tmp/pip-ephem-wheel-cache-fiitn79r/wheels/da/26/d2/3d735db9f06e1e2d04f0d162ae3c73c5b255d462e0c372acee
Successfully built hid_downloader
Installing collected packages: hid_downloader
Successfully installed hid_downloader-1.0

[notice] A new release of pip is available: 23.2.1 -> 24.0
[notice] To update, run: pip install --upgrade pip

Script uartprogram should work now.

gui flasher

This flasher written in C# and could be built with Mono under Linux.

Full log
 ~/projects/src/github.com/openshwprojects/BK7231GUIFlashTool  λ  xbuild

>>>> xbuild tool is deprecated and will be removed in future updates, use msbuild instead <<<<

XBuild Engine Version 14.0
Mono, Version 6.12.0.182
Copyright (C) 2005-2013 Various Mono authors

Build started 2/5/2024 11:04:12 PM.
__________________________________________________
/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher.sln:  warning : Don't know how to handle GlobalSection ExtensibilityGlobals, Ignoring.
Project "/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher.sln" (default target(s)):
	Target ValidateSolutionConfiguration:
		Building solution configuration "Debug|Any CPU".
	Target Build:
		Project "/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/BK7231Flasher.csproj" (default target(s)):
			Target PrepareForBuild:
				Configuration: Debug Platform: AnyCPU
				Created directory "bin/Debug/"
				Created directory "obj/Debug/"
			Target CopyFilesMarkedCopyLocal:
				Copying file from '/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/packages/Newtonsoft.Json.13.0.3/lib/net35/Newtonsoft.Json.dll' to '/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/bin/Debug/Newtonsoft.Json.dll'
			Target GenerateResources:
				Tool /nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/4.5/resgen.exe execution started with arguments: /useSourcePath /compile "FormDownloader.resx,obj/Debug/BK7231Flasher.FormDownloader.resources"
				Tool /nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/4.5/resgen.exe execution started with arguments: /useSourcePath /compile "FormExtractedConfig.resx,obj/Debug/BK7231Flasher.FormExtractedConfig.resources"
				Tool /nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/4.5/resgen.exe execution started with arguments: /useSourcePath /compile "FormMain.resx,obj/Debug/BK7231Flasher.FormMain.resources"
				Tool /nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/4.5/resgen.exe execution started with arguments: /useSourcePath /compile "FormOBKConfig.resx,obj/Debug/BK7231Flasher.FormOBKConfig.resources"
				Tool /nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/4.5/resgen.exe execution started with arguments: /useSourcePath /compile "FormPin.resx,obj/Debug/BK7231Flasher.FormPin.resources"
				Tool /nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/4.5/resgen.exe execution started with arguments: /useSourcePath /compile "FormPrompt.resx,obj/Debug/BK7231Flasher.FormPrompt.resources"
				Tool /nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/4.5/resgen.exe execution started with arguments: /useSourcePath /compile "Properties/Resources.resx,obj/Debug/BK7231Flasher.Properties.Resources.resources"
			Target GenerateSatelliteAssemblies:
			No input files were specified for target GenerateSatelliteAssemblies, skipping.
			Target CoreCompile:
				Tool /nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/4.5/csc.exe execution started with arguments: /noconfig /debug:full /debug:portable /optimize- /out:obj/Debug/BK7231Flasher.exe /resource:obj/Debug/BK7231Flasher.FormDownloader.resources /resource:obj/Debug/BK7231Flasher.FormExtractedConfig.resources /resource:obj/Debug/BK7231Flasher.FormMain.resources /resource:obj/Debug/BK7231Flasher.FormOBKConfig.resources /resource:obj/Debug/BK7231Flasher.FormPin.resources /resource:obj/Debug/BK7231Flasher.FormPrompt.resources /resource:obj/Debug/BK7231Flasher.Properties.Resources.resources BitUtils.cs BK7231Flasher.cs BKFlashList.cs Colors.cs ConfigBase.cs CRC.cs FormDownloader.cs FormDownloader.Designer.cs FormExtractedConfig.cs FormExtractedConfig.Designer.cs FormMain.cs FormMain.Designer.cs FormMain_Net_Scanner.cs FormMain_Net_SingleDevice.cs FormMain_TuyaConfigExtractor.cs FormOBKConfig.cs FormOBKConfig.Designer.cs FormPin.cs FormPin.Designer.cs FormPrompt.cs FormPrompt.Designer.cs ILogListener.cs MiscUtils.cs ModifyProgressBarColor.cs MySettings.cs OBKConfig.cs OBKDeviceAPI.cs OBKFlags.cs OBKFlashLayout.cs OBKMassBackup.cs OBKRoles.cs OBKScanner.cs Program.cs Properties/AssemblyInfo.cs Rand.cs RequiredLibrariesCheck.cs TuyaConfig.cs RFPartitionUtil.cs RichTextUtil.cs SecurityProtocolTypeExtensions.cs TuyaModules.cs Properties/Resources.Designer.cs Properties/Settings.Designer.cs /target:winexe /win32icon:bk_icon.ico /define:"DEBUG;TRACE" /nostdlib /platform:AnyCPU /reference:../packages/Newtonsoft.Json.13.0.3/lib/net35/Newtonsoft.Json.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/2.0-api/System.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/2.0-api/System.Data.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/gac/System.Deployment/4.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/2.0-api/System.Drawing.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/2.0-api/System.Net.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/2.0-api/System.Windows.Forms.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/2.0-api/System.Xml.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/2.0-api/System.Core.dll /reference:/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/2.0-api//mscorlib.dll /warn:4
				Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
				Copyright (C) Microsoft Corporation. All rights reserved.
FormMain.cs(170,17): warning CS0162: Unreachable code detected
FormMain.cs(161,29): warning CS0168: The variable 'ex' is declared but never used
FormPin.cs(46,29): warning CS0168: The variable 'ex' is declared but never used
FormOBKConfig.cs(44,30): warning CS0168: The variable 'ex' is declared but never used
FormMain.cs(279,29): warning CS0168: The variable 'ex' is declared but never used
BK7231Flasher.cs(371,30): warning CS0168: The variable 'ex' is declared but never used
OBKFlashLayout.cs(38,29): warning CS0168: The variable 'ex' is declared but never used
FormOBKConfig.cs(171,21): warning CS0162: Unreachable code detected
BK7231Flasher.cs(493,37): warning CS0168: The variable 'ex' is declared but never used
TuyaConfig.cs(149,30): warning CS0168: The variable 'ex' is declared but never used
FormOBKConfig.cs(336,29): warning CS0168: The variable 'ex' is declared but never used
OBKDeviceAPI.cs(443,30): warning CS0168: The variable 'ex' is declared but never used
FormMain.cs(696,30): warning CS0168: The variable 'ex' is declared but never used
FormMain.cs(742,30): warning CS0168: The variable 'ex' is declared but never used
FormMain.cs(828,13): warning CS0162: Unreachable code detected
FormMain.cs(843,13): warning CS0162: Unreachable code detected
FormMain.cs(941,29): warning CS0168: The variable 'ex' is declared but never used
FormMain.cs(1233,30): warning CS0168: The variable 'ex' is declared but never used
BK7231Flasher.cs(31,14): warning CS0649: Field 'BK7231Flasher.bDebugUART' is never assigned to, and will always have its default value false
			Target _CopyAppConfigFile:
				Copying file from '/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/app.config' to '/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/bin/Debug/BK7231Flasher.exe.config'
			Target DeployOutputFiles:
				Copying file from '/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/obj/Debug/BK7231Flasher.pdb' to '/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/bin/Debug/BK7231Flasher.pdb'
				Copying file from '/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/obj/Debug/BK7231Flasher.exe' to '/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/bin/Debug/BK7231Flasher.exe'
		Done building project "/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/BK7231Flasher.csproj".
Done building project "/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher.sln".

Build succeeded.

Warnings:

/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher.sln:  warning : Don't know how to handle GlobalSection ExtensibilityGlobals, Ignoring.

/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher.sln (default targets) ->
(Build target) ->
/home/user/projects/src/github.com/openshwprojects/BK7231GUIFlashTool/BK7231Flasher/BK7231Flasher.csproj (default targets) ->
/nix/store/3y3gbf12dg4wz4lqn4qjjnr4bz79cm74-mono-6.12.0.182/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) ->

	FormMain.cs(170,17): warning CS0162: Unreachable code detected
	FormMain.cs(161,29): warning CS0168: The variable 'ex' is declared but never used
	FormPin.cs(46,29): warning CS0168: The variable 'ex' is declared but never used
	FormOBKConfig.cs(44,30): warning CS0168: The variable 'ex' is declared but never used
	FormMain.cs(279,29): warning CS0168: The variable 'ex' is declared but never used
	BK7231Flasher.cs(371,30): warning CS0168: The variable 'ex' is declared but never used
	OBKFlashLayout.cs(38,29): warning CS0168: The variable 'ex' is declared but never used
	FormOBKConfig.cs(171,21): warning CS0162: Unreachable code detected
	BK7231Flasher.cs(493,37): warning CS0168: The variable 'ex' is declared but never used
	TuyaConfig.cs(149,30): warning CS0168: The variable 'ex' is declared but never used
	FormOBKConfig.cs(336,29): warning CS0168: The variable 'ex' is declared but never used
	OBKDeviceAPI.cs(443,30): warning CS0168: The variable 'ex' is declared but never used
	FormMain.cs(696,30): warning CS0168: The variable 'ex' is declared but never used
	FormMain.cs(742,30): warning CS0168: The variable 'ex' is declared but never used
	FormMain.cs(828,13): warning CS0162: Unreachable code detected
	FormMain.cs(843,13): warning CS0162: Unreachable code detected
	FormMain.cs(941,29): warning CS0168: The variable 'ex' is declared but never used
	FormMain.cs(1233,30): warning CS0168: The variable 'ex' is declared but never used
	BK7231Flasher.cs(31,14): warning CS0649: Field 'BK7231Flasher.bDebugUART' is never assigned to, and will always have its default value false

	20 Warning(s)
	0 Error(s)

Time Elapsed 00:00:02.9161710
 ~/projects/src/github.com/openshwprojects/BK7231GUIFlashTool  λ  ls -la BK7231Flasher/bin/Debug/                                                                                                                                                                                                                    (3s 96ms)
.rw-r--r-- 271k user  5 Feb 23:04 BK7231Flasher.exe
.rw-r--r--  134 user  5 Feb 23:01 BK7231Flasher.exe.config
.rw-r--r--  74k user  5 Feb 23:04 BK7231Flasher.pdb
.rw-r--r-- 516k user  5 Feb 23:01 Newtonsoft.Json.dll
 ~/projects/src/github.com/openshwprojects/BK7231GUIFlashTool  λ  mono --version
Mono JIT compiler version 6.12.0.182 (tarball Mon Jan 22 11:28:14 UTC 2024)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug
	Interpreter:   yes
	LLVM:          supported, not enabled.
	Suspend:       hybrid
	GC:            sgen (concurrent by default)
 ~/projects/src/github.com/openshwprojects/BK7231GUIFlashTool  λ  xbuild --version

>>>> xbuild tool is deprecated and will be removed in future updates, use msbuild instead <<<<

XBuild Engine Version 14.0
Mono, Version 6.12.0.182
Copyright (C) 2005-2013 Various Mono authors
MSBUILD: error MSBUILD0000: Project file '--version' not found.

Now it should be runnable with mono ./BK7231Flasher/bin/Debug/BK7231Flasher.exe.

flashing chip

Well, to be honest, we are not flashing cb3s chip, which is just a wireless communication chip, we are using it to access BK7231 serial.

here is pinout from https://developer.tuya.com/en/docs/iot/cb3s?id=Kai94mec0s076

Pins we would connect UART to:

  • VCC 8
  • GND 9
  • RXD1 15
  • TXD1 16

I have soldered thin copper wires to this pins & connected my USB UART.