logo elektroda
logo elektroda
X
logo elektroda

[Solved] Automatic Fish Feeder, BL602

Virnik0 2286 23
ADVERTISEMENT
  • Helpful post
    #1 20859669
    Virnik0
    Level 5  
    Hello,

    I have recently purchased Automatic Fish Feeder from eBay.

    It has XT-BL12 chiplet inside. Inside this chiplet, it has BL602. I have successfully soldered my UART jig to it, and flashed OpenBelken firmware.

    Wi-Fi, MQTT works. I can also turn LED on/off, and rotate the drum.

    I have few questions:
    I have soldered DS18B20 temperature sensor to GPIO17. I have put 150k rezistor between data (GPIO17) and VCC, GND to GND.

    But I haven't found out how to configure it properly. GPIO mapper wizzard from the web doesn't help. Toggling the drum doesn't turn it off after one rotation, it keeps rotating. I have to turn it off manually. I know that with Tasmota, identical problem is solved by setting pulsetime1. How can I do the same thing here, ie: Turning the drum will toggle-off automatically after it finishes its single rotation.

    Second issue is that the default template doesn't know anything about temp sensor. I can't pick pin type from pre-defined list.
    It doesn't read correct values.
    Close-up of a circuit board with an XT-BL12 Wi-Fi module in an automatic fish feeder..

    And last, if I'll exclude HomeAssistant for now, how can I automate or mimic behavior of stock firmware, eg: When the drum rotates, LED blinks. When the button is pressed, it turns the drum once. If long-press is used, it forces an action (Pairing on stock, but I would prefer either reboot or safe mode).

    PCB with Wi-Fi module and soldered wires.

    To summ things up, I have so far identified GPIO03 as a button, GPIO04 as a LED, and GPIO05 as a drum rotation. Setting it to PWM allows me to rotate it through button on board's GUI. GPIO17 has a temp sensor connected.

    I was able to put button and drum rotation to one group, so by pressing the button, the drum rotates (and never stop until pressed again). Toggle in the UI thinks it is a light.
    Screenshot showing GPIO configuration for an automatic fish feeder.

    I am sorry if it was already discussed elsewhere....I tried to search for either BL602 controlling a motor, or BL602 used in fish feeder units, but haven't found anything. Most feeders uses different chiplets which usually work well with Tasmota.

    I have also tried to use gui flasher app to parse tuya mcu gpio config, but the app tells me that there was an error (tried both on Linux and Windows) while choosing tuyamcu dump binary file. The app refuses to download or read from BL602, because it was made for different chip. But it is able to verify connectivity from the unit over network, reads its chip, firmware version, etc. Is there a better or other way for BL602 to convert/parse tuyaMCU GPIO config?

    Also, the unit prints "boot incompletes 1" in its gui. Should I be worried?

    Update: I've read a bit more about drivers to start. I have tried to work with autoexec.bat, letting it start TuyaMCU, but there is no mention of this driver in logs, even though I set them to debug level verbosity. And if I'll try to start it manually, I'll get this:
    Info:MAIN:Driver TuyaMCU is not known in this build.
    Info:MAIN:Available drivers: 
    Info:MAIN:NTP
    Info:MAIN:, RN8209
    Info:MAIN:, BL0942
    Info:MAIN:, BL0937
    Info:MAIN:, CSE7766
    Info:MAIN:, DDP
    Info:MAIN:, SSDP
    Info:MAIN:, DGR
    Info:MAIN:, Wemo
    Info:MAIN:, SM2135
    Info:MAIN:, BP5758D
    Info:MAIN:, BP1658CJ
    Info:MAIN:, SM2235
    Info:CMD:[WebApp Cmd 'startDriver TuyaMCU' Result] OK


    Technically, this feeder was sorta no-name, came with specific app (Vanters), and while it does work similarly to other tuya devices (pairing mode, etc), it used some other noname vendor's cloud. I was looking to achieve two goals:
    a) cut it off from chinese cloud services and allow direct LAN control (apart from endless drum rotation, this was achieved. I can control and automate the feeding using HA
    b) Read temperature values from connected sensor. So far, I haven't found a way how, although the same procedure with Tasmota wasn't a problem.

    I am attaching TuyaConfig dump made using web client.

    Update2:
    Bellow button config works, eg: rotates the drum only once, both toggle and the button:
    {
      "vendor": "Vanters",
      "bDetailed": "0",
      "name": "Automatic Fish Feeder",
      "model": "ANT325 V0",
      "chip": "BL602",
      "board": "XT-BL12",
      "flags": "-2080373664",
      "keywords": [
        "Feed",
        "Fish"
      ],
      "pins": {
        "2": "Btn_n;1",
        "3": "Btn;2",
        "4": "WifiLED_n;0",
        "5": "PWM;3"
      },
      "command": "waitFor WiFiState 4;waitFor MQTTState 1",
      "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }


    Screenshot of GPIO configuration for a BL602-based board

    In General/Flags, I had to enable "Flag 6 - [BTN] Instant touch reaction instead of waiting for release (aka SetOption 13)"

    Apart from it thinking about the toggle being a LED light, it works. Only thing remaining is the temp sensor. To me, it seems like device class isn't defined in OpenBeken.



    ========================================================================================================
    Update3:
    As for HA integration, I did this:
    configuration.yaml
      - platform: template
        sensors:
           fish_feed_time_tabs:
            friendly_name: "Last Fish Feeding - Tabs"
            value_template: >
              {%- set time = (as_timestamp(now()) - as_timestamp(states.counter.number_of_feedings_tabs.last_changed)) | int  %}
              {%- set minutes = ((time % 3600) // 60) %}
              {%- set minutes = '{}minutes'.format(minutes) if minutes > 0 else '' %}
              {%- set hours = ((time % 86400) // 3600) %}
              {%- set hours = '{}hours '.format(hours) if hours > 0 else '' %}
              {%- set days = (time // 86400) %}
              {%- set days = '{}days '.format(days) if days > 0 else '' %}
              {{ 'Less than 1 minute' if time < 60 else days + hours + minutes }} ago


    mqtt:
      switch:
      - unique_id: "feeder1.iot.lan_switch"
        name: Feed
        command_topic: "cmnd/Feeding/led_enableAll"
        state_topic: "Feeding/led_enableAll/get"
        availability_topic: "Feeding/connected"
        payload_on: 1
        payload_off: 0
    
      - unique_id: "feeder1.iot.lan_reboot"
        name: Reboot
        command_topic: "cmnd/Feeding/restart"
        availability_topic: "Feeding/connected"
        payload_on: 1
        payload_off: 0
        state_off: "Feeding/online"
        state_on: "Feeding/offline"


    I have added helpers to serve as a counter(s), and input boolean toggles to serve as a virtual on-off switch. I have two feeders, one based off of WBR3 - so used with TuyaLocal, and second one with BL602 I am playing with now, named Feeder1 (Tabs).
    Aquarium control panel with various options and counters.

    Aquarium LED Strip as seen in the dash panel screenshot is different controller entity not related to BL602
  • ADVERTISEMENT
  • Helpful post
    #2 20864952
    p.kaczmarek2
    Moderator Smart Home
    I haven't seen that kind of device yet, thanks for submitting it.
    The boot incompletes 1 is okay, because boot is marked as complete after some time and you may catch the counter before its completion.
    The DS18B20 support is planned, I can look into it sooner if you need that
    For PulseTime, you need to see:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    In case of BL602, you can put those scripts in short startup command. Maybe something like this:
    
    // This aliased command will turn off relay on CH1 after 10 seconds
    // addRepeatingEvent	[IntervalSeconds][RepeatsOr-1][CommandToRun]
    alias turn_off_after_time addRepeatingEvent 10 1 setChannel 1 0
    // this will run the turn off command every time that CH1 becomes 1
    addChangeHandler Channel1 == 1 turn_off_after_time 
    

    We don't get BL602 devices often so we haven't ported LFS to this platform yet.
    Helpful post? Buy me a coffee.
  • #3 20867273
    Virnik0
    Level 5  

    Hi,

    Thanks for the tip! This MCU (not Tuya apparently) has a break relay, which breaks/disconnects right after turning it on. So, I mapped it like this:
    Screenshot of Pin Configuration settings with four different configurations.


    And it does work correctly. So one turn only. If I'll toggle PWM, then it will do two rotations. From this perspective, I achieve what I wanted - the feeder is remotely controllable without a Chinese cloud provider. But the temperature I wanted to get....I can live without it, but it is sad.

    As for the temp sensor, I would really appreciate that support. After managing to finally flash this chip, I was hoping to use it, as WBR3 I have in the other feeder couldn't be flashed (iLonda - should be L88, but it is not - they have changed the chip from ESP to a clone from Tuya) and the sensor intended for it couldn't be used. That is why I thought that because OpenBeken is so similar, the same approach would work. And it does, up till software support, which is not yet present. But it is maybe the cheapest sensor you can get, and it is produced on a long cable suitable for tank temp measurement.

    As for LFS, I thought it to be a bug when I noticed that the FS browsing from the web browser doesn't work.

    If you'd need any logs or dumps, I will happily provide what I have. As a one wish if I could have it - could the next release be a bit modified so it wouldn't think I am controlling an LED strip with it? PWM controls an electric DC motor, instead of LEDs. So added controls for color temperature couldn't be used as such (but I have noticed it can control the speed of rotation apparently).
  • Helpful post
    #4 20867348
    p.kaczmarek2
    Moderator Smart Home
    I will try to look into it for you, the little problem is just that BL602 is not very popular and there are few devices using this chip, so Beken takes the priority. Do you have some basic C skills to help with enabling LFS on BL602, maybe?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 20867360
    Virnik0
    Level 5  

    Sadly, my coding skills aren't usable (compared to someone who really does develop the code). Last time I coded something in C, it was for the M@ngos project over 20 years ago.

    So I try to avoid it if possible because I know I am a much better platform engineer than a developer. I can apply patches and sometimes debug what went wrong. I do not have any issues rebuilding software from sources, and in specific cases, alter the code to suit either my needs or to simply work, but all those are relatively easy tasks for someone who really knows how to code. It is no wonder that BL602 is not so popular. It is possibly the cheapest module you can get. And honestly, I thought that the feeder has either an ESP proper or RTL clone, not a completely alien, minority-used chip. But I'm trying to get the most from little, if you know what I mean ;-)

    So if LFS enablement means to review certain diffs, apply them, and try to rebuild, yes, I can do that. But please do not expect truly developer kind of work, as I am not a developer myself.

    Anyway, I am not rushing, certainly not a maintainer of a bigger project for which my use-case is truly a minority. But I also won't stop you, if you know what I mean ;-) To that end, I consider myself lucky to be able to achieve the primary goal for that feeder. The first try failed due to WBR3 in the first feeder, so having success (although partial) on the second try wasn't that bad an experience.

    That said, if there would be something I can test, provide, run, build/compile....I am open to help (myself).
  • Helpful post
    #6 20940687
    Jinaria
    Level 8  

    Virnik0 wrote:
    As WBR3, I have the other feeder that couldn't be flashed (iLonda - should be L88, but it is not - they have changed the chip from ESP to a clone from Tuya)


    ESPHome now has partial support for WBR3 (no OTA at the moment). I have the same iLonda feeder with WBR3 modules and managed to flash mine successfully.
    
    rtl87xx:
      board: wbr3
      family: rtl8720c
      framework:
        version: 0.0.0
        source: https://github.com/libretiny-eu/libretiny.git#feature/realtek-update

  • #7 20945217
    Virnik0
    Level 5  

    Thanks. As for iLonda, I left it where it was - integrated through TuyaLocal.

    As it works as it should now, I am more concerned about that no-name one,
    which uses BL602. It works correctly, but my concern was temperature sensor.

    So far, I have downloaded the sources, did basic configuration, but haven't found
    the time to actually build it and test, namely VFS. To be honest, I was fighting
    off one more resilient WINE build and then forgot about beken feeder.
  • #8 21059631
    Tilator
    Level 10  

    Virnik0 wrote:
    Hello,

    I have few questions:
    I have soldered DS18B20 temperature sensor to GPIO17. I have put 150k resistor between data (GPIO17) and VCC, GND to GND.

    But I haven't found out how to configure it properly. GPIO mapper wizard from the web doesn't help. Toggling the drum doesn't turn it off after one rotation, it keeps rotating. I have to turn it off manually. I know that with Tasmota, identical problem is solved by setting pulsetime1. How can I do the same thing here, i.e.: Turning the drum will toggle-off automatically after it finishes its single rotation.

    Second issue is that the default template doesn't know anything about temp sensor. I can't pick pin type from pre-defined list.
    It doesn't read correct values.


    Did you get any values from this DS18B20?

    I would like to add these sensors too, but can it be used? There seems to be some LibreTiny to allow it in Beken devices, but it sounds a bit complicated.
  • ADVERTISEMENT
  • #9 21075275
    Virnik0
    Level 5  

    Hi, no. No data from it. There is no support for it in OpenBeken. I haven't had a time to play with the source code, to be honest, as I am working and quite a lot of things simultaneously now, so tinkering is out of my capacity for the time being (probably till Fall).
  • Helpful post
    #10 21075277
    p.kaczmarek2
    Moderator Smart Home
    I can look into supporting DS18B20 in OBK
    Helpful post? Buy me a coffee.
  • Helpful post
    #11 21075516
    Tilator
    Level 10  
    p.kaczmarek2 wrote:
    I can look into supporting DS18B20 in OBK


    Excellent!
  • #12 21075758
    Virnik0
    Level 5  

    >>21075277

    That would be awesome! I can easily flash for testing, not worried about bricking the unit - it is just an aquarium feeder after all.

    Added after 2 [minutes]:

    >>20940687

    Wired flash? I have it hooked up over TuyaLocal now. So once I'll have the time to open it and solder pins, I'll flash it too. If it is possible wirelessly (I think it is not with WBR3, that flaw was fixed last summer), even better. But I guess it's not.
  • #13 21089522
    BorgMcz
    Level 1  

    I think DS18B20 support would be a cool thing to have.
  • ADVERTISEMENT
  • #14 21095600
    Tilator
    Level 10  

    Does DHT11 need some kind of pullup resistor, or should it simply be power to VDD, ground to ground and GPIO to SDA?
  • #15 21095625
    p.kaczmarek2
    Moderator Smart Home
    Here is our DHT11 + OBK tutorial, including connection:


    Helpful post? Buy me a coffee.
  • #16 21267631
    divadiow
    Level 34  
    BorgMcz wrote:
    I think DS18B20 support would be a cool thing to have.


    a DS18B20 driver has since been developed and is available for use on BL602 and Beken platforms

    Added after 3 [minutes]:

    Virnik0 wrote:
    As for LFS, I thought it to be a bug when I noticed that the FS browsing from the web browser doesn't work.

    LFS is also available on BL602 now, but only on the older partition layout (this would be the case if flashed with BL DevCube 1.4.8 with the stock partition_cfg_2M.toml file)
  • #17 21290478
    Virnik0
    Level 5  
    divadiow wrote:
    BorgMcz wrote:
    I think DS18B20 support would be a cool thing to have.


    a DS18B20 driver has since been developed and is available for use on BL602 and Beken platforms

    Added after 3 [minutes]:

    Virnik0 wrote:
    As for LFS, I thought it to be a bug when I noticed that the FS browsing from the web browser doesn't work.

    LFS is also available on BL602 now, but only on the older partition layout (this would be the case if flashed with BL DevCube 1.4.8 with the stock partition_cfg_2M.toml file)


    Sorry for too many edits. I was able to make it work after reading the manual again....I had to specify the driver to start:
    startDriver DS1820

    Now I can read the sensor, although the value was initially off. But now it looks like it is reading correct value. So it works. thanks a lot and again, sorry for confusion!
  • Helpful post
    #18 21290549
    divadiow
    Level 34  
    -1.27°C? that usually means it's not talking to the sensor. definitely got the right pin assigned?
  • #19 21290559
    Virnik0
    Level 5  
    divadiow wrote:
    -1.27°C? that usually means it's not talking to the sensor. definitely got the right pin assigned?


    It shows this value some 30s after reboot. But then it switches to proper value, currently 24.37˚C

    Verified across few reboots.
  • #20 21290566
    divadiow
    Level 34  
    ah OK. there's also an interval value you get add to the end of the startdriver command - eg "startDriver DS1820 5" otherwise it's 15s by default
  • #21 21290593
    Virnik0
    Level 5  
    >>21290566 I think I got it:

    startDriver DS1820 5; waitFor WiFiState 4;waitFor MQTTState 1; addRepeatingEvent 10 -1 publishFloat DS1820Temp $CH5


    Sensor works, I can see its values in the log. But I am unable to make sure it is published via MQTT. Well, I can, if I'll run the command by hand, but it doesn't work after reboot. What am I doing wrong?


    What is strange is that I do get a lot of bellow errors in logs:
    Info:SENSOR:DS1820[17] - Starting conversion
    Error:SENSOR:DS1820[17] - Read CRC=ff != calculated:c9 (errcount=1)
    Error:SENSOR:DS1820[17] - Scratchpad Data Read: ff ff ff ff ff ff ff ff ff
    Error:SENSOR:DS1820[17] - Read CRC=ff != calculated:c9 (errcount=2)
    Error:SENSOR:DS1820[17] - Scratchpad Data Read: ff ff ff ff ff ff ff ff ff
    Error:SENSOR:DS1820[17] - Read CRC=89 != calculated:30 (errcount=3)
    Error:SENSOR:DS1820[17] - Scratchpad Data Read: 87 1 55 5 7f a5 a5 66 89
    Error:SENSOR:DS1820[17] - Read CRC=2d != calculated:cb (errcount=4)
    Error:SENSOR:DS1820[17] - Scratchpad Data Read: 87 11 55 5 7f a5 a5 66 2d
    Error:SENSOR:DS1820[17] - Read CRC=7a != calculated:41 (errcount=5)
    Error:SENSOR:DS1820[17] - Scratchpad Data Read: 87 1 55 5 7f a5 b5 76 7a
    Info:SENSOR:DS1820[17] - Temp=24.43



    OK, so if I'll run the command to add repeating event, I do get the values from the sensor over MQTT. But it is not in json format, just raw value.

    I am trying to add it to my Home Assistant cluster, but sadly I am unable to get the value from it:
    mqtt:
     sensor:
        - state_topic: “Feeding/DS18B20Temp/get”
          availability_topic: "Feeding/connected"
          name: "FishTank Water Temperature"
          unique_id: “feeder1.iot.lan_water-temp”
          unit_of_measurement: "°C"
          device_class: temperature
          state_class: measurement
          icon: mdi:coolant-temperature
          force_update: true
          encoding: ""
          value_template: "{{ value | int * 0.01 }}"


    I also tried with integer switch, but while HA does see mqtt messages, I seem to be unable to define the sensor properly.
    Never had similar issues with mqtt, and I do use object detection from my cameras and binary sensors over it. But I do have to be missing something, that I am unable to get any meaningful value from the sensor in HA.

    Any ideas?
  • #22 21291298
    p.kaczmarek2
    Moderator Smart Home
    If you want to run multiple commands in the short startup line, you need to use "backlog":
    Screenshot of a user interface for setting startup command line for BK7231T device.
    Helpful post? Buy me a coffee.
  • #23 21291312
    Virnik0
    Level 5  
    Thanks!

    Didn't noticed this to be honest.

    Using bellow fixed the issue, now it correctly starts the repeating event:
    backlog startDriver DS1820 5; waitFor WiFiState 4;waitFor MQTTState 1; addRepeatingEvent 60 -1 publishFloat DS1820Temp $CH5;


    OpenBelken FW does what it promissed to do. Data is output to proper MQTT queue/topic. Processing it correctly is another story, because it prints this:
    Feeding/DS18B20Temp/get:
    2487

    Is there a way to add decimal point to the value before it is going to be exported? To show like 24.87 in mqtt instead of 2487 it does now?
    Screenshot of an MQTT console showing various topics and values, including DS18B20Temp.

    If anyone is interested, bellow yaml snippet works in HA to collect the temperature and move decimal split to proper place:
    
    sensor:
    - platform: template
      sensors:
        fishtank_water_temperature-filtered:
          name: "FishTank Water Temperature"
          unique_id: "feeder1.iot.lan_water-temp-filtered"
          device_class: temperature
          unit_of_measurement: '°C'
          state_class: measurement
          icon: mdi:coolant-temperature
          entity_id:
            - sensor.fishtank_water_temperature-filtered
          value_template: >
            {% set unknown = 'unknown' %}
            {% set value = states('sensor.fishtank_water_temperature') %}
            {% set prev_value = states('sensor.fishtank_water_temperature-filtered') %}
            {% if prev_value == unknown %}
              {{ value }}
            {% else %}
              {% set def_deviation = 3.0 %}
              {% set cur_deviation = states('input_number.fishtank_water_temperature-deviation') %}
              {% set deviation = def_deviation if cur_deviation == unknown else float(cur_deviation) %}
              {{ prev_value if value == unknown or (value | float - prev_value | float)|abs > deviation else value }}
            {% endif %}
    
    mqtt:
      sensor:
        - state_topic: "Feeding/DS18B20Temp/get"
          name: "FishTank Water Temperature"
          unique_id: "feeder1.iot.lan_water-temp"
          unit_of_measurement: "°C"
          device_class: temperature
          state_class: measurement
          icon: mdi:coolant-temperature
          force_update: true
          availability_template: "{{ 'online' if (10.0 <= value|float(0)/100 <= 40.0) else 'offline' }}"
          value_template: >-
            {%- if value|float(0)/100 >= 10.0 and value|float(0)/100 <= 40.0 -%}
            {{ (value | float(0)) / 100 }}
            {%- else -%}
            {{ states('sensor.fishtank_water_temperature_filtered') }}
            {%- endif -%}
    


    The sensor reports back values in bellow format (so the same as OpenBelken itself report) in HA:
    24,35°C

    Above MQTT sensor definition for HA takes care of sometimes imaginary values the sensor throws out (like temperature being -1500˚C or +90˚C). It is random, but annoying. Since this is aquarium, I set the temperature range between 10˚C and 40°C being reasonable. The sensor will switch offline for one measurement which returns invalid value, and also will skip recording such a value to statistics, retaining prior value for the time being. Since the measuring happens every 60s (at least the feeder unit pushes value from DS18B20 to MQTT every 60 seconds in my case), it has no ill impact.

    This thread could be possibly closed, as basically everything I started it with was either answered, corrected, or otherwise done.

    Thanks a lot guys! Your nudging towards right direction and information I needed was really helpful.
  • #24 21291606
    Virnik0
    Level 5  
    The problem is solved:
    - OpenBelken for BL602 does support DS18B20 temp sensor now
    - Correction made thanks to advices of others to configure Fish Feeder unit with proper startup sequence
    - The feeder itself was added as a template to BL602 FW (will need an update in regard to Temp sensor maybe).
    - Data from sensor is being published over MQTT and also consumed by local install of HA

    Again, thanks a lot!

Topic summary

The discussion revolves around the Automatic Fish Feeder utilizing the BL602 chip, where the user successfully flashed OpenBelken firmware and integrated a DS18B20 temperature sensor. The user encountered issues with configuring the temperature sensor and automating the drum rotation to stop after one cycle. Responses included suggestions for scripting commands to manage the drum's operation and inquiries about the DS18B20 sensor's support in OpenBeken. The community expressed interest in adding support for the temperature sensor and discussed the challenges of working with the less common BL602 chip. Recent developments indicated that a DS18B20 driver is now available for BL602, and LFS support has been implemented.
Summary generated by the language model.
ADVERTISEMENT