Loop in thing declaration


#1

Hello guys, I have the following things declared, and them works flawlessly, but does anybody how to declare this with a “for” loop (for example), in case that its needed to declare n fields to avoid write them line by line.

This is for the input output case:

 thing["Calibration"] << [](pson& in){
    if(in["Cal1"].is_empty()) in["Cal1"] = cal[1];
    else cal[1] = in["Cal1"];
    if(in["Cal2"].is_empty()) in["Cal2"] = cal[2];
    else cal[2] = in["Cal2"];
    if(in["Cal3"].is_empty()) in["Cal3"] = cal[3];
    else cal[3] = in["Cal3"];
    };

And this for the output case:

thing["Status"] >> [](pson& out){
      out["Actual1"] = current[1];
      out["Actual2"] = current[2];
      out["Actual3"] = current[3];
}; 

Thanks in advance


#2

Hi @alvarolb! Any advice about this?