How to parse JSON data from local web server?

Greetings,
I am new to the forum and have searched all over for a solution to my problem. I am trying to make a program that reads temperature and humidity data off of a local server, and using Benoit Blanchon's ArduinoJson Library and the ethernet library, translate certain temperature and humidity values into variables that I can manipulate throughout more of the code. The issue is when I try to compile, I get many error messages, the last one saying:"substitution of deduced template arguments resulted in errors seen above". Any Ideas? I'm new to arduino and code.
Thanks
Max

WebDataAndParser.ino (2.86 KB)

can't read your attachment from my mobile. seems small... post inline with code tags....

Greetings,
I'm new to the forum and generally new to arduino programming. I have been trying to create a program that receives temperature and humidity data (in a Json format), then translates the data into variables that I can manipulate throughout the rest of my code. The problem is when I try to compile the code, I get multiple errors, many of which I cannot understand. Any help would be appreciated!

Here are the errors:
In file included from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/JsonBufferBase.hpp:7:0,

from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/DynamicJsonBuffer.hpp:7,

from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson.hpp:9,

from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson.h:9,

from C:\Users\Max Kreckel\Desktop\Arduino\Programs\WebDataAndParser\WebDataAndParser.ino:1:

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/Deserialization/JsonParser.hpp: In instantiation of 'struct ArduinoJson::Internals::JsonParserBuilder<ArduinoJson::Internals::DynamicJsonBufferBaseArduinoJson::Internals::DefaultAllocator, char, void>':

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/Deserialization/JsonParser.hpp:96:66: required by substitution of 'template<class TJsonBuffer, class TString> typename ArduinoJson::Internals::JsonParserBuilder<TJsonBuffer, TString>::TParser ArduinoJson::Internals::makeParser(TJsonBuffer*, TString&, uint8_t) [with TJsonBuffer = ArduinoJson::Internals::DynamicJsonBufferBaseArduinoJson::Internals::DefaultAllocator; TString = char]'

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/JsonBufferBase.hpp:86:60: required from 'ArduinoJson::JsonObject& ArduinoJson::Internals::JsonBufferBase::parseObject(TString&, uint8_t) [with TString = char; TDerived = ArduinoJson::Internals::DynamicJsonBufferBaseArduinoJson::Internals::DefaultAllocator; uint8_t = unsigned char]'

C:\Users\Max Kreckel\Desktop\Arduino\Programs\WebDataAndParser\WebDataAndParser.ino:44:54: required from here

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/Deserialization/JsonParser.hpp:73:50: error: no type named 'Reader' in 'struct ArduinoJson::Internals::StringTraits<char, void>'

typedef typename StringTraits::Reader InputReader;

^

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/Deserialization/JsonParser.hpp:74:50: error: no type named 'Reader' in 'struct ArduinoJson::Internals::StringTraits<char, void>'

typedef JsonParser<InputReader, TJsonBuffer &> TParser;

^

In file included from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/DynamicJsonBuffer.hpp:7:0,

from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson.hpp:9,

from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson.h:9,

from C:\Users\Max Kreckel\Desktop\Arduino\Programs\WebDataAndParser\WebDataAndParser.ino:1:

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/JsonBufferBase.hpp: In instantiation of 'ArduinoJson::JsonObject& ArduinoJson::Internals::JsonBufferBase::parseObject(TString&, uint8_t) [with TString = char; TDerived = ArduinoJson::Internals::DynamicJsonBufferBaseArduinoJson::Internals::DefaultAllocator; uint8_t = unsigned char]':

C:\Users\Max Kreckel\Desktop\Arduino\Programs\WebDataAndParser\WebDataAndParser.ino:44:54: required from here

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/JsonBufferBase.hpp:86:60: error: no matching function for call to 'makeParser(ArduinoJson::Internals::DynamicJsonBufferBaseArduinoJson::Internals::DefaultAllocator*, char&, uint8_t&)'

return Internals::makeParser(that(), json, nestingLimit).parseObject();

^

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/JsonBufferBase.hpp:86:60: note: candidate is:

In file included from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/JsonBufferBase.hpp:7:0,

from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/DynamicJsonBuffer.hpp:7,

from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson.hpp:9,

from C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson.h:9,

from C:\Users\Max Kreckel\Desktop\Arduino\Programs\WebDataAndParser\WebDataAndParser.ino:1:

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/Deserialization/JsonParser.hpp:96:66: note: template<class TJsonBuffer, class TString> typename ArduinoJson::Internals::JsonParserBuilder<TJsonBuffer, TString>::TParser ArduinoJson::Internals::makeParser(TJsonBuffer*, TString&, uint8_t)

