ArduinoJson icon indicating copy to clipboard operation
ArduinoJson copied to clipboard

Compiler crash when add EasyTransfer library

Open choncba opened this issue 10 years ago • 3 comments

Hello everyone, first of all I want to congratulate the creator of this excellent library. I use a ESP8266 ESP12 , in one of my projects I use EasyTransfer library (https://github.com/madsci1016/Arduino-EasyTransfer) to synchronize with another arduino via serial link. When trying to compile ArduinoJSON with this compiler fails with the following message:

ArduinoJson.hpp:11: In file included from
ArduinoJson.h:8: from
ArduinoJson.h:8: from
RiegoControlV4ESP.ino:47: from
JsonArray.hpp: In instantiation of typename ArduinoJson::Internals::JsonVariantAs<T>::type ArduinoJson::JsonArray::get(size_t) const [with T = char; typename ArduinoJson::Internals::JsonVariantAs<T>::type = char; size_t = unsigned int]
JsonArraySubscript.hpp:55: required from typename ArduinoJson  Internals  JsonVariantAs<T>  type ArduinoJson  JsonArraySubscript  as() const [with T = char; typename ArduinoJson  Internals  JsonVariantAs<T>  type = char]
JsonVariantBase.hpp:61: required from const typename ArduinoJson  Internals  JsonVariantAs<T>  type ArduinoJson  JsonVariantBase<TImpl>  as() const [with T = char; TImpl = ArduinoJson  JsonArraySubscript; typename ArduinoJson  Internals  JsonVariantAs<T>  type = char]
JsonVariantBase.hpp:56: required from ArduinoJson  JsonVariantBase<TImpl>  operator T() const [with T = char; TImpl = ArduinoJson  JsonArraySubscript]
RiegoControlV4ESP.ino:583: required from here

JsonArray.hpp: 142:17: error: no matching function for call to 'ArduinoJson::JsonVariant::as()
   JsonVariant::defaultValue<T>()
JsonArray.hpp:142: note  candidates are

This library uses malloc () to allocate memory.

Any ideas?

Thanks.-

choncba avatar Oct 11 '16 04:10 choncba

Hello Luciano,

It seems that you are trying to convert a JsonVariant to char, which is not supported.

You probably have code like this:

char c = myObject["key"];

you just need to change it to:

byte c = myObject["key"];

bblanchon avatar Oct 11 '16 08:10 bblanchon

Thank you @bblanchon ! I was focused on thinking it was a problem of memory allocation and did not see the obvious. Here is my code:

StaticJsonBuffer buffer; JsonArray& recibido = jsonBuffer.parseArray(server.arg("plain"));

if (recibido.success())
{
    int NumSalida = recibido[0];
    Estados.EstadoSalida[NumSalida] = recibido[1];
    // SendCmd() takes 3 chars as argument
        //SendCmd('S', recibido[1], recibido[0]);   // -> This way produces the error
        SendCmd('S', Estados.EstadoSalida[NumSalida], NumSalida);   // This way is ok
}

So, the EasyTransfer library has nothing to see with this error.

choncba avatar Oct 11 '16 13:10 choncba

You're welcome Luciano, thanks for using ArduinoJson.

Don't hesitate to edit the wiki if you think you can improve it. In particular, feel free to add your projects to Projects using ArduinoJson.

Also, a GitHub star is always appreciated :wink:

bblanchon avatar Oct 11 '16 13:10 bblanchon