# DHT22 getting started device.sendState problem

**URL:** <https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570>\
**Category:** Help\
**Tags:** mqtt\
**Created:** [February 4, 2021, 4:23pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570 "2021-02-04T16:23:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 4, 2021, 4:23pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/1 "2021-02-04T16:23:48Z")

</div>

Hey I´m struggeling withe the DHT22 project.  
I followed the Instruction and the description about the update from json5 to json6.  
But Now the code can not be compiled. I always get the following error:  
no matching function for call to ‘LosantDevice::sendState(ArduinoJson6161\_11::StaticJsonDocument\<500u\>&)’

If i uncomment the device.sendState line the code works, but no data is send.  
Also sendState is not coloured like in the example

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [February 4, 2021, 5:04pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/3 "2021-02-04T17:04:56Z")

</div>

Hello @Matthias_Kamps,

Welcome to the Losant forums, we’re happy you’re here!

Would you be able to send me a link to the example you’re following? Would you also be able to send me your code, or at least some snippets of it?

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 4, 2021, 5:37pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/5 "2021-02-04T17:37:38Z")

</div>

Of Course!  
This is the example:

> **[Getting Started With the ESP8266 and DHT22 Sensor](https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor)**
>
> A tutorial on getting started with the ESP8266 NodeMCU and a DHT22 temperature and humidity sensor.

And a snippet of my code:

```auto
void report(double humidity, double tempC, double heatIndexC) {
  StaticJsonDocument<500> doc;
  
  doc["humidity"] = humidity;
  doc["tempC"] = tempC;
  //doc["tempF"] = tempF;
  doc["heatIndexC"] = heatIndexC;
  //doc["heatIndexF"] = heatIndexF;
  device.sendState(doc);
  Serial.println("Reported!");
}

```

Is there any way to post the complete code?

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [February 4, 2021, 5:58pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/7 "2021-02-04T17:58:22Z")

</div>

@Matthias_Kamps,

You sent the exact snippet I was looking for, I appreciate it!

You’re using `StaticJsonDocument` correctly, which is great. But you’re missing one small step. `StaticJsonDocument` is ArduinoJson’s type for JSON, you’ll need to cast it to a JSON object before sending state since Losant is expecting a JSON Obejct.

You can do this by adding ` JsonObject root = doc.to<JsonObject>();` and then modifying the `device.sendState` to be `device.sendState(root);`

So your function would look like:

```auto
void report(double humidity, double tempC, double heatIndexC) {
  StaticJsonDocument<500> doc;

  doc[“humidity”] = humidity;
  doc[“tempC”] = tempC;
  //doc[“tempF”] = tempF;
  doc[“heatIndexC”] = heatIndexC;
  //doc[“heatIndexF”] = heatIndexF;
  JsonObject root = doc.to<JsonObject>();
  device.sendState(root);
  Serial.println(“Reported!”);
}

```

Let me know if this works for you or if you have any other questions.

Thanks,  
Heath

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 4, 2021, 6:22pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/9 "2021-02-04T18:22:33Z")

</div>

The code can be compiled now and there is communication.  
But there is still no data transfer.  
 ![grafik](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/19ce75238899c7dc413af541bd823e96085cc8e8.png)

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [February 4, 2021, 6:42pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/11 "2021-02-04T18:42:16Z")

</div>

@Matthias_Kamps,

I think this would be the perfect place to see the rest of your code!

Are you getting sensor readings in your serial monitor?  
How are you calling the `report()` function you defined?

I’d also like to point out that our forums have a great search utility. Here are some links I found that are similar to your question:

