Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you create a very simple sketch that follows the filtering example described in the readme? #48

Open
rkertesz opened this issue Jul 23, 2013 · 12 comments

Comments

@rkertesz
Copy link

I will be the first to admit that I am not a strong programmer in C/C++. I could really use an example sketch that uses the "Filtering while parsing" method described in the README.md file. It would help me through the following problem

I was getting an error while compiling that the "scalar object requires one element in initializer". To my understanding, the use of the char** is a pointer to a pointer but I honestly don't know what is needed to initialize this correctly:
char** jsonFilter = {"name,"format","height","width",NULL};

Also of note, there is a missing close quote after {"name in the README file.

@rkertesz
Copy link
Author

I posted to pastebin here.
http://pastebin.com/naF0C6sn

@rkertesz
Copy link
Author

This is slightly different from the parsing example. The parsing example doesn't do any filtering from what I can tell. I want to use the filtering method to manipulate only the pieces of information I need from the tree rather than store the whole string response and then also store the whole tree before parsing. I thought that the filtering example in the read me was designed to reduce the memory load. I thought that the code for filtering, combined with the code for streaming would allow me to dump the information that I don't need rather than store it, saving me space.

@sudar
Copy link
Contributor

sudar commented Jul 30, 2013

@I8P Yeah, I realized it as soon as I replied. That's why I removed my comment.

Give me a couple of days, I will try it out and get back with a working example.

@sjunnesson
Copy link

does the above pastebin compile for you? Im getting the below error when I just do a straight copy paste from the bin

sketch_aug22a.ino: In function 'char* parseJson(char*)':
sketch_aug22a:63: error: scalar object 'jsonFilter' requires one element in initializer

@epiccoolguy
Copy link

If I have the following response and store it for parsing:

{
    "sensor": {
        "id": "418143",
        "name": "analogpin0",
        "type": "0",
        "device_type": "Pressure Sensor",
        "data_type_id": "35501",
        "pager_type": "",
        "display_name": "Analog Pin A0",
        "use_data_storage": true,
        "data_type": "json",
        "data_structure": "{\"value\":\"Integer\"}"
    }
}

Shouldn't the following work?

char** jsonFilter = (char*[]) {"sensor","id","display_name",NULL};

Explanation I found here: http://compsci.ca/v3/viewtopic.php?p=223745#223745

aJson.h only has the following functions though:

parse(aJsonStream*)
parse(aJsonStream*, char**) // This one should be able to use a filter
parse(char*)

According to the header file you will need a stream in order to use a filter. I haven't gotten a http client working with streams (yet) so I'm not able to test this.

If this isn't correct, please let me know. I'm still learning about C and the Arduino ecosystem.

@rkertesz
Copy link
Author

@sjunnesson that is correct. I was not able to compile it. I am looking for help in determining why it doesn't work. Novice here.

@rkertesz
Copy link
Author

@epiccoolguy My JSON response is too large to store and then search. That is why I need to use streaming to look for the information as it is being streamed. When you say you haven't set up an http client to stream, do you mean that I something has to be done to a json stream before sending it to the arduino? Why use ajson if you use a computer in T&E first place?

@epiccoolguy
Copy link

@I8P Not a json stream, aJsonStream is a class defined in this library.

Have you looked at how the EthernetClient examples on the Arduino Playground work?
I would recommend looking at how the (Arduino) Streams, the Ethernet library and this library work.

You need to feed parse(aJsonStream* stream, char** filter) an aJsonStream* together with a filter in order to get the data from the response without buffering the entire response.
Looking at the header file, there's an object which inherits aJsonStream and accepts a Stream (such as Serial, EthernetClient) as parameter:

/* JSON stream that consumes data from a connection (usually
 * Ethernet client) until the connection is closed. */
class aJsonClientStream : public aJsonStream {
public:
    aJsonClientStream(Client *stream_)
        : aJsonStream(NULL), client_obj(stream_)
        {}

Try passing this constructor the client you're using to receive the data and then pass that aJsonClientStream to parse(aJsonStream* stream, char** filter).

I can't remember what I've tried myself. I gave up eventually on using additional libraries since they were also massive (example sketch size 90%) and instead used string.h functions to parse http responses.

This library would've worked nice in combination with interactive-matter/HTTPClient, but both are kind of abandoned and HTTPClient is still using C-style streams while aJson has been updated for use with Arduino style streams.

@rkertesz
Copy link
Author

Thank you! ... It does seem like they are not in development. I am trying to see if I can parse the data using a Yun instead. More memory etc. I'll have to dig into Linux tools to do so I think.

I8P

On Oct 14, 2013, at 6:09 PM, Miguel Lo-A-Foe [email protected] wrote:

@I8P Not a json stream, aJsonStream is a class defined in this library.

Have you looked at how the EthernetClient examples on the Arduino Playground work?
I would recommend looking at how the (Arduino) Streams, the Ethernet library and this library work.

You need to feed parse(aJsonStream* stream, char** filter) an aJsonStream* together with a filter in order to get the data from the response without buffering the entire response.
Looking at the header file, there's an object which inherits aJsonStream and accepts a Stream (such as Serial, EthernetClient) as parameter:

/* JSON stream that consumes data from a connection (usually

  • Ethernet client) until the connection is closed. /
    class aJsonClientStream : public aJsonStream {
    public:
    aJsonClientStream(Client *stream
    )
    : aJsonStream(NULL), client_obj(stream_)
    {}
    Try passing this constructor the client you're using to receive the data and then pass that aJsonClientStream to parse(aJsonStream_ stream, char** filter).

I can't remember what I've tried myself. I gave up eventually on using additional libraries since they were also massive (example sketch size 90%) and instead used string.h functions to parse http responses.

This library would've worked nice in combination with interactive-matter/HTTPClient, but both are kind of abandoned and HTTPClient is still using C-style streams while aJson has been updated for use with Arduino style streams.


Reply to this email directly or view it on GitHub.

@lyssbach
Copy link

I am having exactly the same issue when initating the filter string for my program to process the JSON feed from Yahoo.

initialize the filter:
char** jsonFilter = (char *[]) {"query","results","channel","item","condition","text",NULL};

error from Arduino IDE (both 1.0.5 and 1.5.5)
GetYahooWeather:222: error: no matching function for call to 'aJsonClass::parse(char_&, char__&)'
C:\Users\why\Documents\Arduino\libraries\aJson/aJSON.h:179: note: candidates are: aJsonObject_ aJsonClass::parse(aJsonStream_)
C:\Users\why\Documents\Arduino\libraries\aJson/aJSON.h:180: note: aJsonObject_ aJsonClass::parse(aJsonStream_, char__)
C:\Users\why\Documents\Arduino\libraries\aJson/aJSON.h:181: note: aJsonObject_ aJsonClass::parse(char*)

Really like to have an example to understand the filter usage. Thanks.

@atoudam
Copy link

atoudam commented Jan 20, 2014

@I8P did you end getting the filtering / stream running? as im working on something similar at the moment

@djMax
Copy link

djMax commented Oct 13, 2014

I don't see any evidence that the filter is used anywhere in the json parser code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants