Why does the Value on the dashboard show 0?

I have an Arduino UNO R4 WiFi connected to the cloud.
I have created a variable for CO2 concentration in the “ThingProperties.h” tab, when I Serial.print the variable to the monitor, the resulting value is displayed exactly on the monitor.
However, in the Arduino Cloud dashboard, the value of Value keeps updating with 0.
Why does it keep showing up as 0?

The Sketch code is below.

①~~.ino

#include "thingProperties.h"
#include <Wire.h>
#include "SparkFun_ENS160.h"

SparkFun_ENS160 myENS; 
int ensStatus; 

void setup() {
  // シリアル通信開始
  Serial.begin(9600);
  delay(1500);

  // thingProperties.h で定義されたプロパティを初期化
  initProperties();

  // Arduino IoT Cloud に接続
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  // デバッグ情報
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

  // ENS160 センサーの初期化
  Wire.begin();

  if( !myENS.begin() ) {
    Serial.println("Could not communicate with the ENS160, check wiring.");
    while(1);
  }

  // センサーのリセット
  if( myENS.setOperatingMode(SFE_ENS160_RESET) )
    Serial.println("Ready.");

  delay(100);

  // 標準動作モードに設定
  myENS.setOperatingMode(SFE_ENS160_STANDARD);
}

void loop() {
  // Arduino IoT Cloud の更新
  ArduinoCloud.update();

  // ENS160 のデータ取得
  if( myENS.checkDataStatus() ) {
    Serial.println((float)myENS.getECO2(), 2); // float型の数値のみ表示 (小数点以下2桁)
  }

  delay(1000);
}

②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)


float co2censor02;

void initProperties(){

  ArduinoCloud.addProperty(co2censor02, READ, 1 * SECONDS, NULL);


}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Does anyone have any ideas on this?
Best regards.
NOBU

Hi @03_nobu. The dashboard shows the value of the Arduino Cloud IoT Variable.

You created a Variable named co2censor02 for your Thing. The dashboard will show the value of that variable. Your sketch code never sets the value of the variable, so it is expected that the dashboard will only show the default variable value of 0.

If you want the dashboard to show the value from the CO2 sensor, then you need to set the co2censor02 variable to that value in your Thing sketch code:

co2censor02 = myENS.getECO2();

You aren't printing the variable. You are printing the value returned by the SparkFun_ENS160 library:

If you actually print the variable then you will see the same value in Serial Monitor as in the dashboard:

Serial.println(co2censor02)

Thank you for your advice!

I fixed the code and it solved the problem.

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.