REST API and JSON-RPC in easy way

Dear Community,

Please let me share μcuREST library which is aimed for easy creation of RESTful and/or JSON-RPC API in IoT projects.
The concept of this library is described on this page. In short words - you define a map of URIs to application’s variables/functions and μcuREST makes them accessible via HTTP protocol.

The ZIP with the library sources packaged for Spark Particle SDK is available for downloading from GitHub. Just unzip in in the SDK’s top directory and it will create user/libraries/micurest with the library sources, user/applications/micurest_snip and user/applications/micurest_demo with a simple example and more advanced demo application. The demo is also available as prebuilt binary on this link.
Library sources are hosted on GitHub as well
Below you may find some screenshots made from the demo application.


Great stuff. How did you compile for the photon platform? (what libraries did you need and commands did you run?)

All you need is Spark Particle SDK, and of course, the μcuREST library.
The easiest way to start is to download and unzip it in the SDK’s root dir.

Then just run command
make PLATFORM=photon APP=micurest_snip

In details, the Particle build system is described here:


will do it right now!

ps, i had flashed my photon with your binary, but it wasn’t accessible when I went to what I understand (from the router’s MAC table) is the photon. ie

Changing Serial1 to Serial and will see what it thinks is going on!

A file is missing… #include “micurest/network_log.ccs”

…edit: changed it to ‘access_log.ccs’ and seems to continue, access_log has references to the network namespace.

In file included from applications/micurest_snip/micurest/access_log.hpp:21:0,
from applications/micurest_snip/application.cpp:9:
applications/micurest_snip/micurest/miculog.hpp:86:54: error: ‘enabled’ function uses ‘auto’ type specifier without trailing return type
static inline constexpr const auto enabled(level lvl) {

corresponding code:

static inline constexpr const auto enabled(level lvl)  {
		return details::is_set(levels, lvl);

All I can find is references to auto deduced return values with C++1Y.

May you try to add CPPFLAGS="-std=gnu++1y" to the make command line?

Thanks for reporting a missing file - it has been renamed but not all references were updated

1 Like

Trying that now!

Also tried with a 5.1 arm gcc rather than 4.9.1 and it now looks for C++14 (which was the version that C++1Y became 1 year later in 2014)

Seems to error close to the end. Will re-run it with 4.9.1

/Users/markterrill/opt/gcc-arm-none-eabi-5_4-2016q3/bin/…/lib/gcc/arm-none-eabi/5.4.1/…/…/…/…/arm-none-eabi/bin/ld: …/build/target/bootloader/platform-6-lto/bootloader.elf section .text' will not fit in regionAPP_FLASH’
/Users/markterrill/opt/gcc-arm-none-eabi-5_4-2016q3/bin/…/lib/gcc/arm-none-eabi/5.4.1/…/…/…/…/arm-none-eabi/bin/ld: region APP_FLASH' overflowed by 3348 bytes /Users/markterrill/opt/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7-m/libg.a(lib_a-sbrkr.o): In function_sbrk_r’:
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk’
collect2: error: ld returned 1 exit status
make[1]: *** […/build/target/bootloader/platform-6-lto/bootloader.elf] Error 1

It doesn’t do that error if using gcc 4.9.1, however pulls up a range of template errors to do with ‘micurest::network_spark_socket::tcp::tcp’ (the tcp::tcp seems not to match the template in the .ccs:

namespace micurest {
namespace network_spark_socket {
namespace tcp {
class server; /* uses log */

@hutorny, could you try compiling again locally? I’m swimming a bit further than my normal depth. Changing the reference to avoid the double tcp::tcp didn’t work out. It seems since the last time you compiled that a fair few things have moved quietly in the night that you probably could fix up quickly.

I remember once I’ve got this error to, give me some time to recall a solution.

1 Like

There was an outdated configuration.h. A fresh update is availabe from github. There is also a new README with build instructions

You may also need to run make clean to fix bootloader issue, which is caused by building the core with wrong compiler flags

1 Like

Working great, thanks!

BTW, I compiled against the current stable branch of Particle firmware as that other SDK repository appears to be 2 years old.

There were a few minor tweaks needed. On both I changed Serial1. to Serial. as most people are debugging via the USB cable.

_snip in application.cpp needed:

#define LED_BUILTIN D7

_demo in photon_wiring_rpc.cpp needed:

#include "pinmap_hal.h" 

Simply included the pinmap_hal as it has the system wide define for total_analog_pins, whereas strangely digital_pins isn’t defined so simply put in a define.

Awesome library, its like the tinker app but over local HTTP which addresses so many use cases when the user doesn’t have internet.

I’ve updated my SDK to the official release/stable and confirm the issue. It looks like application.h does not include Arduino.h anymore. With inclusion of it, issue with NUM_DIGITAL_PINS and LED_BUILTIN is gone

You can follow this issue on github but my understanding is that adding Arduino.h to application.h caused a lot a libraries to fail to compile due to multiply defined Arduino symbols. So they decided to change it in a way that lets library authors control which level of compatibility they want.

1 Like