Hi
I am looking for help in collecting LYWSD03MMC data via bluetooth using a ESP32.
The LYWSD03MMC is the Mi Temperature and Humidity Monitor. I have the original version.
I can see the devices using a basic Arduino bluetooth scanner sketch.
However, I cannot read the data.
I have even flashed the ATC firmware.
All I get is a count of devices, but no data.
I have spent days trying different sketches but no joy.
Can someone point me to a proven Arduino sketch for a stock LYWSD03MM.
Or, could someone point me to a proven Arduino sketch for the ATC firmware, with details of which settings to invoke in the Telink Flasher?
Thanks guys
LYWSD03MMC Problems : SOLVED
LYWSD03MMC Problems : SOLVED
Last edited by AcmeUK on Sun Dec 21, 2025 5:59 pm, edited 1 time in total.
-
lichurbagan
- Posts: 60
- Joined: Thu Nov 13, 2025 3:20 pm
Re: LYWSD03MMC Problems
Hi Lichurbagan
Thank you for your response.
I was looking for a vanilla script that just puts the data read out on the serial monitor.
This is targeted at MQTT and Platformio.
However, I tried to adapt it, BUT there is an #include <userconfig.h>; this generates :- Compilation error: userconfig.h: No such file or directory
I have looked but cannot find details of the content of userconfig.h
Thank you for your response.
I was looking for a vanilla script that just puts the data read out on the serial monitor.
This is targeted at MQTT and Platformio.
However, I tried to adapt it, BUT there is an #include <userconfig.h>; this generates :- Compilation error: userconfig.h: No such file or directory
I have looked but cannot find details of the content of userconfig.h
-
lbernstone
- Posts: 1133
- Joined: Mon Jul 22, 2019 3:20 pm
Re: LYWSD03MMC Problems
Hi Lichurbagan
Thank you for your response.
I had not unpacked the zip correctly.
However, this looks too complex.
As I said in my post, I am looking for a simple script that puts the readings out on the serial monitor.
I can the build from there.
Kind regards
Thank you for your response.
I had not unpacked the zip correctly.
However, this looks too complex.
As I said in my post, I am looking for a simple script that puts the readings out on the serial monitor.
I can the build from there.
Kind regards
Re: LYWSD03MMC Problems : SOLVED
Hi Lichurbagan
Good News
I uploaded the main.ino sketch to ChatGPT and requested it to modify the code to remove MQTT and Platformio features. Then modify to show device readings on the serial monitor.
And, it worked! Although I had to change the UUIDs.
I did try a modification to also use ATC software. No joy so I abandoned ATC for the time being.
So, now I have a working script that reads LYWSD03MMC stock firmware.
It shows that not all ChatGPT output is rubbish!
For anyone researching the same problem I am parking the code here:-
Many Thanks
Good News
I uploaded the main.ino sketch to ChatGPT and requested it to modify the code to remove MQTT and Platformio features. Then modify to show device readings on the serial monitor.
And, it worked! Although I had to change the UUIDs.
I did try a modification to also use ATC software. No joy so I abandoned ATC for the time being.
So, now I have a working script that reads LYWSD03MMC stock firmware.
It shows that not all ChatGPT output is rubbish!
For anyone researching the same problem I am parking the code here:-
Code: Select all
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEClient.h>
#include <BLEAddress.h>
#define SENSOR_MAC "a4:c1:38:f6:89:e0" // <-- CHANGE THIS
#define SERIAL_BAUD 115200
// LYWSD03MMC UUIDs
// static BLEUUID serviceUUID("0000fe95-0000-1000-8000-00805f9b34fb"); // Did not work
// static BLEUUID charUUID("00000017-0000-1000-8000-00805f9b34fb"); // Did not work
static BLEUUID serviceUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6");
static BLEUUID charUUID ("ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6");
BLEClient* pClient;
bool connected = false;
class MyClientCallback : public BLEClientCallbacks {
void onConnect(BLEClient* pclient) {
Serial.println("✅ BLE connected");
}
void onDisconnect(BLEClient* pclient) {
Serial.println("❌ BLE disconnected");
connected = false;
}
};
void notifyCallback(
BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData,
size_t length,
bool isNotify) {
if (length != 5) {
Serial.println("❗ Unexpected data length");
return;
}
float temperature = (pData[0] | (pData[1] << 8)) * 0.01;
float humidity = pData[2];
float voltage = ((pData[4] << 8) | pData[3]) / 1000.0;
float battery = (voltage - 2.1) * 100.0;
if (battery > 100) battery = 100;
if (battery < 0) battery = 0;
Serial.println("📡 Sensor Data:");
Serial.print(" Temperature: "); Serial.print(temperature); Serial.println(" °C");
Serial.print(" Humidity: "); Serial.print(humidity); Serial.println(" %");
Serial.print(" Voltage: "); Serial.print(voltage); Serial.println(" V");
Serial.print(" Battery: "); Serial.print(battery); Serial.println(" %");
Serial.println("--------------------------------");
pClient->disconnect();
}
void connectToSensor() {
BLEAddress address(SENSOR_MAC);
pClient = BLEDevice::createClient();
pClient->setClientCallbacks(new MyClientCallback());
if (!pClient->connect(address)) {
Serial.println("❌ Failed to connect to sensor");
return;
}
connected = true;
BLERemoteService* pService = pClient->getService(serviceUUID);
if (pService == nullptr) {
Serial.println("❌ Service not found");
pClient->disconnect();
return;
}
BLERemoteCharacteristic* pChar = pService->getCharacteristic(charUUID);
if (pChar == nullptr) {
Serial.println("❌ Characteristic not found");
pClient->disconnect();
return;
}
Serial.println("🔔 Waiting for notifications...");
pChar->registerForNotify(notifyCallback);
}
void setup() {
Serial.begin(SERIAL_BAUD);
delay(1000);
Serial.println("🚀 Starting BLE Serial Monitor Client");
BLEDevice::init("ESP32_BLE_Reader");
connectToSensor();
}
void loop() {
// Nothing needed here
delay(1000);
}
Who is online
Users browsing this forum: Baidu [Spider], Qwantbot and 6 guests