[CLOSED]Arduino Cloud Int Variables turn into 0

Hello, i have a project called "Smart Home model". And I need to know the answer as soon as possible, because I would need to show my project next week. So, the problem is that when the temperature sensor in my model sends data, and esp8266 sends it, arduino cloud just turns it into 0. I don't know why, but it just shows me nothing. Here's the code:

//    This code is made by Javdat Khudanov, and Arduino Cloud
//  *******************************************************************
//  *******/-----\ |-----\ | /----\ | |\    |     /\     |      *******
//  *******|     | |     | | |    | | | \   |    /  \    |      *******
//  *******|     | |-----/ | |  __  | |  \  |   /____\   |      *******
//  *******|     | |     \ | |    | | |   \ |  /      \  |      *******
//  *******\-----/ |     | | \----/ | |    \| /        \ |______*******
//  *******************************************************************


#include "thingProperties.h"
#include <FastLED.h>
#include <SPI.h>
#include <MFRC522.h>
#include "timer.cpp"

#define NUM_LEDS 50 // Number of LEDS on an LED strip
#define LED_PIN D1 // Pin, where LED strip is connected

#define SS_PIN 15 // SDA pin of RFID
#define RST_PIN 2 // RST pin of RFID

#define PIR D2 // Define the PIR sensor's pin

#define buzzer D3

// Define variables for lights
int bri = lights.getBrightness();
int hue = lights.getHue();
int sat = lights.getSaturation();
int val = lights.getSwitch();

bool isOnce = false;
bool isOnce2 = false;

bool sentryMode = false;

// Define string variables for the RFID reader
String ID;
String UID = "D7 E6 CB B4"; // ID of the card

// Define RGB leds
CRGB leds[NUM_LEDS];

// Define the RFID reader
MFRC522 rfid(SS_PIN, RST_PIN);

Timer timer;
unsigned long timenow;

void setup() {
  // Initialize serial and wait for port to open
  pinMode(PIR,INPUT);
  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();

  SPI.begin(); // Initialize SPI
  rfid.PCD_Init(); // Initialize RC522

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  FastLED.addLeds<NEOPIXEL,LED_PIN>(leds, NUM_LEDS); // Initialize LED strip
  pinMode(buzzer,OUTPUT);
  timer.start();
}

void loop() {
  ArduinoCloud.update();

  program();
  checkForTemp();
  checkRFID();
  checkAway();
  sentryModee();
  ArduinoCloud.update();
}


void checkAway() {
  if (away == true) {
    if (!isOnce2) { // Чтобы таймер начинал работу только один раз при активации
      timenow = millis(); // Запоминаем текущее время
      isOnce2 = true;
    }

    // Проверяем, прошло ли время, указанное в awayTimer
    if (millis() - timenow >= awayTimer*60000) {
      sentryMode = true;
      isOnce2 = false; // Сбрасываем флаг для следующего использования
    }
  } else {
    isOnce2 = false; // Сбрасываем флаг, если режим away отключен
  }
}

void sentryModee() {
  if (sentryMode == true) {
    if (motion == true) {
      unsigned long motionStart = millis(); // Начало таймера для blinking режима

      while (millis() - motionStart < 60000) { // Таймер на минуту
        // Моргаем лампочками
        fill_solid(leds, NUM_LEDS, CRGB::Red);
        FastLED.show();
        delay(2000); // Зажгли на 1 секунду
        fill_solid(leds, NUM_LEDS, CRGB::Black);
        FastLED.show();
        delay(2000); // Потушили на 1 секунду
        ArduinoCloud.update();

        // Проверяем, если away выключен, то сбрасываем sentryMode
        if (away == false) {
          sentryMode = false;
          return; // Выход из функции, если условие выполнено
        }
      }
      ArduinoCloud.update();
      // Если таймер на минуту истек, но away всё ещё true, включаем alarm
      if (away == true) {
        while (away == true) {
          alarm();
          ArduinoCloud.update();
        }
      } else {
        sentryMode = false; // Если away == false, выключаем sentryMode
      }
    }
  }
}

