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

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.

Somebody from community got a nice video which shows what to do https://www.youtube.com/watch?v=F1hV6AIMZXU

In my case flashing went smoothly, I’ve need to reboot device for a few times rerunning uartprogram.

(.venv)  ~/projects/src/github.com/OpenBekenIOT/hid_download_py  λ  uartprogram OpenBK7231N_QIO_1.17.451.bin -d /dev/ttyUSB0 -w -u -s 0x0
UartDownloader....
programm....
Write Successful: |##################################################|[ 15.3k/s]

After that OpenBK7231N_REDACTED open network appeared. Device web interface is at http://192.168.4.1

secure way to configure wifi network

I have discovered serial command interface is not working. I don’t like the idea of filling in wifi network password using unprotected network (this is horrible idea).

More information

Startup script was:

startDriver TuyaMCU
tuyaMcu_setBaudRate 115200
SetFlag 31 1
logPort 1

Connected to UART using:

picocom /dev/ttyUSB0 --baud 115200 --parity n --databits 8 --stopbits 1 --omap crcrlf
  • input was echoed to me (which is expected)
  • all commands ignored
  • have tried different omap’s without success

So, we will try to build firmware with hardcoded ssid & password.

TL;DR modified default configuration, but haven’t found any way to reset previously saved configuration on device, so flashed firmware which enforced default configuration then reflashed original firmware.

Boring details

Let’s prepare build environment:

 ~/projects/src/github.com/openshwprojects/OpenBK7231T_App  λ  cd docker/                                                                                                                                                                                                                                       (3m 27s 871ms)
 ~/projects/src/github.com/openshwprojects/OpenBK7231T_App/docker  λ  sudo docker build -t openbk_build --build-arg USERNAME=$USER .
[sudo] password for user:
[+] Building 182.5s (12/12) FINISHED                                                                                                                                                                                                                                                                            docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                      0.1s
 => => transferring dockerfile: 764B                                                                                                                                                                                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                         0.1s
 => => transferring context: 2B                                                                                                                                                                                                                                                                                           0.0s
 => [internal] load metadata for docker.io/library/ubuntu:20.04                                                                                                                                                                                                                                                           2.7s
 => [1/7] FROM docker.io/library/ubuntu:20.04@sha256:bb1c41682308d7040f74d103022816d41c50d7b0c89e9d706a74b4e548636e54                                                                                                                                                                                                     4.2s
 => => resolve docker.io/library/ubuntu:20.04@sha256:bb1c41682308d7040f74d103022816d41c50d7b0c89e9d706a74b4e548636e54                                                                                                                                                                                                     0.0s
 => => sha256:18ca3f4297e795532c0d053ba443d392d5d316ee83ddee0de27f1e742a7db273 2.30kB / 2.30kB                                                                                                                                                                                                                            0.0s
 => => sha256:8ee0874247356ecb5ea92128219660506b139dcb6cc45dcab84d98b3c6485061 27.51MB / 27.51MB                                                                                                                                                                                                                          2.8s
 => => sha256:bb1c41682308d7040f74d103022816d41c50d7b0c89e9d706a74b4e548636e54 1.13kB / 1.13kB                                                                                                                                                                                                                            0.0s
 => => sha256:a4fab1802f08df089c4b2e0a1c8f1a06f573bd1775687d07fef4076d3a2e4900 424B / 424B                                                                                                                                                                                                                                0.0s
 => => extracting sha256:8ee0874247356ecb5ea92128219660506b139dcb6cc45dcab84d98b3c6485061                                                                                                                                                                                                                                 1.1s
 => [internal] load build context                                                                                                                                                                                                                                                                                         0.1s
 => => transferring context: 1.58kB                                                                                                                                                                                                                                                                                       0.0s
 => [2/7] RUN dpkg --add-architecture i386  && apt-get update  && apt-get upgrade -y  && apt-get install -y                 wget git python3 python-is-python3 python3-pip                 libc6-i386 make                 build-essential cmake gcc-arm-none-eabi                                                      159.1s
 => [3/7] RUN pip3 install pycryptodomex configobj toml fdt                                                                                                                                                                                                                                                               3.3s
 => [4/7] RUN useradd -m -s /bin/bash user                                                                                                                                                                                                                                                                                0.5s
 => [5/7] COPY build_target_platforms.sh /build_target_platforms.sh                                                                                                                                                                                                                                                       0.2s
 => [6/7] RUN chmod 775 /build_target_platforms.sh                                                                                                                                                                                                                                                                        0.3s
 => [7/7] RUN mkdir -p /${OpenBK7231T_App} && chown user /${OpenBK7231T_App}                                                                                                                                                                                                                                              0.4s
 => exporting to image                                                                                                                                                                                                                                                                                                   11.5s
 => => exporting layers                                                                                                                                                                                                                                                                                                  11.4s
 => => writing image sha256:924ddc798bc8af58a97aacf638eb7e82f454700043e18f5fd70a49e4caf48d60                                                                                                                                                                                                                              0.0s
 => => naming to docker.io/library/openbk_build

