You’ll know the game. Someone gets a post-it on his forehead with a name and must find this person by asking e.g. „Am I an engineer?“. The answer is always YES or NO. To handle several Spark Cores with different functionality, I’ve implemented this idea as webservice for all my Cores.
For my Death Star lamp, I’m implementing a mobile app. To be able to control also several lamps, the app is dynamically deriving a list of Spark Cores available. As there might be more cores available and I haven’t find a way to tag/classify/group several core based on their role, the app is asking whether the Core is a Deathstar. If so the Core is returning true/1 if not false/0.
For all my Cores I have implemented/will be implementing the function in the same way. So this piece of code will be compatible in future and even allow to have one personal app, offering different interfaces/functionality based on the Cores.
String Iam = "Deathstar"; // Defines the role of the core void setup() { ... Spark.function("AmI", AmI); // Exposes the function to the Web API ... } int AmI(String who){ // "Actual Who Am I"-function if (who.equalsIgnoreCase(Iam)){ return 1; } else { return 0; } }
As one security principle only as little information as possible is being exposed. With this implementation the client application needs to come up with an proposal of the concrete Core’s role and the Core is just returning whether this is correct or not. This makes it already tougher to attack it instead of having a function „WhoAreYou“ returning directly the role.