 
     Serial.print("IP number assigned by DHCP is ");
     Serial.println(WiFi.localIP());
+}
+
+void setupMQTT()
+{
+    mqttClient.setServer(mqttServer, mqttPort);
+    mqttClient.setCallback(mqttSubHandler);
+    mqttConnect();
+}
+
+void setup()
+{
+    // Serial setup
+    Serial.begin(115200);
+    delay(2000);
+
+    // Sensor setup
+    dht.setup(DHT_DATA_PIN, DHTesp::DHT11);
+    Serial.println("DHT initiated");
+
+    setupWiFi();
+    setupMQTT();
 
     // Read dht every 1000[ms] and repeat forever
-    Tasks.interval(5000, [] {
+    Tasks.interval(10000, [] {
+        char buffer[8];
         // Reading temperature for humidity takes about 250 milliseconds!
         // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
         TempAndHumidity newValues = dht.getTempAndHumidity();


    Serial.print("task start: now = ");
    Serial.println(millis());
}

void loop()

#include <TaskManager.h>
#include <WiFi.h>

/**
 * config.sh should define:
 * const char* wifiSSID = "...";
 * const char* wifiPassword = "....."
 **/
#include "config.h"

// Constants
const int DHT_DATA_PIN = 17;

// Globals
DHTesp dht;
WiFiClient espClient;
PubSubClient mqttClient(espClient);

void mqttConnect()
{
    // Loop until we're reconnected
    while (!mqttClient.connected())
    {
        Serial.print("Attempting MQTT connection...");
        // Attempt to connect
        if (mqttClient.connect(mqttClientName, mqttUser, mqttPassword))
        {
            Serial.println("MQTT connected");
            // Once connected, publish an announcement...
            //mqttClient.publish("sensors/basement/connected", "1");
            // ... and resubscribe
            //mqttClient.subscribe("sensors/basement/led");
        }
        else
        {
            Serial.print("failed, rc=");
            Serial.print(mqttClient.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            delay(5000);
        }
    }
}

void mqttSubHandler(char *topic, byte *message, unsigned int length)
{
    Serial.print("Message arrived on topic: ");
    Serial.print(topic);
    Serial.print(". Message: ");
    String messageTemp;

    for (int i = 0; i < length; i++)
    {
        Serial.print((char)message[i]);
        messageTemp += (char)message[i];
    }
    Serial.println();

    // Act on message here
}

void setupWiFi()
{
    Serial.print("Connecting to ");
    Serial.println(wifiSSID);
    WiFi.disconnect();
