Loftilla Bathroom Scale support - BLE MQTT gateway showing manufacturer data in hex

Here’s code that is working for me.

#define KG_TO_LBS_RATIO	(2.2046226218488)
#define SCALE_BLE_MANUFACTURER_STRLEN	(11)
		if ( strcmp("QN-S3", (char *)advertisedDevice.getName().c_str()) == 0 ) {
		  const int slen = SCALE_BLE_MANUFACTURER_STRLEN;
		  uint8_t *manfData = (uint8_t*)advertisedDevice.getManufacturerData().data();
		  int kg = manfData[slen - 1] << 8 | manfData[slen - 2];

		  int isStableMeasurement = (advertisedDevice.getManufacturerData().c_str()[slen - 3] & 0x01);
		  if ( isStableMeasurement ) {
			char strLbs[8];
			sprintf( strLbs, "%.1f", (float) kg / 100.0 * KG_TO_LBS_RATIO );
			BLEdata.set("weight", strLbs);
			Log.notice(F("weight: %s lbs" CR), strLbs );
			String lbsTopic = mactopic + String("/") + String("lbs");
            pub((char *)lbsTopic.c_str(), strLbs);
		  }
		}

I shoved it right after the
if (advertisedDevice.haveManufacturerData())
in ZgatewayBT.ino

But I’m guessing you have a prettier place to put it. And may not want to force lbs. So I’ll leave it to you to choose what to do with it.

Note that I can not leave the Scan_duration at 10, because the scale throws many readings immediately over and over again, and then when it finally settles in, then it sends that particular reading with a “stable” flag. But if you scan for a long time (multiple seconds), it only gets the first advertisement, which isn’t likely to be the stable reading. So I set my Scan_duration to 2 seconds (and even with that, I worry it may miss the stable reading). Maybe there is a more elegant way to solve that, as your note that reducing Scan_duration below 10 seconds scares me.

1 Like