- [Example for sending temperature and humidity to the cloud using the DHT22 and ESP8266 Code # 2 - #5 by JuliaKempf](https://forums.losant.com/t/example-for-sending-temperature-and-humidity-to-the-cloud-using-the-dht22-and-esp8266-code-2/2773/5)
- [[CLOSED] Raspberry pi with DHT22 sensor ;NOT GETTING ANY PAYLOAD - #4 by anaptfox](https://forums.losant.com/t/closed-raspberry-pi-with-dht22-sensor-not-getting-any-payload/862/4)
- [ESP8266 with Arduino and Display LCD](https://forums.losant.com/t/esp8266-with-arduino-and-display-lcd/2944)

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 4, 2021, 6:52pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/13 "2021-02-04T18:52:07Z")

</div>

Yes, I can see my measurements on ther serial monitor.

Here is my complete code:  
(Sorry for so many parts, but it did not work in One Post)

```auto
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Losant.h>

#define DHTPIN 4 // what digital pin the DHT22 is conected to
#define DHTTYPE DHT22 // There are multiple kinds of DHT sensors

DHT dht(DHTPIN, DHTTYPE);

// WiFi credentials.
const char* WIFI_SSID = "XX";
const char* WIFI_PASS = "XX";

// Losant credentials.
const char* LOSANT_DEVICE_ID = "XX";
const char* LOSANT_ACCESS_KEY = "XX";
const char* LOSANT_ACCESS_SECRET = "XX";

WiFiClient WiFiClient;

LosantDevice device (LOSANT_DEVICE_ID);

void connect() {

  // Connect to Wifi.
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);

  // WiFi fix: https://github.com/esp8266/Arduino/issues/2186
  WiFi.persistent(false);
  WiFi.mode(WIFI_OFF);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  unsigned long wifiConnectStart = millis();

  while (WiFi.status() != WL_CONNECTED) {
    // Check to see if
    if (WiFi.status() == WL_CONNECT_FAILED) {
      Serial.println("Failed to connect to WIFI. Please verify credentials: ");
      Serial.println();
      Serial.print("SSID: ");
      Serial.println(WIFI_SSID);
      Serial.print("Password: ");
      Serial.println(WIFI_PASS);
      Serial.println();
    }

    delay(500);
    Serial.println("...");
    // Only try for 5 seconds.
    if(millis() - wifiConnectStart > 5000) {
      Serial.println("Failed to connect to WiFi");
      Serial.println("Please attempt to send updated configuration parameters.");
      return;
    }
  }

```

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 4, 2021, 6:52pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/15 "2021-02-04T18:52:37Z")

</div>

```auto
Serial.println();
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  Serial.print("Authenticating Device...");
  HTTPClient http;
  http.begin("http://api.losant.com/auth/device");
  http.addHeader("Content-Type", "application/json");
  http.addHeader("Accept", "application/json");

  /* Create JSON payload to sent to Losant
   *
   * {
   * "deviceId": "575ecf887ae143cd83dc4aa2",
   * "key": "this_would_be_the_key",
   * "secret": "this_would_be_the_secret"
   * }
   *
   */

  StaticJsonDocument<200> doc;

  doc["deviceId"] = LOSANT_DEVICE_ID;
  doc["key"] = LOSANT_ACCESS_KEY;
  doc["secret"] = LOSANT_ACCESS_SECRET;
  String buffer;
  serializeJson(doc, Serial);

  int httpCode = http.POST(buffer);

  if(httpCode > 0) {
      if(httpCode == HTTP_CODE_OK) {
          Serial.println("This device is authorized!");
      } else {
        Serial.println("Failed to authorize device to Losant.");
        if(httpCode == 400) {
          Serial.println("Validation error: The device ID, access key, or access secret is not in the proper format.");
        } else if(httpCode == 401) {
          Serial.println("Invalid credentials to Losant: Please double-check the device ID, access key, and access secret.");
        } else {
           Serial.println("Unknown response from API");
        }
      }
    } else {
        Serial.println("Failed to connect to Losant API.");

   }

  http.end();

  // Connect to Losant.
  Serial.println();
  Serial.print("Connecting to Losant...");

  device.connect(WiFiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

  while(!device.connected()) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("Connected!");
  Serial.println();
  Serial.println("This device is now ready for use!");
}

void setup() {
  Serial.begin(9600);
  Serial.setTimeout(2000);

  // Wait for serial to initialize.
  while(!Serial) { }
  
  dht.begin();

  Serial.println("Device Started");
  Serial.println("-------------------------------------");
  Serial.println("Running DHT!");
  Serial.println("-------------------------------------");

  connect();
}

```

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 4, 2021, 6:53pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/16 "2021-02-04T18:53:21Z")

