Compiler error while inserting your example

Hi
I am trying to insert some control on an ESP8266 from a Thinger dashboard.
So I want to manually override a relay that is else controlled by software.

(Relay_value is a boolean.)

 thing["relay"] << [](pson & in) {
   if (in.is_empty()){
      in = Relay_value;
   }
     else {
     Relay_value = in;
   }
 }

Once I have entered that code, directly derived from your example, in the setup section, the sketch would not compile any more complaining that on the next instruction, a semicolon is missing.
I currently cannot figure out the reason for that error.
There is no missing semicolon?

Hi, yes, I think that the end semicolon is missing.

thing["relay"] << [](pson & in) {
   if (in.is_empty()){
      in = Relay_value;
   }
     else {
     Relay_value = in;
   }
 };

Oh yes.
Missing in your 2 examples.
Thank you for the turbo reaction.

Thanks for the report! Will update doc!

Hi @rin67630, can you provide the source of the example? We only found one with the error in the doc.

in https://docs.thinger.io/quick-sart/coding-guide

**

Summary

Show Input Resources State in Dashboards and API

**

The Dashboards or API works in a way that when you open them, they query the associated resources to correctly print its current state, i.e., the switch is on or off. In this way, when the API or a Dashboard is open, each associated input resource is called, receiving empty data in the call, as there is no intention to control the resource (the pson input will be empty).

So, how the Dashboards or the API knows what is the current state of an input resource? The resource must set its current state in the input parameter, if it is empty, or use the input value if there is one. This way, we can obtain three different things: query the current resource state (without modifying it), modify the current resource state, and obtain the expected input on the resource (this is how the API explorer on the device works).

Therefore, a correct input resource definition that actually allows to display the current state of the resource in a Dashboard or in the API, will be like this example code.

thing["resource"] << [](pson& in){
    if(in.is_empty()){
        in = currentState;
    }
    else{
        currentState = in;
    }
}

This sample code basically returns the current state (like a boolean, a number, etc) if there is no input control, or use the incoming data to update the current state. This can be easily adapted for controlling a led, while showing its current state in the dashboard once opened or updated.

thing["led"] << [](pson& in){
    if(in.is_empty()){
        in = (bool) digitalRead(pin);
    }
    else{
        digitalWrite(pin, in ? HIGH : LOW);
    }
}

Note: for controlling a digital pin just use the method explained in the Easier Resources Section.

In both examples given the final “;” is missing.

1 Like