Variables are not displayed at the IOT Cloud dashboard

I have similar problem as noahwaldron1235,
but I am using LCD to display measured temperature and humidity locally.
In my case the local variables are same as the ones declared in cloud properties .
The program attached

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/74c4ce8c-6b60-4af2-bcdd-1f4c7877486b 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float humi;
  float temp;
  bool bramaUp;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include "DHT.h"

 #define TFT_CS        10
  #define TFT_RST        8 
  #define TFT_DC         7
#define TFT_MOSI 11  // Data out
#define TFT_SCLK 13  // Clock out
#define DHTPIN 2    // wejscie czujnika DHT22
#define REL1 3

#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
DHT dht(DHTPIN, DHTTYPE);

unsigned long previousMillis = 0;
const long interval = 2000; //milliseconds

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();
   dht.begin();
   tft.init(172, 320);           // Init ST7789 172x320

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
 
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
   
  float humi = dht.readHumidity();
  float temp = dht.readTemperature();
  onBramaUpChange();
  
  
 
 /*
  float f = dht.readTemperature(true);
  
// Check if any reads failed and exit early (to try again).
  if (isnan(humi) || isnan(temp) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
    }
    */
  
  tft.fillScreen(ST77XX_BLACK);
  tft.setRotation(1);  //. moje
  tft.setCursor(10, 30);
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(7);
  tft.println(humi);
  Serial.println (humi);
  tft.setCursor(0, 110);
  tft.setTextSize(4);
  tft.println( "Wilgotnosc");
  delay(1500);
  
tft.fillScreen(ST77XX_BLACK);
  tft.setRotation(1);//. moje
  tft.setCursor(10, 30);
  tft.setTextColor(ST77XX_ORANGE);
  tft.setTextSize(7);
  tft.println(temp);
    Serial.println(temp);
  tft.setCursor(0, 110);
  tft.setTextSize(4);
  tft.println( "Temperature");
    
   delay(1500);   
} 

 void onBramaUpChange()  {
  // Add your code here to act upon BramaUp change
  unsigned long currentMillis = millis();
  bool bramaUp;

  if (currentMillis - previousMillis >= interval) 
  {
    previousMillis = currentMillis;
    
    if (bramaUp == LOW) {
      bramaUp = HIGH;
    } else {
      bramaUp = LOW;
    }
    digitalWrite(REL1, bramaUp);
    delay(500);
  }
}

And thingProperties .h :

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

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

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)

void onBramaUpChange();

float humi;
float temp;
bool bramaUp;

void initProperties(){

  ArduinoCloud.addProperty(humi, READ, 3 * SECONDS, NULL);
  ArduinoCloud.addProperty(temp, READ, 3 * SECONDS, NULL);
  ArduinoCloud.addProperty(bramaUp, READWRITE, ON_CHANGE, onBramaUpChange);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Please help.

That is correct (Thing variables not indicating on Dashboard).

The Cloud Variables are declared in thingProperties.h here:

But then in the loop function of your .ino file you declare a set of local variables with the same names:

Even though they have the same names, they are completely different variables. So when you set the value of these local variables, it has no effect on your Cloud Variables.

This is known as "variable shadowing", and is the source of many a confusing bug.

The solution is to simply use the global variables instead of declaring "shadow" local variables. So change these declarations in your .ino file:

  float humi = dht.readHumidity();
  float temp = dht.readTemperature();

to this:

  humi = dht.readHumidity();
  temp = dht.readTemperature();

You have the same "variable shadowing" bug with the bramaUp Cloud Variable in your onBramaUpChange function:

You should delete that line from your .ino file.

Hello ptillish.
Thank you very much.
At the end I understand the problem.
Solution implemented and is ok.
So we can close the topic.
Once again - thank you
Stan

You are welcome. I'm glad it is working now.

Regards,
Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.