Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
0

(event.temp) = (event.humidity) problem
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

(event.temp) = (event.humidity) problem

by _phillip on Tue May 11, 2021 11:30 am

I have been trying to publish temperature and humidity data to my dashboard. Last evening I succeeded in publishing the humidity values, but the same data appears in the temperature feed.

In addition, the data printed to the serial monitor is incorrect. The following code:
Code: Select all | TOGGLE FULL SIZE
  Serial.print(F("\n Temperature value is "));
  Serial.print(event.temperature);
  Serial.print("...\n");

  Serial.print(F("\n\t\t Humidity VALUE??? is "));
  //Serial.print(event.relative_humidity); // orig code .......
  Serial.print(event.temperature);
  Serial.print("...\n");

only prints humidity data not (event.temperature) data. I deliberately used (event.temperature) twice to verify that only (event.relative_humidity) values were being printed.

Here is a grab of the serial monitor output and my dashboard feeds:

serial-dashboard-data.png
serial-dashboard-data.png (296.28 KiB) Viewed 265 times


The above shows that the temperature is (approx) 22 ºC and the humidity is (approx) 26%, yet the serial data reflects only humidity values as do both feeds.

Here is how my feeds are configured:

mqtt-test feeds.png
mqtt-test feeds.png (28.23 KiB) Viewed 265 times


Here is my sketch code:

sketch-feed-io-configuration.png
sketch-feed-io-configuration.png (42.76 KiB) Viewed 265 times


Any suggestions in how to unravel this will be greatly appreciated.

Thank you!

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by blnkjns on Thu May 13, 2021 12:16 am

Can you give the complete code? Please use code-tags on the actual code, not an image.

blnkjns
 
Posts: 624
Joined: Fri Oct 02, 2020 3:33 am

Re: (event.temp) = (event.humidity) problem

by _phillip on Thu May 13, 2021 12:37 am

blnkjns wrote:Can you give the complete code? Please use code-tags on the actual code, not an image.


I am SO glad to get some help with this because I have tried to solve this for several days and still the problem persists. This evening I deleted all of my feeds, group, dashboard and recreated them. Nothing makes any sense. If I grip the DHT22 sensor with my fingers, the humidity value increases. Anyway, here is the entire sketch:
Code: Select all | TOGGLE FULL SIZE
/*
 *
 *    FEATHER MO WIFI board sketch
 *   
 *   
 * 11 MAY 2021    FEATHER BOARD  NEEDS WIFI TO WORK   **********
 *
 * ******* >>>   NOTE!  using Feather MO Wifi BOARD   **********
 *
 *  This sketch is a copy of the following sketch:
 *      NEW-mqtt-winc1500-11may21-V08
 *
 *  Note that this sketch has never run the ultrasonic sensor so
 *  will need to update the libraries and hardware code.
 * 
 *  Note will be copying sensor code from the following sketch -
 *      talavera-working-v04-6may2021
 *     
 *  to add to this sketch to make the ultrasonic sensor work.
 * 
 *  12 MAY 21 @ 1753H
 *  I have learned how to throttle back the temp/humidity sensor, but
 *  not the ultrasonic sensor.  May have to save the ultrasoni sensor
 *  data in an array and publish it when we want to.  will see.
 * 
 * 
 *
 */

 #include <Adafruit_SSD1306.h>  // required for ultrasonic sensor
#include <splash.h>             // this was added automatically with the above lib???
#include <SPI.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <WiFi101.h>

#include "DHT.h"; // this required for the temp/humid sensor ...........NO problem!!
#include <DHT_U.h>  // NEW 9MAY21 .............
#include <Adafruit_Sensor.h>  // 9MAY21 Just installed this lib per DWShop video!!

#define DHTPIN 11  // this is output pin of sensor Changed from pin#11
#define DHTTYPE DHT22 

DHT_Unified dht(DHTPIN, DHTTYPE);  // Initialize the sensor just added '_Unified'

uint32_t delayMS; // Used to delay the DHT22 temp/humidity sensor

float hum;
float temp;


//************************* WiFI Setup **************************************
#define WINC_CS   8
#define WINC_IRQ  7
#define WINC_RST  4
#define WINC_EN   2     // or, tie EN to VCC


// ***********************  MY CREDS  ****************************************

char ssid[] = "CenturyLink3132";     //  your network SSID (name)
char pass[] = "a7h78dc8eh4ycc";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;                // your network key Index number (needed only for WEP)



//  *********************  TALAVERA CREDS  ***********************************

//char ssid[] = "WT1";     //  your network SSID (name)
//char pass[] = "Talavera1";    // your network password (use for WPA, or use as key for WEP)
//int keyIndex = 0;                // your network key Index number (needed only for WEP)


int status = WL_IDLE_STATUS;

//  ************************* Adafruit.io Setup *********************************

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "_phillip"
#define AIO_KEY         "aio_bqmF81UmWJqErdIcT3StKZ8kzvJA"


