/* lp_BLE_temp_GT832E_01 This sketch sets up a Nordic BLE UART and sends the chip temperature once a second when connected (c)2022 Forward Computing and Control Pty. Ltd. This example code is in the public domain. */ #include lp_timer tempTimer; const unsigned long DELAY_TIME = 1000; // ms == 1sec lp_BLESerial ble; void setup() { ble.setName("Chip Temperature"); // set advertised name, default name is "Nordic BLE UART" ble.setConnectedHandler(handleConnection); // when a connection is made ble.setDisconnectedHandler(handleDisconnection); // when the connection is dropped or goes out of range ble.begin(); // start advertising and be ready to accept connections } void loop() { sleep(); // just sleep here waiting for a trigger while (ble.available()) { int i = ble.read(); // clear BLE recieve buffer and ignore // could add cmds there to send stored historical temps } } void handleTempTimer() { // send the current time and temp float temp = getChipTemperature(); ble.print(millis()); ble.print(','); ble.print(temp); ble.println(); } void handleConnection(BLECentral& central) { // could just start this in setup and leave running tempTimer.startTimer(DELAY_TIME, handleTempTimer); } void handleDisconnection(BLECentral& central) { // no real need to stop here, ble.print discards the bytes if not connected tempTimer.stop(); }