Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Retrieving json data through Web Server/API commands


EnriqueR Aug 4, 2014 01:18 PM

Hi,

I'm trying to retrieve records from a table in a CR1000 datalogger. I'm using HTTP protocol and issue a command as described in the Web Server/API Commands reference in the help of the CRBasic Editor.

While urls like:

http://<loggerip/?command=dataquery&uri=dl:table1&format=html&mode=most-recent&p1=40

gives me the most recent 40 records from table1 and the same is true for the xml format, but it works different with json format. If I ask (p1=n) for the n most recent records in the table with n>32, I get a json structure with the first 32 pieces of "data" in the batch and an adicional json atribute/value pair of '"more": true"'

¿How can I access to all the data in json format making only one request, like with html and xml formats? I would prefer to obtain data in json format than in xml or html to easily parse it.

I can't find any clue in the documentation about this.

Regards,

Enrique

* Last updated by: EnriqueR on 8/5/2014 @ 2:03 AM *


GaryTRoberts Aug 5, 2014 11:09 PM

Enrique,

The JSON format is used by published projects (RTMC) to get real-time data from the datalogger directly. Early on, we ran into issues where the XMLHttpRequests from RTMC were timing out or taking extraordinarily long times when there was a large data set associated with the query. We addressed this only for the JSON format by adding the more flag at the end of the returned object and letting the datalogger cut off the response after a certain amount of time.

So to get around this, one can either query the datalogger more often asking for a smaller subset (http://loggerip/?command=dataquery&uri=dl:table1&format=html&mode=most-recent&p1=20) or programming for the "more": true and when seen, ask the datalogger to respond with the missing data. For example, I did the API request listed above in your example and received records 0 through 32 plus the "more":true. Now I only want the newer ones starting at record 33:
http://loggerip/?command=dataquery&uri=dl:table1&format=html&mode=since-record&p1=33

I hope this answers your question.

-Gary


EnriqueR Aug 6, 2014 09:59 AM

Gary,

Thanks for your clear explanation. Now I understand the origin of this difference with the other formats and I think it's a great solution. I now know that it's a consistent behaviour and can program with the presence of the more=true "flag" in mind to complete the needed data with new requests when necessary.

Thank you!

Enrique


GTProdMgr Aug 6, 2014 04:24 PM

See the note on page 15 of the CSI Web Server Manual:
http://s.campbellsci.com/documents/us/manuals/csi-web-server.pdf

Log in or register to post/reply in the forum.