#include //vars float x = 185.3; unsigned long lgUpdateTime; #define BLEService weightService("0000181d-0000-1000-8000-00805f9b34fb"); #define BLEFloatCharacteristic weight("00002a9d-0000-1000-8000-00805f9b34fb", BLERead | BLENotify); void setup() { Serial.begin(9600); // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); while (1); } BLE.setLocalName("MH_Wgt_Scale"); BLE.setAdvertisedService(weightService); weightService.addCharacteristic(weight); BLE.addService(weightService); weight.setValue(0.0); BLE.advertise(); Serial.println("Bluetooth device active, waiting for connections..."); lgUpdateTime = millis(); } void loop() { //Execute Comms every 2000 milli seconds if(millis() - lgUpdateTime > 2000) { lgUpdateTime = millis(); // wait for a BLE central BLEDevice central = BLE.central(); // if a central is connected to the peripheral: if (central) { Serial.println("Connected to central: "); // print the central's BT address: Serial.println(central.address()); digitalWrite(LED_BUILTIN, HIGH); //central is connected: if (central.connected()) { x = x + 1; Serial.print("The weight is: "); Serial.println(x,2); weight.writeValue(x,2); } } else { // when the central disconnects, turn off the LED: digitalWrite(LED_BUILTIN, LOW); Serial.println("Disconnected from central: "); Serial.println(central.address()); } } }