Search code examples
json-rpc

send json commands with bash to boxeebox


I'm trying to get my callerid script to send a notification to my boxee box connected tv. I've got the script working using mgetty and notify-send on a couple of my computers.

here is my cidscript.sh which gets triggered by mgetty

#!/bin/sh

# send message to computer
ssh -o ConnectTimeout=10 [email protected] "DISPLAY=:0 notify-send 'Phone call from...      $CALLER_NAME      $CALLER_ID'" &
sleep 0.2
ssh -o ConnectTimeout=10 [email protected] "DISPLAY=:0 notify-send 'Phone call from...      $CALLER_NAME      $CALLER_ID'" &
sleep 0.2
ssh -o ConnectTimeout=10 [email protected] "DISPLAY=:0 notify-send 'Phone call from...      $CALLER_NAME      $CALLER_ID'" &
sleep 0.2
su mrplow -c "DISPLAY=:0.0 notify-send 'Phone call from...      $CALLER_NAME      $CALLER_ID'" &
sleep 5

# update logs
echo `date +"%F %a %r"`"|$CALLER_ID|$CALLER_NAME" >> /home/mrplow/answering_machine/logs/incoming-calls.log
scp -o ConnectTimeout=10 /home/mrplow/answering_machine/logs/incoming-calls.log [email protected]:/home/christine/Desktop/incoming-calls.log

sleep 0.2

exit 1

I think json rpc is going to be the only way to get this to work I've managed to telnet into the boxee box on raw port 9090 then paired my device

so the script will need to send the connect command

{"jsonrpc": "2.0", "method": "Device.Connect", "params":{"deviceid": "############"}, "id": 1}

then the actual notification

{"jsonrpc": "2.0", "method": "GUI.NotificationShow", "params":{"msg" : "Phone call from...      $CALLER_NAME      $CALLER_ID"}, "id": 1}

I tried this to no avail

curl -d '{"jsonrpc": "2.0", "method": "Device.Connect", "params":{"deviceid": "00112fa696c9"}, "id": 1}\
{"jsonrpc": "2.0", "method": "GUI.NotificationShow", "params":{"msg" : "test"}, "id": 1}' -i 192.168.1.6 9090

Solution

  • figured it out...

    echo { \"jsonrpc\": \"2.0\", \"method\": \"Device.Connect\", \"params\":{\"deviceid\": \"############\"}, \"id\": 1}\
    { \"jsonrpc\": \"2.0\", \"method\": \"GUI.NotificationShow\", \"params\":{\"msg\" : \"Phone call from...      $CALLER_NAME      $CALLER_ID\"}, \"id\": 1 } | telnet 192.168.1.6 9090 &> /dev/null