</div>

```auto
void report(double humidity, double tempC, double heatIndexC) {
  StaticJsonDocument<500> doc;
  
  doc["humidity"] = humidity;
  doc["tempC"] = tempC;
  //doc["tempF"] = tempF;
  doc["heatIndexC"] = heatIndexC;
  //doc["heatIndexF"] = heatIndexF;
  device.sendState(doc);
  Serial.println("Reported!");
}

int timeSinceLastRead = 0;
void loop() {
   bool toReconnect = false;

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Disconnected from WiFi");
    toReconnect = true;
  }

  if (!device.connected()) {
    Serial.println("Disconnected from MQTT");
    //Serial.println(device.mqttClient.state());
    toReconnect = true;
  }

  if (toReconnect) {
    connect();
  }

  device.loop();

  // Report every 2 seconds.
  if(timeSinceLastRead > 2000) {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    float f = dht.readTemperature(true);

    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      timeSinceLastRead = 0;
      return;
    }

    // Compute heat index in Fahrenheit (the default)
    float hif = dht.computeHeatIndex(f, h);
    // Compute heat index in Celsius (isFahreheit = false)
    float hic = dht.computeHeatIndex(t, h, false);

    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    //Serial.print(f);
    //Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    //Serial.print(hif);
    //Serial.println(" *F");
    report(h, t, hic);

    timeSinceLastRead = 0;
  }
  delay(100);
  timeSinceLastRead += 100;
}

```

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [February 4, 2021, 6:59pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/17 "2021-02-04T18:59:38Z")

</div>

@Matthias_Kamps,

Thanks so much!

You mentioned that you **are** getting measurements in your serial monitor. Would you be able to send me a screenshot of that? One that includes the startup sequence, and the first few sensor readings?

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 4, 2021, 7:10pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/19 "2021-02-04T19:10:01Z")

</div>

Shure!  
I just cuted out the SSID, the Dievice ID, the key and the secret

 ![dht22](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/a/a60f375983c3d544e8b1b3fab6be0fb14550da87.png)

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [February 4, 2021, 7:43pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/21 "2021-02-04T19:43:41Z")

</div>

@Matthias_Kamps,

The code you sent is still missing a piece in the `report` function. Were you able to implement the changes above with the `JsonObject`?

```auto
void report(double humidity, double tempC, double heatIndexC) {
  StaticJsonDocument<500> doc;

  doc[“humidity”] = humidity;
  doc[“tempC”] = tempC;
  //doc[“tempF”] = tempF;
  doc[“heatIndexC”] = heatIndexC;
  //doc[“heatIndexF”] = heatIndexF;

  JsonObject root = doc.to<JsonObject>();

  device.sendState(root);
  Serial.println(“Reported!”);
}

```

Another debug option you have is to go into your local copy of the Losant client code and add a `Serial.println(stateStr)` before `mqttClient.publish` in `LosantDevice.h`. You can find this file in your Arduino Libraries, usually at `Documents/Arduino/Libraries`. Doing this would allow you to see exactly what is being sent as state to Losant.

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 5, 2021, 2:23pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/23 "2021-02-05T14:23:26Z")

</div>

Oh you´re right I sent you a former version of my Code.  
This is the current verison:

```auto
#include <Losant.h>
/**
 * Example for sending temperature and humidity
 * to the cloud using the DHT22 and ESP8266
 *
 * Copyright (c) 2016 Losant IoT. All rights reserved.
 * https://www.losant.com
 */

#include "DHT.h"
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define DHTPIN 4 // what digital pin the DHT22 is conected to
#define DHTTYPE DHT22 // There are multiple kinds of DHT sensors

DHT dht(DHTPIN, DHTTYPE);

// WiFi credentials.
const char* WIFI_SSID = "";
const char* WIFI_PASS = "";

// Losant credentials.
const char* LOSANT_DEVICE_ID = "";
const char* LOSANT_ACCESS_KEY = "";
const char* LOSANT_ACCESS_SECRET = "";

WiFiClient WiFiClient;

LosantDevice device (LOSANT_DEVICE_ID);

void connect() {

  // Connect to Wifi.
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WIFI_SSID);

  // WiFi fix: https://github.com/esp8266/Arduino/issues/2186
  WiFi.persistent(false);
  WiFi.mode(WIFI_OFF);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  unsigned long wifiConnectStart = millis();

  while (WiFi.status() != WL_CONNECTED) {
    // Check to see if
    if (WiFi.status() == WL_CONNECT_FAILED) {
      Serial.println("Failed to connect to WIFI. Please verify credentials: ");
      Serial.println();
      Serial.print("SSID: ");
      Serial.println(WIFI_SSID);
      Serial.print("Password: ");
      Serial.println(WIFI_PASS);
      Serial.println();
    }

    delay(500);
    Serial.println("...");
    // Only try for 5 seconds.
    if(millis() - wifiConnectStart > 5000) {
      Serial.println("Failed to connect to WiFi");
      Serial.println("Please attempt to send updated configuration parameters.");
      return;
    }
  }

  Serial.println();
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  Serial.print("Authenticating Device...");
  HTTPClient http;
  http.begin("http://api.losant.com/auth/device");
  http.addHeader("Content-Type", "application/json");
  http.addHeader("Accept", "application/json");

  /* Create JSON payload to sent to Losant
   *
   * {
   * "deviceId": "575ecf887ae143cd83dc4aa2",
   * "key": "this_would_be_the_key",
   * "secret": "this_would_be_the_secret"
   * }
   *
   */

  StaticJsonDocument<200> doc;

  doc["deviceId"] = LOSANT_DEVICE_ID;
  doc["key"] = LOSANT_ACCESS_KEY;
  doc["secret"] = LOSANT_ACCESS_SECRET;
  String buffer;
  serializeJson(doc, Serial);

  int httpCode = http.POST(buffer);

  if(httpCode > 0) {
      if(httpCode == HTTP_CODE_OK) {
          Serial.println("This device is authorized!");
      } else {
        Serial.println("Failed to authorize device to Losant.");
        if(httpCode == 400) {
          Serial.println("Validation error: The device ID, access key, or access secret is not in the proper format.");
        } else if(httpCode == 401) {
          Serial.println("Invalid credentials to Losant: Please double-check the device ID, access key, and access secret.");
        } else {
           Serial.println("Unknown response from API");
        }
      }
    } else {
        Serial.println("Failed to connect to Losant API.");

   }

  http.end();

  // Connect to Losant.
  Serial.println();
  Serial.print("Connecting to Losant...");

  device.connect(WiFiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

  while(!device.connected()) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("Connected!");
  Serial.println();
  Serial.println("This device is now ready for use!");
}

void setup() {
  Serial.begin(9600);
  Serial.setTimeout(2000);

  // Wait for serial to initialize.
  while(!Serial) { }
  
  dht.begin();

  Serial.println("Device Started");
  Serial.println("-------------------------------------");
  Serial.println("Running DHT!");
  Serial.println("-------------------------------------");

  connect();
}

void report(double humidity, double tempC,double tempF, double heatIndexC, double heatIndexF) {
  StaticJsonDocument<500> doc;
  
  doc["humidity"] = humidity;
  doc["tempC"] = tempC;
  doc["tempF"] = tempF;
  doc["heatIndexC"] = heatIndexC;
  doc["heatIndexF"] = heatIndexF;
  JsonObject root = doc.to<JsonObject>();
  device.sendState(root);
  Serial.println("Reported!");
}

int timeSinceLastRead = 0;
void loop() {
   bool toReconnect = false;

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Disconnected from WiFi");
    toReconnect = true;
  }

  if (!device.connected()) {
    Serial.println("Disconnected from MQTT");
    //Serial.println(device.mqttClient.state());
    toReconnect = true;
  }

  if (toReconnect) {
    connect();
  }

  device.loop();

  // Report every 2 seconds.
  if(timeSinceLastRead > 2000) {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    float f = dht.readTemperature(true);

    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      timeSinceLastRead = 0;
      return;
    }

    // Compute heat index in Fahrenheit (the default)
    float hif = dht.computeHeatIndex(f, h);
    // Compute heat index in Celsius (isFahreheit = false)
    float hic = dht.computeHeatIndex(t, h, false);

    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    Serial.print(hif);
    Serial.println(" *F");
    report(h, t, f, hic, hif);

    timeSinceLastRead = 0;
  }
  delay(100);
  timeSinceLastRead += 100;
}

```

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 5, 2021, 2:29pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/25 "2021-02-05T14:29:50Z")

