…ring). Signed-off-by: Nick D'Ademo <firstname.lastname@example.org>
EthernetClient will stay connected() as long as data is available(), but WiFiClient() can switch to !connected() while there are still data unread in its buffer and therefore available(). Therefore, let's check for available() when reading data rather than connected().
The original parser does not cope gracefully with input that is not proper json. Try sending "Hi there" to any of the library examples and see the results. This commit adds two things: - the "getch" method now times out after 500ms. This removes the situation whereby the parser got often stuck waiting forever on malformed input. - A new "flush" method is added, because the parser leaves the input buffer untouched in case it cannot understand the contents, which means that it will get stuck forever again trying to parse the same input if we try several times.
Currently, the aJson library uses FILE* avr-libc streams, which does not play well with the Arduino ecosystem. We introduce a new class aJsonStream (plus two subclasses aJsonClientStream and aJsonStringStream) that use the Wiring Stream object. This allows to easily exchange JSON data e.g. over Serial and EthernetClient. An accompanying example Json_Serial shows how to use this functionality to send and receive JSON data over Serial.