marcoschwartz / aREST

A RESTful environment for Arduino
http://aREST.io/
Other
1.2k stars 279 forks source link

Feature/controller #239

Closed OidaTiftla closed 6 years ago

OidaTiftla commented 6 years ago

Hi, if you don't like the changes, don't mind and simply close this pull request 😄

This pull request builds upon pull request #238.

The possibility is added to extend the api by your own subcommands and customized responses. The unit tests are also extended, and tested as far as I could do with my setup (Ethernet Shield on Arduino). With my setup, all test run through now 😅 The examples section is also updated with the new snippets.

I hope you feel comfortable with the changes. If anything is not working, or you have other ideas, I'm looking forward to hearing from you.

The backwards compatibility of the API of the library is kept and the API can be used in the same way as before:

template<typename T>
void variable(const char *name, T *var, bool quotable);

void function(const char *name, int (*f)(String));

To explain the new functionality, I copied the updated README.md section below:

API-Extensions

You can also define your api extensions in your sketch that can be called using the REST API. To access an user-defined api-extension defined in your sketch, you have to declare it first, and then call it from with a REST call. Note that all api-extension functions need to have the following signature void api_extension(aREST *arest, const String& name, const String& request_url). For example, if your aREST instance is called "rest" and the function "aquariumController":

OidaTiftla commented 6 years ago

I also updated this branch :)

marcoschwartz commented 6 years ago

Merged this one as well, thanks again for your contribution! As usual I'll spend some time testing it with all the boards to make sure it all works smoothly.

marcoschwartz commented 6 years ago

One thing is that I will have to remove the examples with aquariumController from the examples, as it is too specific and also the code in the api extension is too long for the examples. However, I invite you to create a new example (for example esp8266_api_extension.ino) to show people how to use this new function :)

marcoschwartz commented 6 years ago

Unfortunately I had to revert this and also the previous commit as it created issues with accessing variables via the cloud server. Please check that, and I'd be happy to merge your changes again once this is fixed :)

OidaTiftla commented 6 years ago

Okay, no problem, it was just for the sake of completeness. I'll copy it to a new example file.

I'll have a look at the cloud server problem.