 void sendbme(char* topic) {
   float temperature = 0;
   float humidity = 0;
+  bme_status = bme.begin();
   size_t len = strlen(topic);
-    Serial.print("BME status ");
-   Serial.println(bme_status);
+  Serial.print("BME status ");
+  Serial.println(bme_status);
 
   if (bme_status) {
     strcpy(topicbuffer,topic);

unsigned long lastrun = millis();
int state = 0;
//#define PERIOD 5*60*1000
#define PERIOD 15*1000

bool bme_status;


}

void loop() {
  
  Serial.print("millis ");
  Serial.println(millis());
  //  if (mqtt.connected()) {
  if (millis() > (lastrun + PERIOD)) {
      if (mqtt.connect("Karttula", mqtt_user, mqtt_pass)) {
      
	switch(state) {
	case 0:
	  senddht22(Makuuhuone, topicMakuuhuone);
	  state++;
	  break;
	  
	case 1:
	  sendbme(topicOlohuone);
	  state++;
	  break;
	  
	case 2:
	  senddht22(WC, topicWC);
	  state++;
	  break;
	  
	case 3:
	  senddht22(Vierashuone, topicVierashuone);
	  state = 0;
	  lastrun = millis();
	}
      } else {
	// Restart takes quite some time
	// To skip it, call init() instead of restart()
	Serial.println("Initializing modem...");
	modem.restart();
	
	// Unlock your SIM card with a PIN
	//modem.simUnlock("1234");

	Serial.print("Waiting for network...");
	if (!modem.waitForNetwork()) {
	  Serial.println(" fail");
	  while (true);
	}
	Serial.println(" OK");

	Serial.print("Connecting to ");
	Serial.print(apn);
	if (!modem.gprsConnect(apn, user, pass)) {
	  Serial.println(" fail");
	  while (true);
	}
	Serial.println(" OK");
      }
    }
    
    delay(1000);
    mqtt.loop();
  /* } else { */
  /*   // Reconnect every 10 seconds */
  /*   unsigned long t = millis(); */
  /*   if (t - lastReconnectAttempt > 10000L) { */
  /*     lastReconnectAttempt = t; */
  /*     if (mqttConnect()) { */
  /*       lastReconnectAttempt = 0; */
  /*     } */
  /*   } */
  /* } */
    
  //  Watchdog.reset();

}
