[Solved] You can expose a method on a C++ object to the Cloud

Hi Everyone,

The example found [here][1] suggests you can expose a class method to the cloud e.g.

class CoffeeMaker {
  public:
    CoffeeMaker() {
      Particle.function("brew", &CoffeeMaker::brew, this);
    }

    int brew(String command) {
      // do stuff
      return 1;
    }
};

I tried this and received some compiler errors which suggest Particle.function does not even have 3 arguments:

 In instantiation of 'static bool CloudClass::function(const T&, Types ...) [with T = char [5]; Types = {void (OneWireInterface::*)(), OneWireInterface*}]':
OneWireInterface.cpp:12:60:   required from here
../wiring/inc/spark_wiring_cloud.h:191:39: error: no matching function for call to 'CloudClass::_function(const char [5], void (OneWireInterface::*&)(), OneWireInterface*&)'
         return _function(name, args...);
                                       ^
../wiring/inc/spark_wiring_cloud.h:191:39: note: candidates are:
../wiring/inc/spark_wiring_cloud.h:194:17: note: static bool CloudClass::_function(const char*, int (*)(String))
 

Does anyone have a solution? 

  [1]: https://docs.particle.io/reference/firmware/photon/#particle-function

Sorry!

I realized the signature must be

int func(String s) {};

:grin:

1 Like