Raspberry PI code not working


#1

HI there the following code is not compiling on Raspberry Pi:

int value3 =0;
int main(int argc, char *argv[])
{
     thinger_device thing(USER_ID, DEVICE_ID, DEVICE_CREDENTIAL);

    // define thing resources here. i.e, this is a sum example
   thing["in_out"] = [](pson& in, pson& out)
   {
       // out["sum"] = (int) in["value1"] + (int) in["value2"];
        //out["mult"] = (int) in["value1"] * (int) in["value2"];
       value3= in["value1"];
       int value4= in["value2"];

       std::cout << "Value 1= ";   
       auto s = std::to_string(value3);
       std::cout << s;
       std::cout << "\n";
       std::cout << "Value 2= ";   
       auto t = std::to_string(value4);
       std::cout << t;
       std::cout << "\n";
       out["sum"] = value3 + value4;
       out["mult"] = value3 * value4;
       out["Level"]= value3;

       if (value3==1000)
       { 
        thing.call_endpoint("Endpoint_1",value3);
        std::cout << "Alarm!!!!!!!"; 
         std::cout << "\n";
       };

   };
   thing.start();
   return 0;
}

It is about the thing.call_endpoint line.

Much appreciated if you could advise what is going wrong here. For me it is just to understand the concept of dealing with the calls.

Cheers,
F.


#2

Hi,

try to define

     thinger_device thing(USER_ID, DEVICE_ID, DEVICE_CREDENTIAL);

outside the main, just below the value3. This way, it can be used inside the lambda to call the endpoint.

Hope it helps!