Resources gets reset on api refresh

hello to all,
i have read the coding guide and i have searched on the forum about that.
i use a input/output resource to output a value in the cloud so other devices can see the value and change the value.
but when i refresh api or simply return in the api page the value gets reset to 0.0 (it’s a float).
how can i solve this problem?

Hi, let us see your code to see how is the “thing” defined.

Best,

first of all thanks for your support.
this is the code

void setup() {
	cella2SetT = preferences.getFloat("cella2set", 4.0); //read data fromm EEPROM
	Serial.print("Temperatura Set cella 2: "); //show data
	Serial.println(cella2SetT); //show data
	thing["Cella 2 set"] >> outputValue(cella2SetT);//send the value on the cloud
	
	thing["Cella 2 set"] << [](pson& in){
	        cella2SetT = in; // transfer (i think) the value in a local variable
	        preferences.putFloat("cella2set", cella2SetT); //save data in EEPROM
	        Serial.print("Nuovo set cella 2 : "); Serial.println(cella2SetT); //show data
	};
	
...
...
}

You have it defined as exclusive input “thing”, something like this should work as input/output:

 thing["Cella 2 set"] << [](pson & in) {
    if (in.is_empty()) in = cella2SetT;
    else cella2SetT= in;
 };

or its resumed form:

 thing["Cella 2 set"] << [](pson & in) {
    (in.is_empty()) ? in = cella2SetT : cella2SetT= in;
 };

I focused just on thinger “thing” definition, you may add the code you want into the “thing” cycle.

Both should work, let me know how it goes.

it works fine,
therefore an input resource can send also an output.

without your help it would have taken me a lot longer.
thanks

i have another question.
i open a new topic so somebody can find it if it need

No worries my friend, that’s why we are here, to help each other.

Regards,