Compiling error with Arduino Mega, ethernet and json library.

Hi, i'm making an app to control my shutters with an Arduino Mega. It's got an ethernet shield so it can connect to my local network, wich makes it easy to control it from anywhere.

In the code I use both the ethernet library and also a json library named ArduinoJson (https://arduinojson.org/). I use this to sent all the variables in one package between the Arduino and my phone. The code is based upon the webserver example from the ethernet library.

Here it is:

#include <ArduinoJson.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177);
EthernetServer server(80);
StaticJsonDocument<5000> doc;

void setup() 
{
  pinMode(34, OUTPUT);
  
  Ethernet.init(10);
  Serial.begin(9600);
  Ethernet.begin(mac, ip);

  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);

        DeserializationError error = deserializeJson(doc, c);
        if(error) {
        Serial.print("deserializeJson() failed with code ");
        Serial.println(error.c_str());
        return false;
        }

        int slider = doc["seekBarValue"];
        if(slider > 0)
        {
          digitalWrite(34, HIGH);
          delay(2000);
          digitalWrite(34, LOW);
          delay(2000);
        }
        
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

However, when I try to compile it, I get this error message:

exit status 1
Fout bij het compileren voor board Arduino/Genuino Mega or Mega 2560

I don't know whats causing it and have checked everything from newer versions to the library's and every letter in my code.

Can someone please help.

Spacehack

Is it the complete compilation error message? Usually, there is more than this...
If necessary, change the size of the compilation message window to see if there is more.

"exit status 1" is NOT a useful error message. That is printed at the end whenever ANY error occurs. The actual error message, with the useful information that explicitly identifies both the precise location and precise nature of the actual error, PRECEDES the "exit status 1" message.

Regards,
Ray L.

This is the complete error message (everything is in dutch):

Build-opties gewijzigd, alles wordt opnieuw gebuild
C:\Users\Conti\Documents\Arduino\Json_bibliotheek_test\Json_bibliotheek_test.ino: In function 'void loop()':

C:\Users\Conti\Documents\Arduino\Json_bibliotheek_test\Json_bibliotheek_test.ino:40:16: warning: return-statement with a value, in function returning 'void' [-fpermissive]

return false;

^

In file included from C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/deserialize.hpp:9:0,

from C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:7,

from C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:33,

from C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,

from C:\Users\Conti\Documents\Arduino\Json_bibliotheek_test\Json_bibliotheek_test.ino:1:

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/Reader.hpp: In instantiation of 'int ArduinoJson6130_000001::Reader<TSource, Enable>::read() [with TSource = char; Enable = void]':

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:46:28: required from 'char ArduinoJson6130_000001::JsonDeserializer<TReader, TStringStorage>::current() [with TReader = ArduinoJson6130_000001::Reader<char, void>; TStringStorage = ArduinoJson6130_000001::StringCopier]'

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:67:20: required from 'ArduinoJson6130_000001::DeserializationError ArduinoJson6130_000001::JsonDeserializer<TReader, TStringStorage>::parseVariant(ArduinoJson6130_000001::VariantData&) [with TReader = ArduinoJson6130_000001::Reader<char, void>; TStringStorage = ArduinoJson6130_000001::StringCopier]'

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:31:44: required from 'ArduinoJson6130_000001::DeserializationError ArduinoJson6130_000001::JsonDeserializer<TReader, TStringStorage>::parse(ArduinoJson6130_000001::VariantData&) [with TReader = ArduinoJson6130_000001::Reader<char, void>; TStringStorage = ArduinoJson6130_000001::StringCopier]'

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/deserialize.hpp:63:24: required from 'ArduinoJson6130_000001::DeserializationError ArduinoJson6130_000001::deserialize(ArduinoJson6130_000001::JsonDocument&, TStream&, ArduinoJson6130_000001::NestingLimit) [with TDeserializer = ArduinoJson6130_000001::JsonDeserializer; TStream = char]'

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:424:39: required from 'ArduinoJson6130_000001::DeserializationError ArduinoJson6130_000001::deserializeJson(ArduinoJson6130_000001::JsonDocument&, TInput&, ArduinoJson6130_000001::NestingLimit) [with TInput = char]'

C:\Users\Conti\Documents\Arduino\Json_bibliotheek_test\Json_bibliotheek_test.ino:36:60: required from here

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/Reader.hpp:20:26: error: request for member 'read' in '((ArduinoJson6130_000001::Reader<char, void>)this)->ArduinoJson6130_000001::Reader<char, void>::_source', which is of non-class type 'char'

return _source->read();

^

exit status 1
Fout bij het compileren voor board Arduino/Genuino Mega or Mega 2560

You have a return statement in your loop() - at line 40, character 16. loop() is a void function - i.e. it does not return anything. You can put a return statement (just "return;"), but you cannot return a value ("return false;").

There is also a problem at line 20, character 26 in:

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/Reader.hpp

It is attempting to invoke the function read(), using the variable "_source", which is apparently a char variable, and NOT a pointer to any type of class object. So that line is completely invalid.

Regards,
Ray L.

I don't understand what you mean with the variable "_source" but I don't think the problem is at line 20. The other one I have fixed,but I still get the error message.

You still get WHAT error message? I'm sure you're not getting exactly the same error messages as before, so post your new code, and the new error messages.

#include <ArduinoJson.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177);
EthernetServer server(80);
StaticJsonDocument<5000> doc;

void setup() 
{
  pinMode(34, OUTPUT);
  
  Ethernet.init(10);
  Serial.begin(9600);
  Ethernet.begin(mac, ip);

  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);

        DeserializationError error = deserializeJson(doc, c);
        if(error) {
        Serial.print("deserializeJson() failed with code ");
        Serial.println(error.c_str());
        return;
        }

        int slider = doc["seekBarValue"];
        if(slider > 0)
        {
          digitalWrite(34, HIGH);
          delay(2000);
          digitalWrite(34, LOW);
          delay(2000);
        }
        
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

In file included from C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/deserialize.hpp:9:0,

from C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:7,

from C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:33,

from C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,

from C:\Users\Conti\Documents\Arduino\Json_bibliotheek_test\Json_bibliotheek_test.ino:1:

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/Reader.hpp: In instantiation of 'int ArduinoJson6130_000001::Reader<TSource, Enable>::read() [with TSource = char; Enable = void]':

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:46:28: required from 'char ArduinoJson6130_000001::JsonDeserializer<TReader, TStringStorage>::current() [with TReader = ArduinoJson6130_000001::Reader<char, void>; TStringStorage = ArduinoJson6130_000001::StringCopier]'

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:67:20: required from 'ArduinoJson6130_000001::DeserializationError ArduinoJson6130_000001::JsonDeserializer<TReader, TStringStorage>::parseVariant(ArduinoJson6130_000001::VariantData&) [with TReader = ArduinoJson6130_000001::Reader<char, void>; TStringStorage = ArduinoJson6130_000001::StringCopier]'

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:31:44: required from 'ArduinoJson6130_000001::DeserializationError ArduinoJson6130_000001::JsonDeserializer<TReader, TStringStorage>::parse(ArduinoJson6130_000001::VariantData&) [with TReader = ArduinoJson6130_000001::Reader<char, void>; TStringStorage = ArduinoJson6130_000001::StringCopier]'

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/deserialize.hpp:63:24: required from 'ArduinoJson6130_000001::DeserializationError ArduinoJson6130_000001::deserialize(ArduinoJson6130_000001::JsonDocument&, TStream&, ArduinoJson6130_000001::NestingLimit) [with TDeserializer = ArduinoJson6130_000001::JsonDeserializer; TStream = char]'

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Json/JsonDeserializer.hpp:424:39: required from 'ArduinoJson6130_000001::DeserializationError ArduinoJson6130_000001::deserializeJson(ArduinoJson6130_000001::JsonDocument&, TInput&, ArduinoJson6130_000001::NestingLimit) [with TInput = char]'

C:\Users\Conti\Documents\Arduino\Json_bibliotheek_test\Json_bibliotheek_test.ino:36:60: required from here

C:\Users\Conti\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/Reader.hpp:20:26: error: request for member 'read' in '((ArduinoJson6130_000001::Reader<char, void>)this)->ArduinoJson6130_000001::Reader<char, void>::_source', which is of non-class type 'char'

return _source->read();

^

exit status 1
Fout bij het compileren voor board Arduino/Genuino Mega or Mega 2560

Manage to find the other error, the "char" on line "char c = client.read();" needed a "*" behind it.
Anyway, thanks for the help

Regards,
Spacehack.