ArduinoJson Example Fails

I tried this example

Got this error =====================

Processing json.ino
Checking library ArduinoJson…
Installing library ArduinoJson 6.10.0 to lib/ArduinoJson …
Library ArduinoJson 6.10.0 installed.
make -C …/modules/photon/user-part all
make[1]: Entering directory ‘/firmware/modules/photon/user-part’
make -C …/…/…/user
make[2]: Entering directory ‘/firmware/user’
Building cpp file: src/json.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p …/build/target/user/platform-6-msrc/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=1.0.1 -DRELEASE_BUILD -I./inc -I…/wiring/inc -I…/system/inc -I…/services/inc -I…/services/nanopb -I…/communication/src -I…/hal/inc -I…/hal/shared -I…/hal/src/photon -I…/hal/src/stm32f2xx -I…/hal/src/stm32 -I…/hal/src/photon/api -I…/hal/src/photon/include -I…/hal/src/photon/wiced/security/BESL/host/WICED/ -I…/hal/src/photon/wiced/security/BESL/include -I…/hal/src/photon/wiced/security/BESL -I…/hal/src/photon/wiced/security/BESL/crypto -I…/hal/src/photon/wiced/WWD/include/ -I…/hal/src/photon/wiced/platform/include/ -I…/hal/src/photon/wiced/platform/GCC/ -I…/hal/src/photon/wiced/security/BESL/supplicant/ -I…/hal/src/photon/libraries/crypto -I…/platform/shared/inc -I…/platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I…/platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I…/platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I…/platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I…/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I…/platform/MCU/shared/STM32/inc -I…/platform/MCU/STM32F2xx/CMSIS/Include -I…/platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I…/dynalib/inc -Isrc -I./libraries -Ilib/ArduinoJson/src -I. -MD -MP -MF …/build/target/user/platform-6-msrc/json.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY -DSPARK_PLATFORM_NET=BCM9WCDUSI09 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=5 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,1002 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="“app”" -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o …/build/target/user/platform-6-msrc/json.o src/json.cpp
In file included from lib/ArduinoJson/src/ArduinoJson/Strings/StringAdapters.hpp:35:0,
from lib/ArduinoJson/src/ArduinoJson/Misc/SerializedValue.hpp:7,
from lib/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp:7,
from lib/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp:7,
from lib/ArduinoJson/src/ArduinoJson.hpp:17,
from lib/ArduinoJson/src/ArduinoJson.h:9,
from json.ino:9:
lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp: In member function ‘bool ArduinoJson6100_110::SizedFlashStringAdapter::equals(const char*) const’:
lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp:17:45: error: ‘strncmp_P’ was not declared in this scope
return strncmp_P(expected, actual, _size) == 0;
^
…/build/module.mk:265: recipe for target ‘…/build/target/user/platform-6-msrc/json.o’ failed
make[2]: Leaving directory ‘/firmware/user’
make[2]: *** […/build/target/user/platform-6-msrc/json.o] Error 1
…/…/…/build/recurse.mk:11: recipe for target ‘user’ failed
make[1]: Leaving directory ‘/firmware/modules/photon/user-part’
make[1]: *** [user] Error 2
…/build/recurse.mk:11: recipe for target ‘modules/photon/user-part’ failed
make: *** [modules/photon/user-part] Error 2

Yup, strncmp_P() does not exist on these devices since there is no such disctinction between RAM and program (hence the _P) memory as on AVR devices where you need special treatment for program memory based data.

You could file an issue on the contributors GitHub repo to add #define strncmp_P(...) strncmp(...) (and for all similar functions like memcpy_P) in case a particle device is detected or you switch over to this library JsonParserGeneratorRK.cpp.

But as it turns out there already is such a define in the Particle device OS repo

This suggests you may just need to select a more recent build target for your firmware.

1 Like

If you are using a local ide just go to that file and change it to strcmp, which is what I did when upgrading my ArduinoJson version. My build target has the file above and I still got that problem, so I doubt that would fix it for you. A github note wouldn’t be a bad idea, I suppose, but not an immediate fix.

If it’s because you’re using ArduinoJson version 6.10.0, maybe defining the below before importing ArduinoJson.h will eliminate the issue as it did for me.

#define ARDUINOJSON_ENABLE_PROGMEM 0
1 Like

I was struggling to get the ArduinoJson library to work, but adding

#include “Arduino.h”

fixed all of my issues.

1 Like

I came across the same issue today with version 6.11.3. Placing the #define mentioned by @ScruffR at the top of my code resolved the problem.