|
Joined: Jan 2015
Posts: 10
Pikka bird
|
OP
Pikka bird
Joined: Jan 2015
Posts: 10 |
Hi all, perhaps there is somebody out there, who knows a lot more about API then I. I want to read API data from Telemachus, it's an Kerbal Space Program Mod: https://github.com/richardbunt/Telemachus/wiki/HTTP-APIhttps://github.com/richardbunt/Telemachus/wiki/Web-Socket-APIHere is the Adress I want to querry: http://127.0.0.1:8085/telemachus/datalink?a=v.altitude and the result in my webbrowser is: {"a":80.1083426593104} Why do I want that? Well, I'd like to have my mirc bot monitor the altitude and at a certain hight speak to me, via the /speak command. My main problem right now is, how do I access that value? Once I know how to access one, I can access all others. Thanks.
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
Install this, a JSON parser: http://hawkee.com/snippet/10194/once you have this installed, it's pretty simple: alias checkit {
JSONOpen -du hight http://127.0.0.1:8085/telemachus/datalink?a=v.altitude
echo -a $json(hight,a)
} This is untested of course, and the code isn't checking for errors.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2015
Posts: 10
Pikka bird
|
OP
Pikka bird
Joined: Jan 2015
Posts: 10 |
Hey Wims, thanks for the answer... it works, but (!) only once. The values on the api change, but in mirc the output is still the same it gave me when I executed the command for the 1st time.
When I restart mirc, and execute the command again, it picks up the current value, and from there on continues to display it untill I restart the program again.
Any idea where the problem could be now?
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
Sure, the COM object used by the JSON parser caches the results, adds "&nocache= $+ $ticks" to the url: JSONOpen -du hight http://127.0.0.1:8085/telemachus/datalink?a=v.altitude&nocache= $+ $ticks
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2015
Posts: 10
Pikka bird
|
OP
Pikka bird
Joined: Jan 2015
Posts: 10 |
Sadly, that did not help:
* /echo: insufficient parameters
When I use the URL in my webbrowser, it tells me:
Internal Server Error 500 Bad data link reference.
Is there any other way to clear the cache?
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
Well I just tried it and it works for me.
You can't just put that in your browser because it won't understand $+ $ticks, try to use &nocache=0 directly in your browser, it should work.
Last edited by Wims; 05/01/15 10:42 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2015
Posts: 10
Pikka bird
|
OP
Pikka bird
Joined: Jan 2015
Posts: 10 |
url + &nocache=0 directly in browser is also an error.
I guess going over sockets (sockets write, read etc.) and away from JSON wouldn't help any, would it? It's not reading API then, but reading websites and understand their content, right?
After all, it's just 1 line of information that I want to read out. And sofar, we can read it, but only once.
The only other alternative is to go over visual basic script, where the constand reading of the url does work (I've tested it there first). The big problem with VBS is data exchange between it and mirc. That would only work over .txt files, which I wanted to avoid useing a direct methode from mirc.
|
|
|
|
Joined: Jan 2004
Posts: 1,330
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 1,330 |
Maybe his service throws an error when there's an unknown parameter, however that's a workaround anyhow. The problem is that MSXML.XmlHttpRequest has poor cache control, to correct this you can use a different object which has no cache at all.
On line 11/12 change 'MSXML2.XMLHTTP.6.0' to 'MSXML2.SERVERXMLHTTP.6.0'; I can't speak to what other functional changes this may cause.
|
|
|
|
Joined: Jul 2006
Posts: 4,020
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,020 |
Likely but that hawkee page for the JSON parser has comments, one of them talks about the cache issue and the author, suggested to use &nocache= so I'm just relaying the information. I know the author had to change the object already to be able to support utf8 so I didn't want to suggest to use a different object because it is likely that the OP doesn't know much about COM and/or I agree, as you said, that it will require more than changing the object's name. @Mandarb: Using socket wouldn't change anything, you would be able to send the Cache-control header, but you can send it as well with this JSON parser, look at the documentation for more information, here is an example with a dropbox url: //jsonopen -dwu test https://dl.dropboxusercontent.com/u/4249275/json_test.txt | jsonurloption test Cache-Control no-cache | jsonget test | echo -a $json(test,test)
Last edited by Wims; 05/01/15 11:49 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2004
Posts: 1,330
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 1,330 |
My server must have been/is misconfigured as the Cache-Control header was not mirrored in the response when I tested the same header earlier, forcing my server response to include the no-cache did cause the activex object to request the file anew.
|
|
|
|
Joined: Jan 2015
Posts: 10
Pikka bird
|
OP
Pikka bird
Joined: Jan 2015
Posts: 10 |
On line 11/12 change 'MSXML2.XMLHTTP.6.0' to 'MSXML2.SERVERXMLHTTP.6.0'; I can't speak to what other functional changes this may cause. It works!!! Yeah, from here I hope/think I'll find my way alone. Many thanks.
|
|
|
|
Joined: Apr 2010
Posts: 964
Hoopy frood
|
Hoopy frood
Joined: Apr 2010
Posts: 964 |
Im the author of the JSON script. I meant for most of the XHR objects to be SERVERXMLHTTP, sorry about that. I have updated it, fixing a few issues that have been spotted. With the updated version, this should work, without the result being cached: alias checkit {
JSONOpen -duw height http://127.0.0.1:8085/telemachus/datalink?a=v.altitude
JSONURLOption height Cache-Control no-cache
JSONGet height
echo -a $json(height,a)
}
Last edited by FroggieDaFrog; 07/01/15 11:14 AM.
|
|
|
|
|