   Serial.print(F("Disconnected event, central: "));
   Serial.println(central.address());
 }
+

#endif

  blePeripheral.setLocalName("Temperature");
  blePeripheral.setAdvertisedServiceUuid(tempService.uuid());
  blePeripheral.addAttribute(tempService);
  blePeripheral.addAttribute(tempCharacteristic);
  blePeripheral.addAttribute(tempDescriptor);

  blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

  blePeripheral.begin();
  
  Timer1.initialize(1 * 1000000); // in milliseconds
  Timer1.attachInterrupt(timerHandler);
}

void loop() {
  blePeripheral.poll();
  
  if (readTemperature) {
    setTempCharacteristicValue();
    readTemperature = false;
  }
}

void timerHandler() {
  readTemperature = true;
}

void setTempCharacteristicValue() {
  int temp = readTempC();
  tempCharacteristic.setValue(temp);
  Serial.println(temp);
}

int readTempC() {
  // Stubbing out for demo with random value generator
  // Replace with actual sensor reading code
  return random(100);
}

void blePeripheralConnectHandler(BLECentral& central) {

#define BLE_RDY   2
#define BLE_RST   9

#define DHTTYPE DHT22
#define DHTPIN 3

DHT dht(DHTPIN, DHTTYPE);

BLEPeripheral blePeripheral = BLEPeripheral(BLE_REQ, BLE_RDY, BLE_RST);

BLEService tempService = BLEService("CCC0");
BLECharacteristic tempCharacteristic = BLECharacteristic("CCC1", BLERead | BLENotify, 7);
BLEDescriptor tempDescriptor = BLEDescriptor("2901", "Temp Celsius");

BLEService humidityService = BLEService("DDD0");
BLECharacteristic humidityCharacteristic = BLECharacteristic("DDD1", BLERead | BLENotify, 6);
BLEDescriptor humidityDescriptor = BLEDescriptor("2901", "Humidity Percent");

volatile bool readFromSensor = false;

float lastTempReading;
float lastHumidityReading;

void setup() {
  Serial.begin(115200);
