showing how OpenBK7231T can be made to work with Domoticz
While walking aimlessly in the aisles of a typical Canadian drug store with its numerous of over-the-counter drugs, "health" products, cosmetics, greeting cards, unhealthy snacks and over-priced, low-quality electronic doodads, I happened on a Globe Outdoor Smart Plug (sku 50151) among the discounted, end-of-line products at the back. The package had some information, the most important being that it was a 2.4 GHz Wi-Fi device controlled with an IOS or Android application called Globe Suite. That screamed Tuya but there was no information about the actual microcontroller. At only $12, the two-socket plug was a good bet because, even if the Globe Suite had to be used, it would look a lot better than the Sonoff Basic stuffed into an upturned peanut butter jar used to control the outdoor Christmas lights in the past.
As usual, I make no claim to be knowledgable about the Beken microcontroller and until about four days ago, I was not even aware of the existence of the Tasmota-like OpenBK7231T_App firmware and its associated SDK. There is a marked probability that what follows is not the most optimal way or even a desirable way of proceeding.
Table of Content
- The Smart Two Outlet Wi-Fi Outdoor Plug
- BEKEN BK7231T
- Installing Tuya Cloudcutter
- Uploading and Configuring OpenBK7231_App
- Better Button and LEDs
- Domoticz Integration
- Download
The Smart Two Outlet Wi-Fi Outdoor Plug
At home, the smart plug (a misnommer because, surely, the important bits of the device are the two remotely controlled sockets) was liberated from its sealed packaging. It's label, in French and English to comply with Canadian standards, contained the following information.
The Blakadder Tasmota database has an entry for the Globe 2-Outlet Outdoor Plug (50029) which is close enough given the MODEL numbers on the device label. Unfortunately, the entry ended with
So it seemed unlikely that the plug contained an ESP. Even if it did, it was more than likely that Tuya-Convert would not work because the ESP Tuya firmware would not be old enough (assuming the 1122 date code means 11th week or 11th month of 2022). So I opened the plug which was surprisingly easy to do, especially as it is a rain resistant outdoor device. The two halves of the shell are held together with three screws only; without glue, sealing compound or catches. Once inside, the microcontroller was easily identified: a BK7231T by Beken which meant nothing to me.
The first image is from the FCC listing 2AQUQGE50151. On the other side of the circuit board, there are well-labelled pads connected to UART pins of the chip which looked very promising if some suitable firmware was available. The image is from a breakdown of a PRIME Wi-Fi Smart Outlets device sold by Costco in Canada done by p.kaczmarek2. Here, in no particular order, are other references found.
- BK7231 datasheet, pinout, programming, specification, wiki (BK7231T, BK7231N)
- Elektroda YouTube Channel
- OpenBK7231T_App
- BK7231 GUI Flash Tool
- Tuya Cloudcutter
- globe-electric-50151-smart-2-outlet-outdoor-plug.json
As often the case when tackling something new, I was suffering from information overload, but it was enough to convince me to buy the second remaining smart plug from the pharmacy with the anticipation that it would be possible to use these devices. There's also another reason for getting the second unit. I found that the device was sold by a well-known Canadian retailer for $32 although it is no longer available for sale at least locally.
Who could pass up a $40 savings and the opportunity to spend hours trying to get acquainted with yet another microprocessor?
BEKEN BK7231T
The BK7231T and BK7231N are WiFi & Bluetooth SoCs used widely in Tuya Smart products such as smart sockets, switches, lights and sensors. Much like the ESP SoC, the BK7231 SoC can be used directly in a product (as in the Globe Smart Plug) or it can be mounted in a module (CB2S, WB2S, WB2L, WB3S, etc.) which is often pin-for-pin compatible with an ESP module (TYWE2S, TYWE3S, ESP12, etc.).
The BK7231T and BK7231N share many characteristics.
1. MCU frequency up to 120 MHz 2. 256 Kbyte internal data RAM 3. In package 2Mbyte FLASH (T) up to 4Mbyte (M) 4. SDIO, PwM, I2C and SPI 5. Multi-channel 10bit ADC 6. Six 16-bits (T) or 32-bits(M) timers 7. IEEE 802.11 b/g/n 1x1 Compliant 8. Wi-Fi modes: STA and SoftAP
It looks like the N variant is an upgrade of the T variant, but I could not find much information at Bekendcorp
. The BK7231 datasheet, pinout, programming, specification, wiki (BK7231T, BK7231N) post by p.kaczmarer2 is the best source of information found so far.
Installing Tuya Cloudcutter
Van_b's post [BK7231T (Onboard/No Module)] Globe Electric - Outdoor 2-Outlet Smart Plug - Guide, especially the section entitled What you should do (the easy way)
was a breakthrough. It contained simple, indeed terse, instructions on using Tuya Cloudcutter to flash a Tasmota like firmware, OpenBK7231T_App, onto the device which is done over the air using an exploit much like Tuya-Convert did a few years back for ESP based Tuya devices.
Here, in broad strokes, is the procedure I used to install Tuya Cloudcutter on the first Raspberry Pi I found. It was an almost first generation Pi: a quad core 32-bits model B v1.2 from 2014 with a USB-WiFi dongle. That was a mistake of sorts as will be explained.
- Install Raspberry Pi OS (Lite) on an micro SD card using Raspberry Imager.
The hostname was set to
cutter
and the user was set tomichel
. - Update and upgrade the OS.
michel@cutter:~ $ date ; sudo apt update && sudo apt upgrade -y ; dateAs timed with the
date
commands, that took 58 minutes! - Install
git
michel@cutter:~ $ sudo apt install git - Install
docker
michel@cutter:~ $ curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.shThank you simplymaker because I know nothing about docker. - Install
Tuya Cloudcuttter
michel@cutter:~ $ git clone https://github.com/tuya-cloudcutter/tuya-cloudcutter - Update
Tuya Cloudcuttter
michel@cutter:~ $ cd tuya-cloudcutter michel@cutter:~ $ git pull - Obtain
OpenBK7231_App
michel@cutter:~ $ cd custom-firmware michel@cutter/tuya-cloudcutter/custom-firmware$ wget https://github.com/openshwprojects/OpenBK7231T_App/releases/download/1.17.776/OpenBK7231T_UG_1.17.776.binOf course, adjust the link as new releases become available. - Fail to Run
Tuya Cloudcutter
michel@cutter/tuya-cloudcutter/custom-firmware$ cd .. michel@cutter:~/tuya-cloudcutter $ sudo ./tuya-cloudcutter.sh -p globe-electric-50151-smart-2-outlet-outdoor-plug -f OpenBK7231T_UG_1.17.776.bin [!] WARNING: Selected wifi AP support: no AP support is manditory for tuya-cloudcutter to work. If this is blank or 'no' your adapter doesn't support this feature. Press any key to continue, or CTRL+C to exitEven before starting to set up the Tuya Cloudcutter docker image, thetuya-cloudcutter.sh
script bailed out because the Wi-Fi dongle could not be put in AP mode. - Move to a Raspberry Pi 3B
Press the CTRL+C keyboard combination as instructed and then shut down the system properly.michel@cutter:~/tuya-cloudcutter $ sudo shutdown now Broadcast message from root@cutter on pts/1 (Wed 2024-11-27 04:43:34 AST): The system will power off now!
The microSD card on the older Pi B (v1.12) was inserted into a Pi 3 B which was then powered up. It worked as shown below. Have to say that the continued support for almost all their hardware by the Raspeberry Pi team is superb. Because of that, choosing the old Pi B initially was a painless mistake.
Uploading and Configuring OpenBK7231_App
Tuya Cloudcutter runs in a Docker image which will be built the first time the installation script is run. That takes a considerable amount of time, 11 minutes, as many packages had to be downloaded and installed: hostapd, rfkill, dnsmasq, build-essential, libssl-dev, iproute2, mosquitto
.
Luckily, only 3.3 seconds were needed to start the docker image after that initial build. The value of the -p
parameter is a json device configuration file in the tuya-cloudcutter
repository. Once the docker image is up, the cloudcutter application starts with the following advice.
I did my best to perform each step as instructed and luckily uploading the new firmware to both of the plugs was successful. However, the procedure was not the same for unknown reasons. Consequently there is no real point in showing the details. In both cases, the process ended with the OpenBK7231T_App firmware starting an access point to which my desktop machine was connected.
Once connected to the AP, access to the Web interface of the modified smart plug is at 192.168.4.1
.
From that point on, it's a matter of configuring the firmware.
Configuring Wi-Fi and MQTT was pretty standard stuff, very similar to how it is done Tasmota. I also configured the Names
, but that is not essential. After that the device was restarted: Home » Restart
. The plug closed its access point and then connected to the Wi-Fi network as a Wi-Fi client (STA). I used the router to find its IP address. It turned out to be 192.168.1.146
.
I do not recall if I had to configure the module manually given that the tuya-cloudcutter
script was given the module name. Assuming that the module was not configured, open the smart plug's web page at http://192.168.1.146
and click on Launch Web Application in the Home
web page. Then click on the Config
tab.
This page makes it easy to configure the module. Select the chipset to narrow down the number of devices from 665 to 194, and then select the device: Globe Electric Outdoor 2-Outlet Smart Plug
. An image and information about the plug, including pin assignments, will be displayed under the drop-down box. The Forum
link will be set to van_b's post. Click on the Copy Device Settings button to load the pin assignments into the Pin Settings table and then on Save Pins
button to write the configuration to the device itself.
Now the relay toggle buttons appear in the web home page and they function.
Better Button and LEDs
Each relay can be independently controlled from the Web interface, but by default the single button on the smart plug either turns on both sockets or turns both off. This can easily be changed so that a single click of the button toggles one of the sockets and a double click of the button toggles the other socket. There is more than one way to accomplish this, but the easiest is to change the role of the button in Home » Config » Configure Module
as shown below.
The role of pin 24 was changed from Btn_Tgl_All
to Btn
with single clics controlling channel 1 (the first relay connected to P6 and the left socket when the plug is viewed from the top) and double clicks controlling channel 2 (the second relay connected to P7 and the right socket).
While this worked and the relays can indeed be controlled independently with the single button, the LED and relays/sockets are mismatched. I prefer that the left and right LED be turned on when the left and right socket is powered up respectively. Accordingly, I switched the channel assignements for the P10 and P26 pins.
I hasten to add that this might not be necessary for all the variants of the plug that appear to have been made.
Domoticz Integration
OpenBK7231T_App supports MQTT and, using that protocol, integrates well into Home Assistant as far as I can make out. This is not currently the case for Domoticz. There is a ChatGPT Bot response to the Speak more about how to configure OpenBeken MQTT to work with Domoticz prompt which, while generally correct in what it says, does not answer the question. The newest pertinent post on the forum that I could find shows that p.kaczmarek2 was willing to add the needed functionality, but it looks like this has not yet been done. So here is how it can be done for this particular device.
Start by looking at the Config » Configure MQTT
web page, to see some of the details.
The module subscribes to the cmdn/<module_name>/[Command]
topic which corresponds to the Domoticz syntax. Furthermore, like in Tasmota, the <module_name> can be the group topic. Consequently, here is how I get the IP address of the two smart plug using the status 5
command. This was done with my own lazmqttc but it could be done in many other ways including subscribing to the MQTT broker with mosquitto_sub -h 192.168.1.22 -t "stat/+/STATUS5"
in one terminal and publishing the topic mosquitto_pub -h 192.168.1.22 -t "cmnd/bekens_t/status" -m "5"
in another.
Note how the hostname of each devices was changed to gsPlug1
and gsPlug2
respectively. This simplifies adding two smart plugs in Domoticz in the next step.
The .../get
and .../set
topics that read and modify the state of the relays do not correspond to the Domoticz/in
and Domoticz/out
topics at all. They do have a very simple syntax, so that the following bash script to set the relays on or off was not difficult to write.
The script was saved to domoticz/scripts/bash/gsPlug.sh
and made executable.
Four virtual switches were set up in Domoticz corresponding to the four sockets for the two plugs. As can be seen the left socket of gsSwitch2
has been nominally turned on by clicking on the icon and the Planning
button of the right socket of gsSwitch1
is highlighted indicating that on and off times have been set.
None of those things mean anything until the On Action
and Off Action
of each of those new virtual switches is defined. Here is a capture of the Modify window where this is done for the right hand socket of gsPlug1
.
Do not forget to click on the Save
button after editing these actions.
We are almost done. The only missing bit is updating the virtual switches when the state of the relays is changed by any means other than with Domoticz. This turned out to be not too difficult because OpenBK7231_App has a powerful set of commands to customize its behaviour and two mechanisms to execute commands at boot time.
- Startup Command (
Home » Config » Change Startup Command Text
):
A startup command is executed whenever the device is booted. Multiple commands can be performed using theBacklog
command. - autoexec.bat (
Home » Lauch Web Application » Filesystem
):
A batch file of commands to be executed when the device is booted can be stored in the file system (LittleFS
).
I used the second approach because I can't seem to be able to add commands with the quote character. The autoexec.bat
file contains two event handlers for changes in the value of channels 1 and 2 that update the Domoticz server. This can be done with HTTP requests.
I prefer using MQTT messages to avoid hard-wiring the IP address of the Domoticz server. Consequently, this is the final version of the autoexec.bat
file.
The -1 at the end ensures that the "raw" topic will be used, which in this case is domocitz/in
. Otherwise, the topic would be gsPlug1/domoticz/in/get
which would definitely not find its way to the Domoticz server.
The screen capture of the Filesystem
tab in the Web application (Home » Launch Web Application
) shows how the file can be uploaded from a computer. The file can also be created in the web interface and edited; click on the filename to see and then modify its content in the edit window.
Download
The various scripts mentioned above and custom Domoticz icon sets are available for download in the other_relases GitHub repository.