   });
 
   mqtt->on_connecting([&](int count, bool * flag) {
-    Serial.print("CONNECTION: ");
+    Serial.print("MQTT CONNECTING..: ");
     Serial.println(count);
+  });
+
+  mqtt->on_published([&](const MQTT::Publish & pub) -> void {
+    Serial.print("PUBLISHED: ");
+    Serial.println(pub.payload_string());
   });
 
   mqtt->connect();


void init_wifi()
{
  wifi = new WiFiConnector(ssid, pass);

  wifi->on_connecting([&](const void* message)
  {
    Serial.print("connecting ");
    Serial.println ((char*)message);
    delay(500);
  });

  wifi->on_connected([&](const void* message)
  {
    Serial.print ("WIFI CONECTED: ");
    Serial.println ((char*)message);
  });

  wifi->on_disconnected([&](const void* message)
  {
    Serial.print ("WIFI DISCONECTED: ");
    Serial.print ("WIFI DISCONECTED: ");
    Serial.print ("WIFI DISCONECTED: ");
    Serial.println ((char*)message);
  });

  wifi->connect();

}

void init_mqtt()
{

  mqtt = new MqttConnector("mqtt.tespa.io");

  mqtt->prepare_configuration([&](MqttConnector::Config * config) -> void {

  });

  mqtt->prepare_configuration(NULL);

  mqtt->prepare_data([&](JsonObject * root) -> void {
    JsonObject& data = root->at("d");
    // data["myName"] = "0x001";
    data["adc"] = analogRead(A0);
    data["sdk"] = system_get_sdk_version();
  }, 1500);


  mqtt->prepare_subscribe(NULL);
  mqtt->prepare_subscribe([&](MQTT::Subscribe * sub) -> void {
    // (sub)->add_topic("HELLO");
  });


  mqtt->after_prepare_data([&](JsonObject * root) -> void {
    JsonObject& data = root->at("d");
    //delete data["version"];
  });

  mqtt->on_message([&](const MQTT::Publish & pub) -> void {


#include <pt.h>

MqttConnector *mqtt;
WiFiConnector *wifi;

void init_hardware()
{
  Serial.begin(9600);
  delay(10);
  Serial.println();
  Serial.println("BEGIN");