Prepare patch with wifi credentials written to default configuration:

diff --git src/new_cfg.c src/new_cfg.c
index d89bb19d..89a2d06b 100644
--- src/new_cfg.c
+++ src/new_cfg.c
@@ -122,9 +122,10 @@ void CFG_SetDefaultConfig() {
        // g_cfg.mqtt_clientId is set as shortDeviceName below
        strcpy(g_cfg.mqtt_userName, "homeassistant");
        strcpy(g_cfg.mqtt_pass, "qqqqqqqqqq");
-       // already zeroed but just to remember, open AP by default
-       g_cfg.wifi_ssid[0] = 0;
-       g_cfg.wifi_pass[0] = 0;
+
+       strcpy(g_cfg.wifi_ssid, "REDACTED");
+       strcpy(g_cfg.wifi_pass, "REDACTED");
+
        // i am not sure about this, because some platforms might have no way to store mac outside our cfg?
        memcpy(g_cfg.mac,mac,6);
        strcpy(g_cfg.webappRoot, "https://openbekeniot.github.io/webapp/");

Run the build environment:

 ~/projects/src/github.com/openshwprojects/OpenBK7231T_App/docker  λ  sudo docker run --env TARGET_SDKS=OpenBK7231N -it -v "$(pwd)/..":/OpenBK7231T_App openbk_build                                                                                                                                         ✖ 130 (39s 969ms)
/build_target_platforms.sh: line 3: shell: command not found
****************************************
****************************************

Building OpenBeken for the following platforms: OpenBK7231N
Building OpenBeken with version "dev_20240206_044539"


****************************************
Building platform: OpenBK7231N
****************************************

make -C sdk/OpenBK7231T/platforms/bk7231t/bk7231t_os APP_BIN_NAME=OpenBK7231T_App USER_SW_VER=dev_20240206_044539 clean
make[1]: *** sdk/OpenBK7231T/platforms/bk7231t/bk7231t_os: No such file or directory.  Stop.
make: *** [Makefile:153: clean] Error 2
make APP_NAME=OpenBK7231N TARGET_PLATFORM=bk7231n SDK_PATH=sdk/OpenBK7231N APPS_BUILD_PATH=../bk7231n_os build-BK7231
make[1]: Entering directory '/OpenBK7231T_App'
git submodule update --init --recursive --remote
Cloning into '/OpenBK7231T_App/sdk/OpenBK7231N'...
Cloning into '/OpenBK7231T_App/sdk/OpenBK7231T'...
Cloning into '/OpenBK7231T_App/sdk/OpenBL602'...
Cloning into '/OpenBK7231T_App/sdk/OpenLN882H'...
Cloning into '/OpenBK7231T_App/sdk/OpenW600'...
Cloning into '/OpenBK7231T_App/sdk/OpenW800'...
Cloning into '/OpenBK7231T_App/sdk/OpenXR809'...
Submodule path 'sdk/OpenBK7231N': checked out '244bdfe86a1dd4324038814f3ebb8ebb24117dfb'
Submodule path 'sdk/OpenBK7231T': checked out '12c68122b61da686df8b77a6577857ac05b55cbf'
Submodule path 'sdk/OpenBL602': checked out 'e5769160cfc91a5fe36f040b3d5314e51eda3a28'
Submodule path 'sdk/OpenLN882H': checked out '50761b5a505bd04b23fba6d5c7a77b05330beaf9'
Submodule path 'sdk/OpenW600': checked out 'ad8f51d064a78465ec1845287cf19c3a24c655b8'
Submodule path 'sdk/OpenW800': checked out 'bc2c41e0271f1018bdb66cebddf592de7b7a571d'
Submodule path 'sdk/OpenXR809': checked out '3e8cd2f98075aa89bb1fbafd7871a8bb61360612'
Create symlink for OpenBK7231N into sdk folder
ln -s "/OpenBK7231T_App/" "sdk/OpenBK7231N/apps/OpenBK7231N"
cd sdk/OpenBK7231N/platforms/bk7231n/toolchain/../bk7231n_os && sh build.sh OpenBK7231N dev_20240206_044539 bk7231n
APP_BIN_NAME=OpenBK7231N
APP_VERSION=dev_20240206_044539
TARGET_PLATFORM=bk7231n
USER_CMD=
Start Compile
system:Linux
not is ci build
make[2]: Entering directory '/OpenBK7231T_App/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os'
fatal: No annotated tags can describe '244bdfe86a1dd4324038814f3ebb8ebb24117dfb'.
However, there were unannotated tags: try --tags.
make[3]: Entering directory '/OpenBK7231T_App/sdk/OpenBK7231N/platforms/bk7231n/bk7231n_os'
echo prerequirement0
prerequirement0
===========================================================
Build OpenBK7231N
===========================================================
echo prerequirement1
prerequirement1
mkdir -p Debug/obj
mkdir -p Debug/bin
build beken378/app/app_bk.o
echo prerequirement2
prerequirement2
build beken378/app/ate_app.o
build beken378/app/config/param_config.o
build beken378/app/standalone-ap/sa_ap.o
build beken378/app/standalone-station/sa_station.o
build beken378/demo/ieee802_11_demo.o
...
Done building OpenBeken for the following platforms: OpenBK7231N
Find outputs in: ../output/dev_20240206_051229

Build artifacts:

 ~/projects/src/github.com/openshwprojects/OpenBK7231T_App/docker  λ  tree ../output/dev_20240206_051229/
../output/dev_20240206_051229/
├── OpenBK7231N_dev_20240206_051229.asm
├── OpenBK7231N_dev_20240206_051229.axf
├── OpenBK7231N_dev_20240206_051229.bin
├── OpenBK7231N_dev_20240206_051229.map
├── OpenBK7231N_dev_20240206_051229.rbl
├── OpenBK7231N_QIO_dev_20240206_051229.bin
├── OpenBK7231N_UA_dev_20240206_051229.bin
└── OpenBK7231N_UG_dev_20240206_051229.bin

1 directory, 8 files

Flash new version:

 ~/projects/src/github.com/openshwprojects/OpenBK7231T_App/output  λ  cp dev_20240206_051229/OpenBK7231N_QIO_dev_20240206_051229.bin ~/projects/src/github.com/OpenBekenIOT/hid_download_py
(.venv)  ~/projects/src/github.com/OpenBekenIOT/hid_download_py  λ  uartprogram OpenBK7231N_QIO_dev_20240206_051229.bin -d /dev/ttyUSB0 -w -u -s 0x0
UartDownloader....
programm....
Write Successful: |##################################################|[ 15.3k/s]

Device preserves configuration after flashing, which is good, but… there is no obvious way to reset this configuration (why in the world have you not implemented such an obvious thing?)

Let’s try reverting to GUI flasher, because it could somehow set this settings.

This doesn’t help. Such a horrible UX.

Ok, force default config:

diff --git src/new_cfg.c src/new_cfg.c
index d89bb19d..6e61d2c5 100644
--- src/new_cfg.c
+++ src/new_cfg.c
@@ -726,6 +727,10 @@ void CFG_InitAndLoad() {
                addLogAdv(LOG_WARN, LOG_FEATURE_CFG, "CFG_InitAndLoad: Correct config has been loaded with %i changes count.",g_cfg.changeCounter);
        }

+       CFG_SetDefaultConfig();
+       // mark as changed
+       g_cfg_pendingChanges ++;
+
        // copy shortDeviceName to MQTT Client ID, set version=3
        if (g_cfg.version<3) {
                addLogAdv(LOG_WARN, LOG_FEATURE_CFG, "CFG_InitAndLoad: Old config version found, updating to v3.");

And after this change I finally see device connected to my private network! (don’t forget to revert last change and flash original firmware)

God damn it, openbeken, why you can’t just be like Tasmota?! Wasted horrible amount of time solving such a usual thing.

configuration & MQTT

Here is minimal configuration which will setup this device as dimmer:

startDriver TuyaMCU
tuyaMcu_setBaudRate 115200
SetFlag 31 1
logPort 1
loglevel 3
startDriver SSDP
PowerSave 1
tuyaMcu_setDimmerRange 0 1000
setChannelType 20 toggle
setChannelType 21 toggle
setChannelType 22 dimmer
setChannelType 23 dimmer
linkTuyaMCUOutputToChannel 20 1 20
linkTuyaMCUOutputToChannel 21 1 21
linkTuyaMCUOutputToChannel 22 2 22
linkTuyaMCUOutputToChannel 23 2 23

MQTT support is available (see Mqtt* here).

Sample messages while triggering previously configured outputs (non RGB led strip):

$ mosquitto_sub -v -t 'OpenBK7231N_XXXXXXX/#'
OpenBK7231N_XXXXXXX/connected online
OpenBK7231N_XXXXXXX/22/get 42
OpenBK7231N_XXXXXXX/22/get 66
OpenBK7231N_XXXXXXX/22/get 90
OpenBK7231N_XXXXXXX/22/get 0
OpenBK7231N_XXXXXXX/22/get 5
OpenBK7231N_XXXXXXX/20/get 0
OpenBK7231N_XXXXXXX/20/get 1
OpenBK7231N_XXXXXXX/22/get 30
OpenBK7231N_XXXXXXX/22/get 100
OpenBK7231N_XXXXXXX/22/get 11
OpenBK7231N_XXXXXXX/20/get 0
OpenBK7231N_XXXXXXX/20/get 1
OpenBK7231N_XXXXXXX/22/get 31
OpenBK7231N_XXXXXXX/22/get 60
OpenBK7231N_XXXXXXX/22/get 9

Could be controlled using:

1 & 0 are boolean on & off, 90 is percent value of brightness

$ mosquitto_pub -t 'OpenBK7231N_XXXXXXX/20/set' -m '1'
$ mosquitto_pub -t 'OpenBK7231N_XXXXXXX/22/set' -m '90'
$ mosquitto_pub -t 'OpenBK7231N_XXXXXXX/20/set' -m '0'