Compile error from ArduinoJson library


#1

I am moving from the WebIDE to get to learn Workbench. I initialised a new project. Installed all the libraries, copied all the src files from a downloaded zip from the WebIDE.

1st compile error

/Users/shanevanj/Documents/Workbench/fMonX/fMonX1/lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp: In member function 'int8_t ArduinoJson6113_11000::SizedFlashStringAdapter::compare(const char*) const':
/Users/shanevanj/Documents/Workbench/fMonX/fMonX1/lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp:18:72: error: 'strncmp_P' was not declared in this scope
     return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size);

obviously objecting to strncmp_P, understandable as there is only one space in Gen3 devices (my target) - however in the web wide the doesn’t happen - So how do I get around it without necessarily editing library files locally ?


#2

if you are comfortable sharing your source or simplified version of it that reproduces the error, i’d be happy to take a look.

in the meantime, things to double-check are: platform (photon, argon, etc) and Device OS version - make sure you have them set the same way across both WebIDE and Workbench. you can change these settings via VSCode’s “status” bar at the bottom of the window (typically it’s blue / cyan) - just click the entries and you’ll be prompted to select values. you can also run the Particle: Configure Workspace for Device command and it’ll walk you through making the changes.

also, if you haven’t seen them already, Workbench docs are over here:

https://docs.particle.io/workbench/


#3

As @m_m already asked, what device OS version are you targeting?
These Arduino compatibility macros got introduced later on in history.


#4

Easy to reproduce.

Create new project, install ArduinoJSON libray. Open lib/ArduinoJson/examplesJsonParserExample. Copy contents to your new project .ino file and compile. error produced is

/Users/shanevanj/Documents/Workbench/ArduinoJson/Test/lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp: In member function 'int8_t ArduinoJson6113_11000::SizedFlashStringAdapter::compare(const char*) const':
/Users/shanevanj/Documents/Workbench/ArduinoJson/Test/lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp:18:72: error: 'strncmp_P' was not declared in this scope
     return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size);

This is Photon target with deviceOS@1.0.1. selected, then try with deviceOS@1.2.1. - same error.

I then edited spark_wiring_arduino.h in …toolchains/deviceOS/1.2.1/firmware-1.2.1/wiring/inc/ and added in

#ifndef strncmp_P
#define strncmp_P strncmp
#endif

and the source now compiles with no errors - try it again with deviceOS@1.1.0 and then with deviceOS@1.0.1 - error returns


#5

Can someone log as a bug after verifying the above (or not if thats the case - I am still a noob at this and may have got it wrong)


#6

sounds like you are hitting this:

do any of the suggested fixes in that thread work for you?


#7

Essentially I came to the same conclusion as @ScruffR did in that thread.The definition above is missing from the Arduino compatibility macros in each deviceOS release fro workbench. Once you add it in it all works. It needs to be be logged as an issue for the workbench team to add in this macro.


#8

As it seems pgmspace.h is not included when not also including Arduino.h but for existing libraries that were ported for Particle before Arduino.h was added to the build farms that’s suboptimal :wink:

But if you #include <Arduino.h> before any dependent headers you should be good.


#9

So just to close this thread down - the fix is as follows

include <Arduino.h> before the <ArduinoJson.h> library and add in a definition as follows

#include <Arduino.h>
#define ARDUINOJSON_ENABLE_PROGMEM 0
#include <ArduinoJson.h>