 				firstPublish = false;
 			}
 		}
+		// Check if time to Update configuration
+		if (isTimePassed(updateConfigTs, MQTT_UPDATE_CONFIG_PERIOD_MS)) {
+			if (updateConfig()) {
+				updateConfigTs = time.millis();
+			}
+		}
 		// Idle until next event
-		LOG_PRINTFLN("Idle for %lu ms", min(timeLeft(publishTs, publishPeriodMs), mqtt->getIdleInterval()));
+		unsigned long nextEventDelay = min(
+			timeLeft(publishTs, publishPeriodMs),
+			timeLeft(updateConfigTs, MQTT_UPDATE_CONFIG_PERIOD_MS)
+		);
+		LOG_PRINTFLN("Idle for %lu ms", min(nextEventDelay, mqtt->getIdleInterval()));
 		networkHibernate(NETWORK_HIBERNATE_DELAY_MS);
-		Lpm::idle(min(timeLeft(publishTs, publishPeriodMs), mqtt->getIdleInterval()));
+		Lpm::idle(min(nextEventDelay, mqtt->getIdleInterval()));
 		networkWakeUp(NETWORK_WAKE_UP_DELAY_MS);
-		// Determine the next event
-		if (timeLeft(publishTs, publishPeriodMs) > mqtt->getIdleInterval()) {
+		// Determine the next event after wake up
+		nextEventDelay = min(
+			timeLeft(publishTs, publishPeriodMs),
+			timeLeft(updateConfigTs, MQTT_UPDATE_CONFIG_PERIOD_MS)
+		);
+		if (nextEventDelay > mqtt->getIdleInterval()) {
 			// Need to call yield
 			while(mqtt->isConnected() && mqtt->getIdleInterval() < MQTT_COMMAND_TIMEOUT_MS) {
 				mqtt->yield();

void(* reset) (void) = 0;//declare reset function at address 0
void check();
void connect();
void buildMessagePayload(char* buffer, int size);
void processMessageConfig(MqttClient::MessageData& md);
void networkHibernate(unsigned long);

		if (rc != MqttClient::Error::SUCCESS) {
			LOG_PRINTFLN("ERROR, Connect, rc:%i", rc);
		} else {
			if (updateConfig()) {
				// Success
				updateConfigTs = time.millis();
				return;
			}
		}
	}
	// Failure => disconnect
	network->disconnect();
}

bool updateConfig() {
	bool res = false;
	if (mqtt->isConnected()) {
		const char* topic = MQTT_SUBSCRIBE_TOPIC_CFG;
		LOG_PRINTFLN("Subscribe to %s", topic);
		MqttClient::Error::type rc = mqtt->subscribe(topic, MQTT_SUBSCRIBE_QOS, processMessageConfig);
		if (rc != MqttClient::Error::SUCCESS) {
			LOG_PRINTFLN("ERROR, Subscribe, rc:%i", rc);
		} else {
			// Listen for configuration
			LOG_PRINTFLN("Waiting the configuration for %lu ms", MQTT_LISTEN_TIME_MS);
			mqtt->yield(MQTT_LISTEN_TIME_MS);
			rc = mqtt->unsubscribe(topic);
			if (rc != MqttClient::Error::SUCCESS) {
				LOG_PRINTFLN("ERROR, Unsubscribe, rc:%i", rc);
			} else {
				// Success
				res = true;
			}
		}
	}
	if (!res) {
		LOG_PRINTFLN("Drop connection");
		mqtt->disconnect();
	}
	return res;
}

void processMessageConfig(MqttClient::MessageData& md) {
