ESP32 as DataGateway from BLE to MQTT

MicErd
Posts: 1
Joined: Wed Aug 06, 2025 5:51 am

ESP32 as DataGateway from BLE to MQTT

Postby MicErd » Wed Aug 06, 2025 6:10 am

Hi,
I am completely new to ESP32. It was ChatGPT that suggested me to use a ESP32 to get data via BLE from LiFePO4 battery and send it via MQTT to a victron cerbo gx (solar project) to get remote view in VRM (Victron portal) on the battery.
So I buyed this ESP device (https://www.amazon.de/dp/B0F446BHYJ?ref ... asin_title) and tried going the first simple steps with ChatGPT code: ESP32 should scan for devices in BLE and show them. But ESP32 doesn't find anything. My iphone finds several BLE devices. I use Arduino IDE for writing code on ESP32. It took me 13 iterations to get the following code out of ChatGPT. Earlier codes weren't even able to be compiled. Silly ChatGPT? Perhaps. Here is the code:
**************************************************************************
#include <NimBLEDevice.h>

void setup() {
Serial.begin(115200);
NimBLEDevice::init("");
}

void loop() {
NimBLEScan* pScan = NimBLEDevice::getScan();
pScan->setActiveScan(true);
pScan->setInterval(500); // Interval between scans
pScan->setWindow(400); // duration active scan window
NimBLEScanResults results = pScan->start(10, false);

Serial.printf("Found devices: %d\n", results.getCount());

for (int i = 0; i < results.getCount(); i++) {
const NimBLEAdvertisedDevice* dev = results.getDevice(i);
Serial.printf("Name: %s, Address: %s\n",
dev->getName().c_str(),
dev->getAddress().toString().c_str());
}
pScan->clearResults();
delay(5000);
}
**************************************************************************
I would like to know: Are my 2 ESP32 Modules defective? Or does the code simply not work?
THX
Regards
Michael

MicroController
Posts: 2663
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32 as DataGateway from BLE to MQTT

Postby MicroController » Thu Aug 07, 2025 7:57 am


Who is online

Users browsing this forum: No registered users and 7 guests