 	if (LOG_DATA && sensorReadingSuccessful) {
 		Serial.println("Logging data");
 
-		if (!networkConnected) {
-			networkConnected = connectToWirelessNetwork();
+		if (WiFi.status() != WL_CONNECTED) {
+			connectToWirelessNetwork();
 		}
 
 		bool dataLoggingSuccessful = false;
-		if (networkConnected) {
+		if (WiFi.status() == WL_CONNECTED) {
 			dataLoggingSuccessful = writeToThingSpeak(temperature, humidity);
 		}
 


// Initialization
DHT weatherSensor = DHT(DHT_PIN, DHT_TYPE);
bool networkConnected = false;


// Main

			Serial.println(" dBm)");

			WiFi.maxLowPowerMode();
			return;
		}

		// Wait in between attempts
