0

Incorrect Block Data Being Published
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.

Incorrect Block Data Being Published

by _phillip on Mon May 10, 2021 10:41 am

I am trying to show temp and humidity test data on two AIO Blocks, but all I see are the counter values seen next.

block-data.png
block-data.png (86.5 KiB) Viewed 217 times


The correct data prints out correctly in the serial monitor, but not in the IO Blocks. Here is the pertinent code of my sketch:

Code: Select all | TOGGLE FULL SIZE
//  NEW!!  try to publish temp data ............
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mqtt-test.temperature");

//  NEW!!  try to publish humidty data ............
Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mqtt-test.humidity");


And the Loop() code:

Code: Select all | TOGGLE FULL SIZE
  Serial.print(F("\nSending sendor data "));
  Serial.print(x);
  Serial.print("...");

  //  ======  BEGING PUBLISHING DATA  =====================
  if (! temperature.publish(x++)) {  // Publish temp data ...

    Serial.println(F("Failed"));
  } else {
    Serial.println(F("OK!"));
  }

  if (! humidity.publish(x++)) {  // Publish humidity data ...

    Serial.println(F("Failed"));
  } else {
    Serial.println(F("OK!"));
  }
  //  =======   END OF PUBLISH CODE  =======================

  //  Following is all new unified_dht code ..............
  // Get temperature event and print its value.
  sensors_event_t event;
  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("Humidity: "));
    Serial.print(event.relative_humidity);
    Serial.println(F("%"));
  }


Any help will be much appreciated.
Thanks!

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

Re: Incorrect Block Data Being Published

by millercommamatt on Mon May 10, 2021 11:04 am

you're publishing x not event.temperature and event.humidity

millercommamatt
 
Posts: 649
Joined: Tue Jul 31, 2018 4:57 pm

Re: Incorrect Block Data Being Published

by _phillip on Mon May 10, 2021 3:41 pm

millercommamatt wrote:you're publishing x not event.temperature and event.humidity


Thanks for your help, but my changes created another error as follows:

Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.13 (Mac OS X), Board: "Adafruit Feather M0, Small (-Os) (standard), Arduino, Off"

/Users/PhillipBriles/Documents/Arduino/NEW-mqtt_winc1500-10may2021-V05/NEW-mqtt_winc1500-10may2021-V05.ino: In function 'void loop()':
NEW-mqtt_winc1500-10may2021-V05:211:26: error: 'struct sensors_event_t' has no member named 'humidity'
  211 |   float humidity = event.humidity;
      |                          ^~~~~~~~
