Hi @corri,
welcome to the community! some recommendations, anytime you post code in the forum, please, use the code button to correctly format it, i.e.,
thing [ “Value_in”] << [] (pson & in) {
some c code with no action on “in”
};
Regarding your question, it is normal that your code is executed twice when you call it from a dashboard. What the system does, is:
- Send the desired value to the resource
- Execute the resource to check the actual value established, in order to transmit current state to listening dashboards.
You can check if there is incoming data or not with the is_empty
. Direct example copied for our documentation: https://docs.thinger.io/quick-sart/coding-guide#show-input-resources-state-in-dashboards-and-api
thing["led"] << [](pson& in){
if(in.is_empty()){
in = (bool) digitalRead(pin);
}else{
digitalWrite(pin, in ? HIGH : LOW);
}
};
Hope it helps!