Accéder au contenu principal

Playing with the B-Parasite

One of the most successful Bluetooth Low Energy devices that started appearing in our Smart Home is the Xiaomi Mi Flora. Decoded and integrated into OpenMQTTGateway in 2017 this device enabled us to have a nice follow-up on our plants and vegetables' health.

One of the main drawbacks is its power consumption, I'm around 6-9 months in terms of battery life. Not very satisfying when we see BLE sensors that can last several years.

By chance, I found recently the work of Raphael about the b-Parasite, a BLE open-source plant sensor: https://github.com/rbaron/b-parasite

It is interesting from several aspects:

  • Nice form factor and size
  • The moisture probe is integrated into the PCB
  • You can order directly from the files proposed to a PCB manufacturer with most of the components already soldered
  • nRF52 powered, a reference module in Bluetooth Low Energy
  • It's open-source design and code!
So why not try it and see if it can replace my Mi Floras.

The ordering experience from JLPCB was quite easy, just had to sort out and verify some component's locations.
Apart from the PCB I had to order separately the nRF52 module and the battery holder.

The time to gather all the components, I realized also that I will need a special tool to flash the nRF52, from the advice of Koen Vervloesem I ordered a Black Magic Probe from 1BitSquared with the JTAG Cable, 0.1" UART Cable and 7pin 0.1" pitch breakout adapter.


Once delivered, I started the assembly, the battery holder is the easiest part to solder, for the nRF52 this is a different story, but finally got it soldered.

Side by side with the Mi Flora

Once soldered the next step is to flash the device, by grabbing different information I came up with these different steps that work well with a Black Magic Probe.

Note that this has been done on macOS

Hardware prerequisites:
  • Black Magic Probe
  • Jtag Cable
  • JTAG/SWD 0.1in Breakout Adapter
  • B parasite soldered

Follow this tutorial so as to set up your environment:

https://azlekov.medium.com/adafruit-nrf52840-ble-probes-using-black-magic-probe-debugger-7fc2b40f4c4a


Once done clone the Github repository for the b-parasite:

https://github.com/rbaron/b-parasite


Building and flashing

  • Go to the code/b-parasite folder
  • Build with the following command:

$SDK_ROOT=/Applications/nRF5_SDK_17.1.0_ddde560 make

Compiling file: main.c

Compiling file: adc.c

Compiling file: ble.c

Compiling file: pwm.c

Compiling file: rtc.c

Compiling file: shtc3.c

Linking target: _build/nrf52840_xxaa.out

   text   data     bss     dec     hex filename

  34540     252   3148   37940   9434 _build/nrf52840_xxaa.out

Preparing: _build/nrf52840_xxaa.hex

Preparing: _build/nrf52840_xxaa.bin

DONE nrf52840_xxaa

  • Go to the _build folder and ls

$ cd _build


$ ls

nrf52840_xxaa nrf52840_xxaa.map out_300.hex

nrf52840_xxaa.bin nrf52840_xxaa.out out_sleep-adv.hex

nrf52840_xxaa.hex nrf52840_xxaa_300.hex s140_nrf52_7.2.0_softdevice.hex

nrf52840_xxaa.in out_1.hex

  • Copy the softdevice for nrf52840 downloaded in the prerequisites into the _build folder
  • Merge the program with the softdevice

$mergehex -m s140_nrf52_7.2.0_softdevice.hex nrf52840_xxaa.hex -o out_sleep-adv_300.hex

Parsing input files.

Merging file "s140_nrf52_7.2.0_softdevice.hex" into output.

Merging file "nrf52840_xxaa.hex" into output.

Storing merged file.

  • Connect the Black Magic Probe to the B-Parasite (without battery) and with the JTag 7 pins adapter
    • Adapter VCC to B-Parasite VCC
    • Adapter GND to B-Parasite GND
    • Adapter TCK to B-Parasite CLK
    • Adapter TMS to B-Parasite IO
  • Launch the command below to identify the interface to use

$ ls /dev | grep 'modem'

cu.usbmodem98B699941

cu.usbmodem98B699943

tty.usbmodem98B699941

tty.usbmodem98B699943

  • Launch gdb

$ arm-none-eabi-gdb

  • Select target

(gdb) target extended-remote /dev/cu.usbmodem98B699941

Remote debugging using /dev/cu.usbmodem98B699941

  • Power the nRF52

(gdb) monitor tpwr enable

Enabling target power

  • Scan targets

(gdb) monitor swdp_scan

Target voltage: 3.3V

Available Targets:

No. Att Driver

 1      Nordic nRF52 M4

 2      Nordic nRF52 Access Port 

  • Attach target 1

