logo elektroda
logo elektroda
X
logo elektroda

Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094

p.kaczmarek2 7599 11
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Hello, I will present here two Tuya 'smart' twin sockets/plugs with energy measurement and WiFi control. These sockets are characterized by a glued casing, almost impossible to remove without damaging them. Here I will show you how to access the programming signals without damaging them too much. The sockets shown here will be based on the BK7231T and BL0937 (first) and the BK7231N and BL0942 (second).

    NAS-WR01W/NAS-WR07W plugs
    I got the products for free from their distributor in order to run OpenBeken , but you can normally buy them for around PLN 70 in many online stores.
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    On the internet you can read that these specific sockets are implemented on ESP8266.
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Unfortunately, that has already changed. The manufacturer switched to BK7231. According to their distributor, you can no longer order fresh portions of these sockets for ESP.
    This is what the set I got looks like (the third socket, Mycket PE-01E IP44, I will discuss another time):
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    First Packing:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Contents:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Instruction:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    The instruction of the second one is identical, so I omit it, as well as the tests with the Tuya/SmartLife app that have already been performed many times.

    The inside of the NAS-WR07W
    As in the BW-SHP6, you need to unscrew one hidden screw:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Now it should be possible to remove the plate, but I had a serious problem with it. In this case, the pins of the plug blocked the possibility of removing the PCB. I decided to use the brute force method (later I will show a better way to physically connect the programmer, and there is also a tuya-cloudcutter to upload the batch via WiFi).
    I also tried unscrewing the pins, in vain.
    Finally, the mini-grinder went into action:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Ready:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    You can see BK7231T and BL0937:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    (Yes,I know, the PCB was slightly damaged when opening)
    The BK7231T is directly on the PCB, not as a WB2S, WB3S or similar module.
    BL0937 is an energy measurement system. It is identical to the already discussed BL0942, with the difference that BL0942 reports the results via UART, and BL0937 converts them to signals of a given frequency.
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    The SEL pin selects the mode (voltage or current). Pin Cf is the frequency which represents the power. Pin Cf1 is either voltage or current selectable. To convert the resulting signals into actual numerical values, count the number of signals on a given pin per unit of time (preferably by interrupting) and multiply them by the calibration constant.

    Everything, including the relay, is cleverly packaged:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    The FT8440A is a transformerless power supply system. There is no flyback converter here, it is a buck converter (so there is also no galvanic isolation from the mains):
    Quote:

    ft8440/8441 is a high performance, high precision, low cost non-isolated buck power converter. it contains a dedicated current-mode pwm controller and a high-voltage power mosfet. the built-in error amplifier is optimized to ensure superior dynamic response. the high-precision internal divider resistor and reference voltage, and stable closed-loop feedback enable the ft8440/8441 to obtain a stable and high-precision output voltage within the full voltage input range.

    ft8440/8441 adopts ultra-high voltage technology with internally integrated high voltage start circuit, high voltage power mosfet switch, and current sampling resistor, which reduces external components and greatly simplifies system application. the built-in frequency jitter and soft drive design can effectively improve emi performance.

    the internal integrated functions also include: vcc under-voltage protection (uvlo), vcc over-voltage protection (ovp), over-temperature protection (otp), cycle-by-cycle over-current protection (ocp), output short-circuit protection (scp). the perfect protection function ensures the reliability of the system.

    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    The relay is HF7520.
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    In the photo below you can see the pads for programming:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    You will need 3.3V, GND and TX and RX, and a UART converter with 3.3V levels. I reset/reboot by cutting off the power. Everything is similar to other topics about BK7231:
    Light switch from USA - Gosund Smart Switch SW5-A-V2.1 - BK7231T
    Garden double relay Tuya CCWFIO232PK - BK7231T - programming

    NAS-WR07W pinology
    Below I wrote down the necessary pins, especially those from BL0937:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    P6 is LED, P26 is relay.
    The button is on P9.
    BL0937 CF is on P0, CF1 is on P8 and SEL is on P24.
    In OpenBeken it is set here:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094


    NAS-WR01W plugs and a smarter way to program
    For the NAS-WR01W twin product, I tried a different approach and only cut the plastic at the programmer signals alone:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    In this way, wires can be soldered there and programmed without removing the rest of the housing by force, but of course then you need to protect the damaged housing.
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    And now attention - this plug has BK7231N and BL0942 inside. It's better to use hid_download_py, but this time I managed to upload the batch with bkWriter:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    The relay is as before on P26.
    P6 is LED again.
    BL0942 is on pins from UART, you don't need to set it.
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094


    Configuration and calibration of BL0937/BL0942
    Please follow this topic:
    Electrical socket with energy measurement LSPA9 - we program our own firmware
    For BL0937, we just start the BL0937 driver instead of BL0942.


    Summary
    These were extremely budget sockets, which are extremely difficult to open, and due to the way the pins are attached, it is not possible to remove its housing without damaging it, at least I have not found such a way. Despite this, they can be easily accessed with a programmer if you cut the housing in the right place, and you can count on it to support them tuya-cloudcutter (or maybe it already does - you'd have to check).
    In addition, these are another Tuya sockets that were previously described as being built on ESP and now use Beken.
    One was on BK7321T and BL0937 (slightly older) and the other on BK7231N and BL0942.
    LeadsI described in the content of the topic, so I think that now you have everything you need to configure these sockets.

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 11930 posts with rating 9987, helped 572 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • #2 20180011
    Kuźnia Elektronów
    Level 11  
    I picked up a similar socket from the parcel locker today, model NAS-WR07W marked as IG007FR on the package (Type F socket, the whole cost of PLN 63.96 on a well-known auction site - smart sockets with a schuko plug were even cheaper)

    Inside, based on the BK7231T QN32, the BL0942 is responsible for measuring the current anyway I wonder which UART is used for programming: UART1 or UART2? This is my first contact with uploading this firmware, I did not find direct information in google. Hence the questions: does the BL0942 use the same UART as the bootloader, it would be easier to solder to the legs of the soic-8 without cannibalizing the case :idea:
    Finally, if you need to connect to UART1, I will try to solder to the tracks in the coming days and test it experimentally, here is a photo of the inside of this plug, I have already scratched off the insulation:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094

    Here's the whole thing:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094

    In case I have ST-link if needed and a few UART-USB(COM) converters, I will also come up with something for SPI ;)

    I found a connection in your other topic "Qiahip Smart Switch - BK7231N/CB2S - interior, programming":
    p.kaczmarek2 wrote:
    Connecting the programmer
    (...)(BK7231T). USB to UART converter and only connect TX1 and RX1:
    If I find time, I will set up the environment and prepare the batch, unless you share the finished batch just to use BKwriter and limit my frustration at the first attempts :)
  • #3 20180173
    p.kaczmarek2
    Moderator Smart Home
    Kuźnia Elektronów wrote:

    Hence the questions: does the BL0942 use the same UART as the bootloader, it would be easier to solder to the legs of the soic-8 without cannibalizing the case :idea:

    Yes. Topic:
    https://www.elektroda.pl/rtvforum/topic3887748.html
    Paragraph "Uploading Your Own Load - OpenBK7231N - Part 2"
    initially I thought that the presence of BL0942 on the same UART as the bootloader would interfere with programming, but it went without problems for me. Maybe it was a fluke, or maybe the baud difference somehow affected it? I don't know

    Kuźnia Elektronów wrote:

    If I find time, I will set up the environment and prepare the batch, unless you share the finished batch just to use BKwriter and limit my frustration at the first attempts :)

    Automatic builds for the BK7231T, BK7231N (T34), XR809, BL602 and W800/W801 platforms are here:
    https://github.com/openshwprojects/OpenBK7231T_App/releases/tag/1.12.48
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    On BK7231T you upload UA batch with default offset by bkWriter 1.60.
    On BK7231N you load the QIO batch at offset 0x0.
    RBL is OTA via OpenBeken form.
    UG is for BK7231 as you use Tuya-Cloudcutter.
    before uploading the batch, make a copy of the entire 2MB (enter 2MB in length) of the batch and you can also send it to the gentlemen from tuya-cloudcutter


    Kuźnia Elektronów wrote:

    In case I have ST-link if needed and a few UART-USB(COM) converters, I will also come up with something for SPI ;)

    SPI can be useful when you overwrite the UART Beken bootloader, i.e. in extreme situations. I wouldn't worry about it. But here's the instruction:
    Quote:

    BK7231S Flash via SPI
    This is useful if you accidentally overwrite the bootloader.

    This procedure was tested on an RPI3b having enabled SPI in raspi-config.

    Connections:

    CEN - Chip enable (reset) -> GPIO22
    P20 - SCLK -> SCLK
    P21 - FLASH CSN -> SPI CE0
    P22 - FLASH SI -> SPI MOSI
    P23 - FLASH SO -> SPI MISO
    SPI Mode 3
    SPI Rate 50000
    Enabling SPI Flash
    set GPIO22 (CEN) is low.

    Wait 1s.

    set GPIO22 (CEN) is high.

    Send 250 'D2'

    expected response:

    First byte D2, 249x00

    The MCU is now in SPI flashing mode, and will remain in this state (until power off, or maybe toggle of CEN?).

    Test by sending

    9F 00 00 00 -> 00 15 70 1C

    This is the ID of an EN25QH16B - data sheet here: https://datasheetspdf.com/datasheet/EN25QH16B.html

    Reading the flash

    data may be read in chunks of 256 bytes using cmd 03:

    03 (addr>>16 & 0xFF) (addr>>8 & 0xFF) (addr & 0xFF)

    The data read in this way is from the raw flash. Executable partitions on the BK7231 may/will be both packaged and encrypted.

    writing the flash
    Writing consists of erasing sectors and then writing data.

    As it is writing the faw flash, executable partitions must be encrypted and packaged (32->34 bytes with CRC).

    From the Tuya SDK, the firmware file tagged 'QIO' is suitable. e.g. to replace the bootloader, flash the first 0xf000 bytes from that firmware file.

    Each command must raise CSN at the end to take effect, so all commands must be sent separately over SPI.

    A sector is 0x1000 bytes, writing is max 256 bytes per page.

    Procedure:

    Enable write (must be done before each erase or write):

    06

    Erase sector:

    20 (addr>>16 & 0xFF) (addr>>8 & 0xFF) (addr & 0xFF)

    Wait for Erase to complete:

    05 00

    Repeat until bit 0 of the second byte returns clear.

    Enable write (must be done before each erase or write):

    06

    Write data:

    03 (addr>>16 & 0xFF) (addr>>8 & 0xFF) (addr & 0xFF)

    Note that there are 4 writes to each erase. If you call erase with a write addr not on a 0x1000 boundary, it will erase the sector starting on the relevant 0x1000 boundary.

    Additional notes:
    At first, I attempted this from Espruino on ESP32. That was not successful, and I'm still not sure why.


    PS: Nie wpadnij w pułapkę z konwerterem USB na UART mającym za słabą wydajność prądową na linii 3.3V. Musisz zasilić układ z dobrego źródła 3.3V. Sam mam do tego LDO 3.3 TC1264, ale może być dowolny podobny
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #4 20322891
    SławekSS
    Level 24  
    p.kaczmarek2 wrote:
    Now it should be possible to remove the plate, but I had a serious problem with it. In this case, the pins of the plug blocked the possibility of removing the PCB. I decided to use the brute force method (later I will show a better way to physically connect the programmer, and there is also a tuya-cloudcutter to upload the batch via WiFi).
    I also tried unscrewing the pins, in vain.
    great job :)

    And as for disassembly, there is no problem, maybe a little more difficult than the famous SP111, but it does the trick :)

    After unscrewing the screw under the sticker and removing the plastic cover, you need to gently knock out these pins together with the plates with a hammer, but first you need to peel off the antenna.
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094 Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Above desoldered and removed from the housing without damage.

    My socket is Setti+ SP301.


    I had a problem with uploading OpenBeken, it kept crashing Unlocked Failed.
    Only the 6th time it surprised me.

    Regards
    S
  • #5 20323073
    p.kaczmarek2
    Moderator Smart Home
    @SławekSS can you tell me what layout you have inside (BK7231N or T and BL0937 or BL0942) and show the pin configuration? I would add this socket to the list of supported devices/templates.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #6 20323155
    SławekSS
    Level 24  
    BK7231N, BL0942. Board marked as NAS-WR01W6-T V7
    Pins:
    P9-button
    P26-relay
    P6-WiFiLed
    I assigned the configuration the same as in the topic regarding NAS-WR01W and it worked.
    startDriver BL0942 took care of the measurement indications.

    Now it's time to calibrate and try to assign to domoticz :) As I am a preschooler (well, maybe 1st grade SP) in this topic it will take a while :)

    edit:
    Is it possible to somehow set the LED to flash when there is no WiFi and / or when trying to connect, and how to connect it so that it lights up when the relay is on and goes out as if it is off?
  • ADVERTISEMENT
  • #7 20323188
    p.kaczmarek2
    Moderator Smart Home
    It looks like you want to combine WifiLED_n with regular LED. At the moment it could only be done with a script, but if you need such a function, I can just add such a pin role. Name it e.g. WiFiAndPowerLED or something.
    Helpful post? Buy me a coffee.
  • #8 20323276
    SławekSS
    Level 24  
    p.kaczmarek2 wrote:
    but if you need such a function, I can just add such a pin role
    that would be great if it's not a problem.
    That's one more question, how do I enter some startup commands? For example, start driver xxxx and this command to indicate energy measurement. I tried with comma and semicolon but it didn't work. Unless you can't.
  • #9 20323297
    p.kaczmarek2
    Moderator Smart Home
    As in the tape: backlog a; b; c;
    Or in the Web Panel in autoexec.bat freely in LittleFS

    Edit: I added a hint on how to use the backlog to the page:
    Socket plug with energy measurement NAS-WR01W and NAS-WR07W [BK7231/BL0937/BL094
    Helpful post? Buy me a coffee.
  • #10 20324723
    SławekSS
    Level 24  
    Thanks, everything works. Now Domoticz.

    Is there a software-only topic to submit your comments to it?
  • #11 20324809
    p.kaczmarek2
    Moderator Smart Home
    Domoticz, what about that weird protocol with "in" and "out"? "domoticz/in"?
    I was just about to add this, so you could help with testing, but a bit of information on what exactly is needed with domoticz "chat" would be nice.
    Only the "in" and "out" ones? I have mixed information from users.
    Would you be able to give an example of in and out syntax?

    Collective topic: https://www.elektroda.pl/rtvforum/topic3866123-1050.html#20305000
    Helpful post? Buy me a coffee.
  • #12 20324894
    SławekSS
    Level 24  
    Yes, about this protocol.

    For example, Tasmota sends like this:
    13:23:23.054 MQT: domoticz/in = {"idx":100,"nvalue":0,"svalue":"0.0;2062.5;0.0;0.0;0;0","Battery":100,"RSSI":4}
    13:23:23.054 MQT: domoticz/in = {"idx":96,"nvalue":0,"svalue":"0.0;147046.9;0.0;0.0;112;0","Battery":100,"RSSI":4}
    


    The most important is this syntax domoticz/in = {"idx":100,"nvalue":0,"svalue":"0.0;2062.5;0.0;0.0;0;0","Battery":100,"RSSI":4 }

    This is the syntax sent by the SP111 socket with tasmota to domoticz.
    The "svalue" parameter in this case is the parameters of the P1 Smart Meter(https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Electricity_P1_smart_meter)

    Here is a piece of python code that sends topic to domoticz:
        publish.single('domoticz/in', "{\"idx\": 8, \"svalue\": \""+lambd+"\"}", hostname=ip)
        publish.single("domoticz/in", "{\"idx\": 9, \"svalue\": \""+plomien+"\"}", hostname=ip)
        publish.single("domoticz/in", "{\"idx\": 11, \"svalue\": \""+wentylator+"\"}", hostname=ip)
        publish.single("domoticz/in", "{\"idx\": 13, \"svalue\": \""+ts+"\"}", hostname=ip)


    And this is the topic of switching on and off the socket from domoticz to tasmota read in the tasmota console
    13:43:57.754 MQT: stat/Pralka/RESULT = {"POWER":"ON"}
    13:43:57.757 MQT: stat/Pralka/POWER = ON

    13:47:20.026 MQT: stat/Pralka/RESULT = {"POWER":"OFF"}
    13:47:20.031 MQT: stat/Pralka/POWER = OFF


    Domoticz is definitely sending to the domoticz/out topic but what happens next I don't know, I see the above on the tasmoty console in the socket


    edit:

    socket with tasmota, a virtual switch in domoticz sends such a topic

    domoticz/out{
    "Batteries": 255,
    "LastUpdate" : "2022-12-09 11:16:50",
    "RSSI": 12,
    "description" : "",
    "dtype" : "Light/Switch",
    "hwid" : "13",
    "id": "000140B7",
    "idx": 103,
    "name" : "in\u0142 washing machine",
    "nvalue" : 0,
    "stype" : "Switch",
    "svalue1" : "0", //changes here depending on whether it enables[1] or disables[0] the socket
    "switchType" : "On/Off",
    "unit": 1
    }

Topic summary

The discussion revolves around two Tuya smart twin sockets, NAS-WR01W and NAS-WR07W, which feature energy measurement and WiFi control capabilities. Users share experiences with disassembling the devices, programming them using OpenBeken firmware, and accessing UART for programming. The NAS-WR07W model is identified as IG007FR and utilizes the BK7231T and BL0942 chips for functionality. Participants discuss challenges faced during firmware uploads, including issues with the bootloader and UART connections. Additionally, there are inquiries about integrating the sockets with Domoticz for home automation, including syntax for sending data and configuring LED indicators based on WiFi connectivity and relay status.
Summary generated by the language model.
ADVERTISEMENT