 volatile bool haveData = false;
 volatile bool bbutton_up_isr = false;
 volatile bool bbutton_downp_isr = false;
+bool dataUpdated = false;
 
 unsigned long duration;
 


void loop()
{
  while (!bbutton_up_isr)
  {
    if ((millis() - startMiils) > 500)
    {
      detachInterrupt(digitalPinToInterrupt(BUTTON_INT));
      duration = 500;
      bbutton_up_isr = true;
      break;
    }
  }

  if (duration < 500)
  {
    pir_interuptCount = 1;
  }
  else
  {
    pir_interuptCount = 2;
  }

  device_pro.button = pir_interuptCount;
  device_pro.hash = calc_hash(device_pro);
  
  if (haveData)
  {
    Serial.println("Got msg");

  Serial.println("going to sleep....");
  Serial.flush();

  bbutton_up_isr = bbutton_downp_isr = haveData = dataUpdated = false;
  device_pro.button = device_pro.esp8266 = 0;
  device_pro.hash = calc_hash(device_pro);

  attachInterrupt(digitalPinToInterrupt(BUTTON_INT), button_down_isr, FALLING);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

  delay(10);
  if (bbutton_downp_isr)
  {
    Serial.print("Wake up with button, startMiils : ");
    Serial.println(startMiils);
    reset_esp();
  }
  else
  {
    Serial.print("Wake up, startMiils : ");
  }
}