//  ************ Global State Setup  ******************************************

//Set up the wifi client
WiFiClient client;

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

// You don't need to change anything below this line!
#define halt(s) { Serial.println(F( s )); while(1);  }


/****************************** Feeds ***************************************/

// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
//Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");

//  Publish temp creds ............
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mqtt-test.temperature");

//  Publish humidty data creds  ............
Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mqtt-test.humidity");

//  Publish tank level data creds  ............
Adafruit_MQTT_Publish distance = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mqtt-test.distance");

// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");
//  Note.  I do not think I need the above line but data rate is too high, got warning from AIO!!!!
//  Adding this line eliminated a compile error.  21MAY21 @ 1312H

#define LEDPIN 13


// Print humidity and temperature function Keep this or not ???? ....................
//
/*
void hum_temp_sensor(float hum, float temp)
{
    Serial.print("Humidity: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.println(" Celsius");
   
    //  Degrees celsius to fahrenheit
    //  The following is my code
    float temp_F = (temp * 1.8) + 32;  // where 9/5 = 1.8
   
    Serial.print("\t\t\tTemp: ");
    Serial.print(temp_F);
    Serial.println(" Fahrenheit");
}
*/


void setup() {

  while (!Serial);  // Do not start until the serial monitor is open
 
  Serial.begin(115200);

  dht.begin();  // Activate the DHT22 sensor.
 
  // Print temperature sensor component details.  Not necessary!
  sensor_t sensor;
 
  dht.temperature().getSensor(&sensor);   //  NEW ...
   Serial.println(F("------------------------------------"));
  Serial.println(F("Temperature Sensor"));
  Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
  Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
  Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
  Serial.println(F("------------------------------------"));
 
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  Serial.println(F("Humidity Sensor"));
  Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("%"));
  Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("%"));
  Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("%"));
  Serial.println(F("------------------------------------"));
 
  delayMS = sensor.min_delay / 500; // Was 1000 ...
 
  WiFi.setPins(WINC_CS, WINC_IRQ, WINC_RST, WINC_EN);

  Serial.println(F("Adafruit MQTT demo for WINC1500"));

  // Initialise the Client
  Serial.print(F("\nInit the WiFi module..."));
  // check for the presence of the breakout
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WINC1500 not present");
    // don't continue:
    while (true);
  }
  Serial.println("ATWINC OK!");
 
  pinMode(LEDPIN, OUTPUT);
//  mqtt.subscribe(&onoffbutton);
}



void loop() // ==============================   LOOP()  ==============================
{
  delay(delayMS); // NEW ......................

  sensors_event_t event;
 
  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.
  MQTT_connect();

  // this is our 'wait for incoming subscription packets' busy subloop
  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000))) {
    if (subscription == &onoffbutton) {
      Serial.print(F("Got: "));
      Serial.println((char *)onoffbutton.lastread);

      if (0 == strcmp((char *)onoffbutton.lastread, "OFF")) {
        digitalWrite(LEDPIN, LOW);
      }
      if (0 == strcmp((char *)onoffbutton.lastread, "ON")) {
        digitalWrite(LEDPIN, HIGH);
      }
    }
  }


  // Print temp and humiidity data to serial monitor ...
  //  Following code does NOT WORK!!!!!!!!!!!!

 // Do not need the following code .................
 /*
  Serial.print(F("\n Temperature value is "));
  Serial.print(event.temperature);
  Serial.print("...\n");

  Serial.print(F("\n\t\t Humidity VALUE??? is "));
  //Serial.print(event.relative_humidity); // orig code .......

  Serial.print(event.temperature);
  Serial.print("...\n");
*/
 
  // Get TEMPERATURE event and print its value ...................
  dht.temperature().getEvent(&event);
 
  if (isnan(event.temperature)) {
    Serial.println(F("Error reading temperature!"));
  }
  else {
    Serial.print(F("TEMPERATURE: "));
    Serial.print(event.temperature);
    Serial.println(F("°C"));
  }

 
  // Get HUMIDITY event and print its value ......................
  dht.humidity().getEvent(&event);
 
  if (isnan(event.relative_humidity)) {
    Serial.println(F("Error reading humidity!"));
  }
  else {
    Serial.print(F("\t\tHUMIDITY: "));
    Serial.print(event.relative_humidity);
    Serial.println(F("%"));
  }



 
  // ====== end of getEvent()  ====================================

 

    // PUBLISH TEMPERATURE data ......................  PUBLISH ...
 
  if (!temperature.publish(event.temperature)) {
    Serial.println(F("Failed"));
  } else {
    Serial.println(F("Published Temperature.  OK!\n"));
  }

  // PUBLISH HUMIDIITY data ...

  if (!humidity.publish(event.relative_humidity) ) {
    Serial.println(F("Failed"));
  } else {
    Serial.println(F("\tPublished Humidity.  OK!\n"));
  }