inline typename JsonParserBuilder<TJsonBuffer, TString>::TParser makeParser(

^

C:\Program Files (x86)\Arduino\libraries\ArduinoJson-master\src/ArduinoJson/Deserialization/JsonParser.hpp:96:66: note: substitution of deduced template arguments resulted in errors seen above

WebDataAndParser.ino (2.86 KB)

Here is the code with code tags:

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

//Internet Setup
byte mac[] = {0xE2, 0x79, 0x7A, 0x91, 0x17, 0x2F};
IPAddress ip(10,1,6,205);
IPAddress myDns(10,200,200,5);
EthernetClient client;
IPAddress server(10,1,6,204);
unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 10*1000;


void setup() {
  Serial.begin(9600);
  while(!Serial) continue; 

  //Setting up JSON Buffer
  const size_t buffersize = 14*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(14) + 650;
   

  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) { 
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip, myDns);
    Serial.println("My IP Address: ");
    Serial.println(Ethernet.localIP());
  } else { 
    Serial.print(" DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  } 

  delay(1000);

  }

void loop() {
  if(client.available()){ 
    char webData = client.read();
    Serial.write(webData); 
    const size_t buffersize = 14*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(14) + 650;
     DynamicJsonBuffer jsonBuffer(buffersize);
    JsonObject& root = jsonBuffer.parseObject(webData); 

    const char* HUM_EAST_CHIMNEY_LOW_v = root["HUM_EAST_CHIMNEY_LOW"]["v"]; 
    const char* TEMP_EAST_CHIMNEY_LOW_v = root["TEMP_EAST_CHIMNEY_LOW"]["v"];

    const char* HUM_EAST_CHIMNEY_HIGH_v = root["HUM_EAST_CHIMNEY_HIGH"]["v"];
    const char* TEMP_EAST_CHIMNEY_HIGH_v = root["TEMP_EAST_CHIMNEY_HIGH"]["v"];

    const char* HUM_WEST_CHIMNEY_LOW_v = root["HUM_WEST_CHIMNEY_LOW"]["v"]; 
    const char* TEMP_WEST_CHIMNEY_LOW_v = root["TEMP_WEST_CHIMNEY_LOW"]["v"];
    
    const char* TEMP_WEST_CHIMNEY_HIGH_v = root["TEMP_WEST_CHIMNEY_HIGH"]["v"]; 
    const char* HUM_WEST_CHIMNEY_HIGH_v = root["HUM_WEST_CHIMNEY_HIGH"]["v"];

    Serial.println("East Chimney Low");
    Serial.println(TEMP_EAST_CHIMNEY_LOW_v);
    Serial.println(HUM_EAST_CHIMNEY_LOW_v); 

    Serial.println("East Chimney High");
    Serial.println(TEMP_EAST_CHIMNEY_HIGH_v);
    Serial.println(HUM_EAST_CHIMNEY_HIGH_v); 

    Serial.println("West Chimney Low");
    Serial.println(TEMP_WEST_CHIMNEY_LOW_v);
    Serial.println(HUM_WEST_CHIMNEY_LOW_v);  

    Serial.println("West Chimney High");
    Serial.println(TEMP_WEST_CHIMNEY_HIGH_v);
    Serial.println(HUM_WEST_CHIMNEY_HIGH_v); 
    delay(5000);
    } 

    if(millis() - lastConnectionTime > postingInterval){ 
      httpRequest();
    }

}

  void httpRequest() {
  
  client.stop();

  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    client.println("GET /latest.txt HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    lastConnectionTime = millis();
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  } 
}
    JsonObject& root = jsonBuffer.parseObject(webData);

webData is a character - a SINGLE character.

You can't parse a single character.

    char webData = client.read();
    Serial.write(webData);
    const size_t buffersize = 14*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(14) + 650;
     DynamicJsonBuffer jsonBuffer(buffersize);
    JsonObject& root = jsonBuffer.parseObject(webData);

webData is a character - a SINGLE character.

You can't parse a single character.

How would I get around that? I now understand that it cannot parse a single character. If I understand the client.read() function correctly then I know that It will read the Json object one byte at a time.

If I understand the client.read() function correctly then I know that It will read the Json object one byte at a time.

So, if you need to read n bytes, doesn't it seem reasonable that you'll need to call client.read() n times, AND store the values in an array that can hold n+1 characters?

If you don't know what n is, you need an array that can hold more characters than you expect, and you need to loop reading all the data, until there is no more data to read (the server closed the connection, so client.connected() is false and client.available() is 0).

Why would I store the values in an array if the data is a Json object? Wouldn't it be easier to parse it as an object?
This is the data which is being received from the server:
{
"HUM_EAST_CHIMNEY_LOW":{"t":1538663182,"v":"66.90"},
"TEMP_EAST_CHIMNEY_LOW":{"t":1538663182,"v":"70.88"},
"HUM_EAST_CHIMNEY_HIGH":{"t":1538663183,"v":"61.20"},
"TEMP_EAST_CHIMNEY_HIGH":{"t":1538663183,"v":"71.96"},
"HUM_WEST_CHIMNEY_LOW":{"t":1538663183,"v":"72.40"},
"TEMP_WEST_CHIMNEY_LOW":{"t":1538663183,"v":"71.42"},
"HUM_WEST_CHIMNEY_HIGH":{"t":1538663184,"v":"60.90"},
"TEMP_WEST_CHIMNEY_HIGH":{"t":1538663184,"v":"72.50"},
"HUM_GREENHOUSE_LOW":{"t":1538663185,"v":"60.50"},
"TEMP_GREENHOUSE_LOW":{"t":1538663185,"v":"73.94"},
"HUM_MEZZANINE":{"t":1538663185,"v":"61.80"},
"TEMP_MEZZANINE":{"t":1538663185,"v":"73.58"},
"HUM_GREENHOUSE_HIGH":{"t":1538663186,"v":"60.00"},
"TEMP_GREENHOUSE_HIGH":{"t":1538663186,"v":"73.40"}
}