void alarm()
{
  tone(buzzer,7000,300);
  delay(500);
  tone(buzzer,7000,300);
  delay(500);
  tone(buzzer,7000,300);
  delay(1500);
}

void checkRFID()
{
  static uint32_t rfidRebootTimer = millis();
  static uint32_t timeout = millis();
  
  if (millis() - rfidRebootTimer > 200) {
    if(ID!=UID and lights.getSwitch()==true)
    {
      isOnce=false;
      lights.setSwitch(false);
      val=false;
    }     
    rfidRebootTimer = millis();               // Update the Timer
    digitalWrite(RST_PIN, HIGH);              // Reset the module
    delayMicroseconds(100);
    digitalWrite(RST_PIN, LOW);
    rfid.PCD_Init();                          // Initialize RC522 again
  }
  
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if ( ! rfid.PICC_ReadCardSerial())
    return;
  ID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
    ID.concat(String(rfid.uid.uidByte[i], HEX));
  }
  ID.toUpperCase();
  
  if(ID.substring(1) == UID && isOnce==false)
  {
    lights.setSwitch(true);
    val=true;
    isOnce=true;
  }
}

void checkForTemp()
{
  
  if(Serial.available())
  {
    Serial.println(temperature);
    Serial.println(Serial.parseInt());
    temperature = Serial.parseInt();
    Serial.println("sent");
    
  }
}
void program()
{
  if(digitalRead(PIR)==1)
  {
    motion=true;
  }
  else
  {
    motion=false;
  }
  if(hue>=0 and hue<=23 and val==true)
  {
    showColor("Red");
  }
  else if(hue>=115 and hue<=151 and val==true)
  {
    showColor("Green");
  }
  else if(val==false)
  {
    fill_solid( leds, NUM_LEDS, CRGB::Black);
    FastLED.show();
  }
  else
  {
    usualMode();
  }
}

void onLightsChange()
{
  bri = lights.getBrightness();
  hue = lights.getHue();
  sat = lights.getSaturation();
  val = lights.getSwitch();
}

void usualMode()
{
  fill_solid( leds, NUM_LEDS, CHSV(hue-70,sat,100));
  FastLED.setBrightness(bri);
  FastLED.show();
}

void showColor(String color)
{
  if(color=="Green")
  {
    fill_solid( leds, NUM_LEDS, CRGB::Green);
  FastLED.setBrightness(bri);
  FastLED.show();
  }
  else if(color=="Red")
  {
    fill_solid( leds, NUM_LEDS, CRGB::Red);
  FastLED.setBrightness(bri);
  FastLED.show();
  }
}
void onTemperatureChange(){}
void onAwayTimerChange(){}
void onAwayChange(){
}

and here's the thingProperties code:

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

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

const char DEVICE_LOGIN_NAME[]  = "261fd6b6-0a56-4b02-bdec-63a0f6ff6354";

const char SSID[]               = "BK_2_4";    // Network SSID (name)
const char PASS[]               = "killeradmin1983";    // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[]  = "qURB@lwowL7eGyWYa#r8ei3Iv";    // Secret device password

void onLightsChange();
void onAwayTimerChange();
void onTemperatureChange();
void onAwayChange();

CloudColoredLight lights;
CloudMotionSensor motion;
int awayTimer;
int temperature;
bool away;

void initProperties(){

  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.addProperty(lights, READWRITE, ON_CHANGE, onLightsChange);
  ArduinoCloud.addProperty(motion, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(awayTimer, READWRITE, ON_CHANGE, onAwayTimerChange);
  ArduinoCloud.addProperty(temperature, READWRITE, ON_CHANGE, onTemperatureChange);
  ArduinoCloud.addProperty(away, READWRITE, ON_CHANGE, onAwayChange);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

What can i do?

Here you are reading 2 times an integer from serial. Is that correct?
The temperature you are printing is not the one that you are assigning to the temperature variable.

Hello. You see, i wrote "Serial.println(Serial.parseInt()), because i have an arduino running in the background, which sends the temperature through RX TX pins. And temperature variable is the cloud variable.

Hello. I will mark this post as a solution and close this topic, because I don't need the solution anymore. Thanks

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