(gdb) attach 1

Attaching to Remote target

  • Upoad firmware

(gdb) load out.hex

Loading section .sec1, size 0xb00 lma 0x0

Loading section .sec2, size 0xf000 lma 0x1000

Loading section .sec3, size 0x10000 lma 0x10000

Loading section .sec4, size 0x6634 lma 0x20000

Loading section .sec5, size 0x8818 lma 0x27000

Start address 0x00000000, load size 190796

Transfer rate: 34 KB/sec, 973 bytes/write.

  • Launch debug

(gdb) run

The program being debugged has been started already.

Start it from the beginning? (y or n) y

Starting program:  

warning: No executable has been specified and target does not support

determining executable automatically.  Try using the "file" command.


And that's it, the program is loaded, so now, how to verify that this is working?


The b-parasite can advertise its data following different protocols, you can choose it here

The default protocol is supported by OpenMQTTGateway and Theengs Gateway out of the box. So you can either web upload an ESP32 with OpenMQTTGateway (choose esp32dev-ble-cont for continuous scanning), install Theengs gateway on a server, or Theengs Gateway as an Addon in Home Assistant (for the server installtations reduce the time between scan to 0 so as to have continuous scanning).


Once done, connect to the MQTT broker and you should be able to see the data coming like below:


{ "id":"F0:CA:F0:CA:01:01", "mac_type":1, "name":"prst", "rssi":-89, "servicedata":"21000ba8079caa300cacf0caf0ca01010014", "servicedatauuid":"0x181a", "brand":"rbaron", "model":"b-parasite", "model_id":"BPv1.0-1.2", "tempc":19.48, "tempf":67.064, "hum":66.48051, "moi":4.950027, "lux":20, "volt":2.984 }


With Home Assistant you will have directly the sensor auto-discovered and display values like below:



And finally what about the Theengs App, the sensor can be read with the App but it will require some configuration adjustments discussed here

Here is a screenshot of the values into the app.


Commentaires

Posts les plus consultés de ce blog

433toMQTTto433 - Bidirectional ESP8266 NodeMCU gateway between RF 433Mhz signal and MQTT

The goal  is to act as a gateway between 433Mhz sensors and a MQTT broker or between the MQTT broker and 433Mhz actuators, It enables to: receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data  publish MQTT data to a different topic related to received 433Mhz signal  It can be an interesting part in an home automation system so as to interface sensors and actuators (wall sockets) with software like openhab . List of compatible sensors here The interest of putting this gateway to an ESP8266 and not on a raspberry pi is to be able to manage security actions at gateway level (power on a siren, cut power to certain devices) following RF data received by sensors without being dependent to the PI for security related actions. [EDIT] all infos are now centralized into  the github repository  take a look at it you will find up to date info about OpenMQTTGateway You need: Software: Mosquitto Arduino IDE latest version (tested ok with 1.6.10

Infrared IR, 433mhz and MQTT on ESP8266 bidirectional gateway OpenMQTTGateway

Following discussions on the home assistant forum people gave me the idea to add Infrared communication to the 433mhz gateway.  The goal is to act as a gateway between 433Mhz sensors, infrared remote controls and a MQTT broker or between the MQTT broker and 433Mhz actuators, infrared devices, It enables to: receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data  publish MQTT data to a different topic related to received 433Mhz signal  receive MQTT data from a topic and send infrared signal corresponding to the received MQTT data  publish MQTT data to a different topic related to received infrared signal  It can be an interesting part in an home automation system so as to interface sensors and actuators (wall sockets), your tv, home cinema, hifi ... with software like  openhab  or home assistant . List of compatible RF sensors here [EDIT] all infos are now centralized into the github repository  take a look at it you will find up to d

Get your BLE sensors data into Home Assistant in 5 minutes

You can now upload your board directly from the web browser!  So let's imagine you want to read data from a sensor like a Mi Flora, an LYWSD03MMC, a weight scale, or any other BLE sensor from this list  Plug an ESP32 dev board to your computer USB port Go to this website: https://docs.openmqttgateway.com/upload/web-install.html Select esp32dev-ble Click the install button Depending on your board you may have to press the BOOT button Choose the port that the ESP is connected to. Wait until the process is complete. Release the BOOT button That's it, OMG is now loaded into your ESP32 board without Arduino IDE, platformIO or a binary flasher. Here are the steps in images: Now comes the Home Assistant part: Add the MQTT integration and activate auto discovery Create a user and a password (Configuration->Users) without administrator right for the gateway Well, this is enough for Home Assistant. So let's now connect both: Check the Wifi Access points available with your smartph