My DHT22 Fails to connect to Losant despite Authorized

Hello @Ogbe_Isaac,

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

  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:

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 (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:

The PubSubClinet MQTT library 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.

Hopefully this helps,
Julia