mIRC Home    About    Download    Register    News    Help

Print Thread
#250200 05/01/15 10:59 AM
Joined: Jan 2015
Posts: 10
M
Mandarb Offline OP
Pikka bird
OP Offline
Pikka bird
M
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-API

https://github.com/richardbunt/Telemachus/wiki/Web-Socket-API

Here 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.

Mandarb #250204 05/01/15 04:36 PM
Joined: Jul 2006
Posts: 4,153
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,153
Install this, a JSON parser: http://hawkee.com/snippet/10194/

once you have this installed, it's pretty simple:

Code:
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
Wims #250206 05/01/15 06:44 PM
Joined: Jan 2015
Posts: 10
M
Mandarb Offline OP
Pikka bird
OP Offline
Pikka bird
M
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?

Mandarb #250207 05/01/15 06:58 PM
Joined: Jul 2006
Posts: 4,153
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,153
Sure, the COM object used by the JSON parser caches the results, adds "&nocache= $+ $ticks" to the url:

Quote:
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
Wims #250208 05/01/15 07:31 PM
Joined: Jan 2015
Posts: 10
M
Mandarb Offline OP
Pikka bird
OP Offline
Pikka bird
M
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?

Mandarb #250218 05/01/15 10:39 PM
Joined: Jul 2006
Posts: 4,153
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,153
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
Wims #250221 05/01/15 11:21 PM
Joined: Jan 2015
Posts: 10
M
Mandarb Offline OP
Pikka bird
OP Offline
Pikka bird
M
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.

Wims #250222 05/01/15 11:22 PM
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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.

Loki12583 #250224 05/01/15 11:40 PM
Joined: Jul 2006
Posts: 4,153
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,153
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:

Code:
//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
Wims #250228 06/01/15 12:14 AM
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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.

Loki12583 #250238 06/01/15 08:54 AM
Joined: Jan 2015
Posts: 10
M
Mandarb Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Jan 2015
Posts: 10
Originally Posted By: Loki12583
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.

Mandarb #250268 07/01/15 09:52 AM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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:
Code:
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.

I am SReject
My Stuff

Link Copied to Clipboard