/*
  // PUBLISH DISTANCE data ...
  if (!distance.publish(event.distance) ) {
    Serial.println(F("Failed"));
  } else {
    Serial.println(F("\tPublished Distance.  OK!\n"));
  }
*/
  // =======  END OF NEW UNIFIED_SENSOR CODE ====================


}

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // attempt to connect to Wifi network:
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    uint8_t timeout = 10;
    while (timeout && (WiFi.status() != WL_CONNECTED)) {
      timeout--;
      delay(1000);
    }
  }
 
  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
  }
  Serial.println("MQTT Connected!\n");
}


Here is a grab of the serial monitor's output after I had my fingers on the sensor. The humidity value went up and not the temp.
hum-temp-data-grab.png
hum-temp-data-grab.png (247.11 KiB) Viewed 255 times

In addition, the temperature feed never has worked, only the humidity feed works. I have deleted and replaced them several times and nothing seems to help.

I will remain awake in case you have any more questions. Thank you so much for your help.

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Thu May 13, 2021 12:38 am

Perhaps my DHT22 sensor is bad? I have another that I can try. Will do that.

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Thu May 13, 2021 12:43 am

Here's a grab I just took.
current-grab.png
current-grab.png (347.46 KiB) Viewed 255 times

You can see that both feeds reflect humidity values. The temp values are ignored.

Thanks for your help.

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Thu May 13, 2021 1:01 am

Here's a grab I just took with a different DHT22 sensor. Same result!
grab-02.png
grab-02.png (289.46 KiB) Viewed 254 times

I had my fingers on the sensor and the humidity value increased just as it did with the original DHT22 sensor.

Thanks!

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Thu May 13, 2021 1:45 am

I just ran the DHT_Unified_Sensor-adafruit sketch and when I put my fingers around the DHT22 sensor, the humidity values INCREASED! So from this info, it is the sensor that is causing the problem. But this makes NO sense at all to me.

Wiring is -

Sensor pin #1 = Vcc,
#2 = Feather pin #11 (data output)
#3 = N/C
#4 = GRND

It's about 2400 here, so I will return tomorrow morning.
Thanks for your help.

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Thu May 13, 2021 11:39 am

Because placing my fingers over the DHT22 sensor and seeing the humidity value rise and not the temperature made no sense to me, I decided to heat the DHT22 with a heat gun.

Bottom line - the temp values rose and the humidity values fell. This makes sense, so placing fingers over the sensor expecting the temp to rise is not a valid test at all. Lesson learned.

So my original issue remains: Why am I not able to publish the humidity and temperature data correctly. Both of my feeds reflect the humidity value and not the temperature.

Here is a grab of the heat gun test:

heat-gun-test-results.png
heat-gun-test-results.png (368.07 KiB) Viewed 244 times


Thanks in advance for any help anyone can provide.

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Thu May 13, 2021 1:20 pm

I have once again, deleted the AIO dashboard, group, feeds and replaced them. If I publish only temperature data it will be reflected in the temp feed. If I publish both temp and humidity data, humidity data will appear in both temp and humidity blocks.

I have no idea what else to try.

Any help would be much appreciated.

Thanks!

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Fri May 14, 2021 10:25 am

In a nutshell, this is my publishing issue using a DHT22 humidity / temperature sensor and a Feather MO WIFI board:

If I publish only the temp data to an AIO dashboard block entitled 'Temperature', all goes well.

If add another feed to the dashboard entitled 'Humidity' and publish both temp and humidity data, the humidity data appears in both dashboard blocks.

I have deleted and replaced all groups, dashboards, feeds, etc., and nothing changes.

I just received an Adafruit HUZZAH32-ESP32 board yesterday and am willing to try that board, but I fail to understand how the board is causing this problem.

ANY help will be greatly appreciated.

Thank you!

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by brubell on Fri May 14, 2021 10:34 am

Hi Phillip, could you please open io.adafruit.com/monitor and run your sketch.

Paste the output here (or a screenshot!)

It'll help me diagnose if the data is on IO's end.

brubell
 
Posts: 1381
Joined: Fri Jul 17, 2015 10:33 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Fri May 14, 2021 10:47 am

Got it!!! I am experiencing wifi login issues so will have to solve this before I can do ask you asked.

Thank you!

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Fri May 14, 2021 10:53 am

OK! Back in business. Here is the latest grab:

data-output.png
data-output.png (350.24 KiB) Viewed 223 times


I'm still on-line.

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by _phillip on Fri May 14, 2021 1:52 pm

I logged out of the AIO at 1137H. Was not certain if you wanted me to stay connected.

Thanks!

_phillip
 
Posts: 117
Joined: Fri Apr 09, 2021 3:28 pm

Re: (event.temp) = (event.humidity) problem

by brubell on Mon May 17, 2021 9:35 am

I meant a screenshot of the io.adafruit.com/monitor page.

brubell
 
Posts: 1381
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.