# My DHT22 Fails to connect to Losant despite Authorized

**URL:** <https://forums.losant.com/t/my-dht22-fails-to-connect-to-losant-despite-authorized/1655>\
**Category:** Help\
**Tags:** esp8266, dht22\
**Created:** [March 24, 2019, 7:34pm UTC](https://forums.losant.com/t/my-dht22-fails-to-connect-to-losant-despite-authorized/1655 "2019-03-24T19:34:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)\
**Post date:** [March 25, 2019, 2:54pm UTC](https://forums.losant.com/t/my-dht22-fails-to-connect-to-losant-despite-authorized/1655/2 "2019-03-25T14:54:44Z")

</div>

Hello @Ogbe_Isaac,

There are couple ways we can go about debugging this to find a solution. The code in question is:

```auto
  Serial.println();
  Serial.print("Connecting to Losant...");

  device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);

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

```

The first step is to log the underlying MQTT client’s state to try to see why the board is not reaching Losant. Add a print to the connect loop:

```auto
while(!device.connected()) {
    delay(500);
    Serial.println(device.mqttClient.state()); // HERE
    Serial.print(".");
}

```

This will log a number we can use for debugging.

The second step is detailed further in [this forum post](https://forums.losant.com/t/solved-mkr1000-hangs-on-trying-to-connect-to-losant/1242/5) (the device in this post is different, but the steps are similar for debugging). The change here is to try connecting without SSL to see if that eliminates the issue. There’s only two changes that need to be made:

1. Change `WiFiSSLClient` to `WiFiClient`
2. Change `device.connectSecure(...)` to `device.connect(...)`

Also be sure to check that you have increased the underlying MQTT library’s memory limit, as detailed in this [blog article](https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor):

> The [PubSubClinet MQTT library](https://github.com/knolleary/pubsubclient) has a default memory limit that is not enough to support all the values that the DHT22 sensor can collect. The error is also not apparent, which makes it hard to track. To increase the memory limit, please check out this [forum post](https://forums.losant.com/t/sending-commands-with-larger-payloads/135?source_topic_id=446&source_topic_id=446).

Hopefully this helps,  
Julia

---

_[View the full topic](https://forums.losant.com/t/my-dht22-fails-to-connect-to-losant-despite-authorized/1655)._
