Skip to content

Arduino Library for receiving b parasite data

License

Notifications You must be signed in to change notification settings

Maaajaaa/BParasite

 
 

Repository files navigation

BParasite Arduino library

License: MIT

Arduino BLE Client Library based on NimBLE-Arduino for receiving b-parasite BLE data (soil moisture, temperature, humidity, illuminance as well as battery voltage).

This project allows to receive data from a battery-powered bluetooth low energy soil moisture sensor b-parasite.

The b-parasite firmware sends the sensor and status data as BLE advertisements, i.e. multiple clients can receive and use the sensor data. This is done using the BTHome Protcol

This project is heavily based on the ATC_MiThermometer - with all its benefits inherited from NimBLE-Arduino.

Example

#include "BParasite.h"

const int scanTime = 5; // BLE scan time in seconds
// List of known sensors' BLE addresses
std::vector<std::string> knownBLEAddresses = {"01:23:45:67:89:AB","01:23:45:67:89:CD"};

BParasite parasite(knownBLEAddresses);

// Iteration counter
int iteration = 0;

void setup() {


    Serial.begin(115200);
    // Print free heap before initialization
    Serial.println("Starting:    Free heap is " + String(ESP.getFreeHeap()));
    
    // Initialization
    parasite.begin();
    
    // Print free heap after initialization
    Serial.println("Initialized: Free heap is " + String(ESP.getFreeHeap()));
}

void loop() {
    // Set sensor data invalid
    parasite.resetData();
    
    // Get sensor data - run BLE scan for <scanTime>
    unsigned found = parasite.getData(scanTime);

    for (int i=0; i < parasite.data.size(); i++) {  
        if (parasite.data[i].valid) {
            Serial.println();
            Serial.printf("Sensor %d: %s\n", i, knownBLEAddresses[i].c_str());
            Serial.printf("%.2f°C\n", parasite.data[i].temperature/100.0);
            Serial.printf("%.2f%% humidity\n", parasite.data[i].humidity/100.0);
            Serial.printf("%.3fV\n",  parasite.data[i].batt_voltage/1000.0);
            Serial.printf("%.2f%% soil moisture\n", parasite.data[i].soil_moisture/100.0);
            Serial.printf("%.2flux\n", parasite.data[i].illuminance/100.0);
            Serial.printf("%ddBm\n",  parasite.data[i].rssi);
            Serial.println();
         }
    }
    Serial.println("BLE Devices found (total): " + String(found));

    // Delete results from BLEScan buffer to release memory
    parasite.clearScanResults();
    
    // Print iteration counter and free heap
    Serial.println("Iteration " + String(iteration++) + " - Free heap is " + String(ESP.getFreeHeap()));
    Serial.println("---");

    delay(2000);
}

Similar Projectss

There's also an implementation of this sensor for ESPHome which I've modified to work with currrent data called esphome_b_parasite_component

Todos

  • Adding the library to the Arduino and Platformio library collections
  • implementing a non-blocking example like this

About

Arduino Library for receiving b parasite data

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%