</div>

> [@Heath](#):
>
> `mqttClient.publish` in `LosantDevice.h`

I can´t find this line in my LosantDevice.h  
There is only : MQTTClient mqttClient = MQTTClient(MQTT\_MAX\_PACKET\_SIZE);

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [February 5, 2021, 2:31pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/26 "2021-02-05T14:31:22Z")

</div>

@Matthias_Kamps,

My apologies. It should be in `LosantDevice.cpp`.

I’m looking over your code now!

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 5, 2021, 2:37pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/27 "2021-02-05T14:37:08Z")

</div>

Yes that worked!  
It looks in deed, like it does not send any data.

 ![grafik](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/a/acb22b60688495007b28518002051e2cfcbdcace.png)

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [February 5, 2021, 4:32pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/28 "2021-02-05T16:32:45Z")

</div>

@Matthias_Kamps,

Thank so much, this is certainly interesting.

Would you be able to add `serializeJson(root, Serial);` to your `report` function? It would look like this:

```auto
void report(double humidity, double tempC,double tempF, double heatIndexC, double heatIndexF) {
  StaticJsonDocument<500> doc;
  doc["humidity"] = humidity;
  doc["tempC"] = tempC;
  doc["tempF"] = tempF;
  doc["heatIndexC"] = heatIndexC;
  doc["heatIndexF"] = heatIndexF;
  JsonObject root = doc.to<JsonObject>();
  serializeJson(root, Serial);
  device.sendState(root);
  Serial.println("Reported!");
}

```

This will allow you to see what the `root` object looks like before we send it to Losant.

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 5, 2021, 4:44pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/29 "2021-02-05T16:44:06Z")

</div>

Of course!  
This is what the serial monitor shows now:

 ![grafik](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/6/6d84cbc4ff4353cb43ec72a1d812ddeba9cbe529.png)

By the way, thank you for your help already. Never seen such fast an qualified response in a Forum!!

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [February 5, 2021, 4:58pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/30 "2021-02-05T16:58:20Z")

</div>

@Matthias_Kamps,

Something small, but I think it may be the issue.

In your code you have: ` JsonObject root = doc.to<JsonObject>();`

Instead of `.to<...` it should be `.as<...`

So you’re new line there would be:

` JsonObject root = doc.as<JsonObject>();`

Cheers,  
Heath

---

<div class="post-metadata">

**Author:** ![Matthias\_Kamps](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@Matthias\_Kamps](https://forums.losant.com/u/Matthias_Kamps)\
**Post date:** [February 5, 2021, 5:03pm UTC](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570/31 "2021-02-05T17:03:29Z")

</div>

That´s it !!  
Thank you verry much!  
Nice to get some help from a genius! 😃

[Next page](https://forums.losant.com/t/dht22-getting-started-device-sendstate-problem/3570.md?page=2)
