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.
Locked
User avatar
_phillip
 
Posts: 313
Joined: Fri Apr 09, 2021 3:28 pm

Incorrect Block Data Being Published

Post by _phillip »

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 437 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

//  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

  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!

User avatar
millercommamatt
 
Posts: 828
Joined: Tue Jul 31, 2018 4:57 pm

Re: Incorrect Block Data Being Published

Post by millercommamatt »

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

User avatar
_phillip
 
Posts: 313
Joined: Fri Apr 09, 2021 3:28 pm

Re: Incorrect Block Data Being Published

Post by _phillip »

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

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

  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

User avatar
millercommamatt
 
Posts: 828
Joined: Tue Jul 31, 2018 4:57 pm

Re: Incorrect Block Data Being Published

Post by millercommamatt »

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

User avatar
_phillip
 
Posts: 313
Joined: Fri Apr 09, 2021 3:28 pm

Re: Incorrect Block Data Being Published

Post by _phillip »

Thank you for getting back to me.

I did a you instructed, but got the same error:

Code: Select all

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

  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.

User avatar
_phillip
 
Posts: 313
Joined: Fri Apr 09, 2021 3:28 pm

Re: Incorrect Block Data Being Published

Post by _phillip »

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

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.

User avatar
_phillip
 
Posts: 313
Joined: Fri Apr 09, 2021 3:28 pm

Re: Incorrect Block Data Being Published

Post by _phillip »

@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.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”