NEW-mqtt_winc1500-10may2021-V05:248:21: error: request for member 'publish' in 'temperature', which is of non-class type 'float'
  248 |   if (! temperature.publish(event.temperature++)) {  // Publish temp data ...removed ++
      |                     ^~~~~~~
NEW-mqtt_winc1500-10may2021-V05:255:18: error: request for member 'publish' in 'humidity', which is of non-class type 'float'
  255 |   if (! humidity.publish(event.humidity++)) {  // Publish humidity data ... was (x++) .....
      |                  ^~~~~~~
NEW-mqtt_winc1500-10may2021-V05:255:32: error: 'struct sensors_event_t' has no member named 'humidity'
  255 |   if (! humidity.publish(event.humidity++)) {  // Publish humidity data ... was (x++) .....
      |                                ^~~~~~~~
exit status 1
'struct sensors_event_t' has no member named 'humidity'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


And here is my code change:
Code: Select all | TOGGLE FULL SIZE
  Serial.print(F("\nSending sendor data "));
  Serial.print(event.temperature);  //  ...
  Serial.print("...");

  if (! temperature.publish(event.temperature++)) { 

    Serial.println(F("Failed"));
  } else {
    Serial.println(F("OK!"));
  }

  if (! humidity.publish(event.humidity++)) {

The error was on the last line.
Thanks for your help

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

Re: Incorrect Block Data Being Published

by millercommamatt on Mon May 10, 2021 6:30 pm

I the C language, ++ increments a integer up by one. Remove it from your code where you have the publish statements.

millercommamatt
 
Posts: 649
Joined: Tue Jul 31, 2018 4:57 pm

Re: Incorrect Block Data Being Published

by _phillip on Mon May 10, 2021 6:37 pm

Thank you for getting back to me.

I did a you instructed, but got the same error:
Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.13 (Mac OS X), Board: "Adafruit Feather M0, Small (-Os) (standard), Arduino, Off"

/Users/PhillipBriles/Documents/Arduino/NEW-mqtt_winc1500-10may2021-V05/NEW-mqtt_winc1500-10may2021-V05.ino: In function 'void loop()':
NEW-mqtt_winc1500-10may2021-V05:250:26: error: 'struct sensors_event_t' has no member named 'humidity'
  250 |   float humidity = event.humidity;
      |                          ^~~~~~~~
NEW-mqtt_winc1500-10may2021-V05:284:21: error: request for member 'publish' in 'temperature', which is of non-class type 'float'
  284 |   if (! temperature.publish(event.temperature)) {  // Publish temp data ...removed ++
      |                     ^~~~~~~
NEW-mqtt_winc1500-10may2021-V05:291:18: error: request for member 'publish' in 'humidity', which is of non-class type 'float'
  291 |   if (! humidity.publish(event.humidity)) {  // Publish humidity data ... was (x++) .....
      |                  ^~~~~~~
NEW-mqtt_winc1500-10may2021-V05:291:32: error: 'struct sensors_event_t' has no member named 'humidity'
  291 |   if (! humidity.publish(event.humidity)) {  // Publish humidity data ... was (x++) .....
      |                                ^~~~~~~~
exit status 1
'struct sensors_event_t' has no member named 'humidity'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


and here is my code:
Code: Select all | TOGGLE FULL SIZE
  Serial.print(F("\nSending sendor data "));
  //Serial.print(x);  // orig code ...
  Serial.print(event.temperature);
  Serial.print("...");

  //  ======  BEGING PUBLISHING DATA  =====================
  if (! temperature.publish(event.temperature)) {  // Publish temp data ...removed ++

    Serial.println(F("Failed"));
  } else {
    Serial.println(F("OK!"));
  }

  if (! humidity.publish(event.humidity)) {  // Publish humidity data ... was (x++) .....

    Serial.println(F("Failed"));
  } else {
    Serial.println(F("OK!"));
  }
  //  =======   END OF PUBLISH CODE  =======================

  //  Following is all new unified_dht code ..............
  // Get temperature event and print its value.
//  sensors_event_t event;
 
  //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("Humidity: "));
    Serial.print(event.relative_humidity);
    Serial.println(F("%"));
  }
  // =======  END OF NEW UNIFIED_SENSOR CODE ====================


Thanks again.

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

Re: Incorrect Block Data Being Published

by _phillip on Mon May 10, 2021 6:53 pm

I'm looking at the Adafruit sensor_event_t Struct Reference and from what I can make of it, there is not any reference to 'humidity'. But I must use 'relative_humidity'. Here is the link:

http://adafruit.github.io/Adafruit_Circ ... nt__t.html

How the heck was I supposed to know that? LOL!!!!

However, now the compile error I got was:
Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.13 (Mac OS X), Board: "Adafruit Feather M0, Small (-Os) (standard), Arduino, Off"

/Users/PhillipBriles/Documents/Arduino/NEW-mqtt_winc1500-10may2021-V05/NEW-mqtt_winc1500-10may2021-V05.ino: In function 'void loop()':
NEW-mqtt_winc1500-10may2021-V05:284:21: error: request for member 'publish' in 'temperature', which is of non-class type 'float'
  284 |   if (! temperature.publish(event.temperature)) {  // Publish temp data ...removed ++
      |                     ^~~~~~~
NEW-mqtt_winc1500-10may2021-V05:291:18: error: request for member 'publish' in 'humidity', which is of non-class type 'float'
  291 |   if (! humidity.publish(event.relative_humidity)) {  // Publish humidity data ... was (x++) .....
      |                  ^~~~~~~
exit status 1
request for member 'publish' in 'temperature', which is of non-class type 'float'


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The class reference refers to temperature as a float, which is what I have, so I do not understand the error.

Thanks again for your help.

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

Re: Incorrect Block Data Being Published

by _phillip on Tue May 11, 2021 8:50 am

@millercommamat

Thank you for pointing me in the correct direction yesterday. Late last evening I was able to publish one of my data values to my dashboard. I now have a new publishing issue, but will begin a new thread so its solution will not get buried in this thread.

I sincerely appreciate all of your help.

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

Please be positive and constructive with your questions and comments.