Cloud Variables issue

Hi I would like to ask you for help with my Cloud variables issue. I have two projects with the same approach in how I am reading temperature from Dallas sensors and showing them as variables in the cloud. But it seems that it stops working and shows the only strange character as you can see in the picture.
I tested various variable types and the only string somehow works. I have a specific problem with INT and Boolean. It might be an format or variable type definition problem. But when I am specifiing Variable type in Particle.variable(“Teplota 1”, temp1, INT); I got error msg during compilation.

…/wiring/inc/spark_wiring_cloud.h:81:39: call of overloaded ‘_variable(const char [10], const int&, const CloudVariableTypeInt&)’ is ambiguous

Thank you for any help
Jaroslav

First you are using a deprecated syntax and that not correctly :wink:

The correct way to write the deprecated syntax would be

Particle.variable("Teplota1", &temp1, INT);

(no spaces in the variable name and an ampersand (address of operator) in front of the source variable)

However the better way to write it in a “modern” fashion would be

Particle.variable("Teplota1", temp1);

BTW, since we cannot see your variable definitions and how you use Particle.variable() in your code I’ll just mention for completeness:
The base variables must be global and Particle.variable() can only be called once per variable definition.

2 Likes

Thank you ScruffR,
I have test both syntax unfortunately with the same result. I am also attaching the code. This is basic pool management starting relay modules and reading temperatures. Functions and variables are initiated and ready by IFTTT.
Do you have any idea where the problem could be?
Thank you
Jaroslav

#include "DS18B20_Pi.h"
#include <iostream>
#include <string>



int led1 = D1;
int led2 = D2;
int led3 = D3;
int led4 = D4;
int led5 = D5;
int led6 = D6;
int led7 = D7;
int led8 = D8;





char w1_address[15]; //temp akumulacka string
char w2_address[15]; //temp boiler string
char w3_address[15]; //temp boiler string

bool bublinky = false; // vririvka
bool filtrace = false; //aktivita filtrace
bool svetlo = false; //bazenove svetlo

int temp1=0;
int temp2=0;
int temp3=0;



 
void setup() {


   
   
   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);
   pinMode(led3, OUTPUT);
   pinMode(led4, OUTPUT);
   pinMode(led5, OUTPUT); //čistící robot
   pinMode(led6, OUTPUT); //bublinky vířivka
   pinMode(led7, OUTPUT); //Led světlo bazénu
   pinMode(led8, OUTPUT); //filtrace





   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   digitalWrite(led5, HIGH);
   digitalWrite(led6, HIGH);
   digitalWrite(led7, HIGH);
   digitalWrite(led8, HIGH);



   Particle.function("8CH_rele",ledToggle);
   Particle.variable("Bublinky", bublinky);
   Particle.variable("Svetlo", svetlo);
   Particle.variable("Filtrace", filtrace);
   Particle.variable("Teplota1", temp1);
   Particle.variable("Teplota 2", temp2);
   Particle.variable("Teplota 3", temp3);
   Particle.variable("Test", "led8");

   

}



void loop() 


   {
   
    
   strcpy(w1_address, "28-00000d2f9d04"); //cteni teploty
   strcpy(w2_address, "28-00000c4223e5"); //cteni teploty
   strcpy(w3_address, "28-00000d2fbcad"); //cteni teploty
   
    
    DS18B20 w1Device (w1_address); // prevod typu promene z text na int
    temp1 = w1Device.getTemp(); // prevod typu promene z text na int
    
    DS18B20 w2Device (w2_address); // prevod typu promene z text na int
    temp2 = w2Device.getTemp();  // prevod typu promene z text na int
    
    DS18B20 w3Device (w3_address); // prevod typu promene z text na int
    temp3 = w3Device.getTemp();  // prevod typu promene z text na int
    

    

      }


int ledToggle(String command) {

    if (command=="D1") {
        digitalWrite(led1,LOW);
        delay(1000); 
        digitalWrite(led1,HIGH);
       
        return 1;
    }
    else if (command=="D2") {
        digitalWrite(led2,LOW);
        delay(1000); 
        digitalWrite(led2,HIGH);

        return 2;
    }
    else if (command=="D3") {
        digitalWrite(led3,LOW);
        delay(1000); 
        digitalWrite(led3,HIGH);

        return 3;
    }
    else if (command=="D4") {
         digitalWrite(led4,LOW);
        delay(1000); 
        digitalWrite(led4,HIGH);

        return 4;
    }
     // Robot
    else if (command=="D5") {
        digitalWrite(led5,LOW);
        delay(1000); 
        digitalWrite(led5,HIGH);

        return 5;
    }
        else if (command=="D55") {
        digitalWrite(led5,LOW);
        delay(1000); 
        digitalWrite(led5,HIGH);
        delay(3000); 
        digitalWrite(led5,LOW);
        delay(1000); 
        digitalWrite(led5,HIGH);

        return 5;
    }
      // bublinky
    else if (command=="D6") {
        digitalWrite(led6,LOW);
        bublinky = true;
   

        return 6;
    }  
     else if (command=="D60") {
       
        digitalWrite(led6,HIGH);
          svetlo = false;
        return 60;
    
    }
          // světlo
  
    else if (command=="D7") {
        digitalWrite(led7,LOW);
           svetlo = true;
         return 7;
    }
       else if (command=="D70") {
       
        digitalWrite(led7,HIGH);
          svetlo = false;
        return 70;
    
    }
    else if (command=="D8") {
        digitalWrite(led6,LOW);
         bublinky = true;
        delay(30000); 
        digitalWrite(led6,HIGH);
         bublinky = false;
        digitalWrite(led8,LOW);
        filtrace = true;

        return 8;
        
    }
    else if (command=="D80") {
       
        digitalWrite(led8,HIGH);
          filtrace = false;
        
        

        return 80;
        
    }
    
  
    
    else {
        return -1;
    }
  
}

@vasekj, as @ScruffR said, no spaces in the variable names! You still have spaces in some names. Also, the length of your address strings are too short as you need to include room for a terminating NULL. So you need a size of 16 not 15.

Once set in setup() using strcpy() you don’t modify the address anywhere in your code. You could, instead you could simply declare your addresses this way and not use strycpy() at all:

const char w1_address[] = "28-00000d2f9d04";  //temp akumulacka string
const char w2_address[] = "28-00000c4223e5"; //temp boiler string
const char w3_address[] = "28-00000d2fbcad";  //temp boiler string

Better yet, you could use arrays for both the addresses and the temperatures but I’m not sure you are ready for that.

Finally, the long delays in you Particle.function() are not good, especially those exceeding 10 seconds as the Particle Cloud expects an int value to be returned within 10 secs max. The ideal code design would use an FSM (Finite State Machine) in loop() which covers the different LED states and associated delays. In your Particle.function() you would then set the state of the FSM to the corresponding value to trigger the sequence of LEDs and delays() without delaying the Particle.function().

@rickkas7 put together an Application Note for FSMs here:

https://docs.particle.io/datasheets/app-notes/an010-finite-state-machines/

2 Likes