Variables always have zero value in dashboard

Continuing the discussion from Arduino could dashboard not shown temperature data:

I have a problem identical to this.
I have the ESP32 module on line on the cloud.
I created the three variables (Temperature, Pressure and humidity in my case) in the
"ThingProperties.h" tab,
I have code in the "// Your code here" that reads the three variables and then writes them to the Cloud variables.
I Serial.print the three cloud variables to the monitor and they are accurately displayed on the monitor.
I have deleted and re-created all three variables ,
first in the thingProperties.h
and then successfully compiled, then used the variables in the "Thing Code" however they steadfastly stick to zero on all three, even thou they correctly display on the serial monitor.

YEs, the thing and the device are both on line .

Does anybody have any ideas on this?
Cheers
TomG

thingProperties.h
// Code generated by Arduino IoT Cloud, DO NOT EDIT.

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char DEVICE_LOGIN_NAME[]  = "518ab34a-65ae-4e23-ad96-ff46bdf60955";

const char SSID[]               = SECRET_SSID;    // Network SSID (name)
const char PASS[]               = SECRET_OPTIONAL_PASS;    // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[]  = SECRET_DEVICE_KEY;    // Secret device password


float cloud_H3;
float cloud_P3;
float cloud_T3;

void initProperties(){

  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.addProperty(cloud_H3, READ, 10 * SECONDS, NULL);
  ArduinoCloud.addProperty(cloud_P3, READ, 10 * SECONDS, NULL);
  ArduinoCloud.addProperty(cloud_T3, READ, 10 * SECONDS, NULL);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

_________________________
The thing Code (first tab) is as follows

#include "thingProperties.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10


Adafruit_BME280 bme; // I2C

unsigned long delayTime;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(4);
  ArduinoCloud.printDebugInfo();
  unsigned status;
    status = bme.begin();  
    delayTime = 5000;
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
 delay(delayTime);
    float Cloud_T3 = bme.readTemperature();
    float Cloud_P3 = bme.readPressure();
    float Cloud_H3 = bme.readHumidity();
    /*Serial.print(25);
    Serial.print("\t");*/
    Serial.print(Cloud_T3);
    Serial.print("\t");
    Serial.print(Cloud_P3);
    Serial.print("\t");
    Serial.print(Cloud_H3);
    Serial.println("\t"); 
  
}

Hi @tom-grayson.

Here your code declares three Arduino Cloud Variables:

The variable names are cloud_H3, cloud_P3, and cloud_T3.

Here you declare three local variables:

The variable names are Cloud_H3, Cloud_P3, and Cloud_T3.

You never set the values of your Cloud Variables, but only the values of these local values. You then print the values of the local variables to Serial. Your sketch code never sets the value of the Cloud Variables so they always have their initialization values of 0. This is the reason why you see the expected values in Serial Monitor, but not in the dashboard.

The solution is to change your code so that you set the Cloud Variables instead of declaring local variables:

  cloud_T3 = bme.readTemperature();
  cloud_P3 = bme.readPressure();
  cloud_H3 = bme.readHumidity();
  /*Serial.print(25);
    Serial.print("\t");*/
  Serial.print(cloud_T3);
  Serial.print("\t");
  Serial.print(cloud_P3);
  Serial.print("\t");
  Serial.print(cloud_H3);
  Serial.println("\t");

ptillisch,
Thankyou for that.
Once the error was pointed out, it was easy to see. I guess a rookie mistake.
Again, Thankyou. a
Cheers
TomG

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per

That is not a proper cloud sketch. You need to set up a dashboard and link the displayed variables to the cloud variables. Also learn patience, cloud performance is slow.