How would one go about reading and/or updating a device parameter from the app? From what I read in the documentation, it should be possible to do it like this:
thing[“minimum”] = [](pson& in, pson& out){
if (in > 0) { minimum = in }
out = minimum;
};
However, when I tried that, the device value was not shown by the app, and a POST operation from the app to the device never ended on the app (even though it got executed by the device).
So then I had to revert to something more complicated, using a separate attribute name for setting the value, and one for reading the value. That works but it’s not as straightforward.
These resources that have both input and output are not selectable for the dashboard, is that by design? I would think that the one from the example above should be visible, as there are no subitems.
Then another question, is there a way to hide certain device resources from the app?
When making (in>0) You are trying to evaluate a Pson as a numerical variable, and this might not work properly. By another side, could be useful to include an additional comparison to know if the input pson is empty:
thing["minimum"] = [](pson& in, pson& out){
if (in.is_empty()){
in=minimum ; //we are taking the last value of minimum in our program
out=minimum; //if you want to show this value too when de pson is empty
}else{
minimum = in ;
out = minimum;
}
};
with this resource, the sistem will create two boxes, one for input and one for output data:
Our sketch usually defines some parameters or variables that are used inside the loop code. This kind of resources are normally used to handle or control the execution behaviour. With this kind of resources we can modify any parameter we want to expose, like a float, an integer, a boolean, etc.
In this example it is possible to remotelly modify the boolean sdLogging variable defined as a global variable.
thing["logging"] << inputValue(sdLogging);
It is also possible to define a callback function to know when the variable has changed, so we can perform any other action. For this use case, define the resource as the following to have some code executed when the hysteresisVar changes.
thing["hysteresis"] << inputValue(hysteresisVar, {
// execute some code when the value change
Serial.println("Hystereis changed to: ");
Serial.print(hysteresisVar);
});