Daverz wrote:
> This is a nice little module. It would have saved me a lot of trouble
> messing with the telnet interface if I'd known about it earlier.
>
> BTW, the requests module makes JSON even easier to deal with (at the
> cost of an external dependency). It's just
>
Yes, it's sometimes confusing that there's so much outdated information
out there. I also started with Telnet using a Perl script, but got very
frustrated with that.. Main issue with Telnet is that the responses get
confused if you send too many messages at the same time... Then I also
used LMSTools for a while, but also found that a bit frustrating and
complicated. Simply using JSON (in Python or in Shell scripts) is way
easier, but the info is much harder to find..
In Python, for more complicated stuff, I use Request. Example (count
players):
Code:
--------------------
import requests
def countplayers():
data = '{ "id": 1, "method": "slim.request", "params": ["", ["player",
"count", "?"]]}'
try:
response = requests.get(ServerLMS, data=data).json()['result']['_count']
except: response = 0
return response
--------------------
Other example (all players on):
Code:
--------------------
def powerplayerson():
for EachPlayer in Players:
try:
data = '{ "id": 1, "method": "slim.request", "params":["'+EachPlayer+'",
["power", 1]]}'
requests.post(ServerLMS, data=data)
--------------------
In a Shell script, for simple scripting on pCP without installing
Python, I use Curl. Example (->lmsjson.sh var1 var2-):
Code:
--------------------
LMSIP=$(netstat -nt 2>&1 | grep :3483 | grep ESTABLISHED | uniq -f 4 | awk
'{ print $5 }' | grep :3483 | awk -F: '{ print $1 }')
MAC=aa.bb.cc.dd.ee
command='{"id": 1, "method": "slim.request", "params":["'$MAC'", ["'$1'",
"'$2'", "'$3'"]]}'
eval "curl -X POST -d '"$command"' "$LMSIP":9000/jsonrpc.js"
--------------------
------------------------------------------------------------------------
jeroen2's Profile: http://forums.slimdevices.com/member.php?userid=70418
View this thread: http://forums.slimdevices.com/showthread.php?t=107209
_______________________________________________
diy mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/diy