 StaticJsonBuffer<200> jsonBuffer;
 MqttConnector* mqttConnector = NULL;
 
-JsonObject* sensorsData;
+JsonObject* sensorsData = NULL;
 
 void register_receive_hooks(MqttConnector* mqtt)
 {

  sensorsData = &root;

  char dirName[12];
  sprintf(dirName, "/%.4i/%.2i/%.2i", tmYearToCalendar(tm.Year), tm.Month, tm.Day);
  char fileName[25];
  sprintf(fileName, "/%s/%.2i.csv", dirName, tm.Hour);

  File dataFile;
  if(!SD.exists(fileName)){
    if(!SD.mkdir(dirName)){
      Serial.printf("Failed to create directory %s\r\n", dirName);
      return;
    }
    dataFile = SD.open(fileName, O_WRITE | O_CREAT);

  }

  dataFile.seek(dataFile.size());
  char data[100];
  snprintf(data, 100, "%i;%i;%i;%.2f;%i;%i\r\n", currentTime, thc.celsiusHundredths, thc.humidityPercent, bmpTemp, p, ppm);
  dataFile.write(data, 100);
  dataFile.close();
  Serial.println();
}
