[API] SamyGO web API

Here are software that related with Samsung H series TVs.
Please don't create any new topic here unless you have software to post/release.

mad_ady
SamyGO Project Donor
Posts: 268
Joined: Sun May 03, 2015 10:42 am

[API] SamyGO web API

Post by mad_ady »

I've developed a simplified API to interact with some common libraries that run on SamyGO (B/C/D/E/H) and I'm releasing it to the community, for tests, ideas and improvements :)

You can get it here:
https://github.com/mad-ady/samygo-web

SamyGO web API

The Web API exposes some of SamyGO's plugins to external clients. The API tries to return data in json format where possible, but uses image/jpg for screenshots.

Features:
  • Get TV State and current program details via libLogChannel
  • Control the TV via samyGOrc with remote actions
  • Reboot the TV
  • Get a screenshot of what is on the screen via libScreenShot
  • Start a widget via libRunWidget
  • Display an onscreen message via libAlert
  • Compatibility with libSoftPowerOff (viewtopic.php?t=8987&start=230)
Dependencies:
Installation:

Download to your rooted SamyGO TV:

Code: Select all

cd /tmp
curl -k https://codeload.github.com/mad-ady/samygo-web/zip/master > samygo-web-api.zip
Unzip

Code: Select all

unzip samygo-web-api.zip
Run the installation script:

Code: Select all

./samygo-web-master/installer.sh
LibSoftPowerOff coexistence:
If you have libSoftPowerOff enabled in your TV and you use the screenshot functionality, in order not to inject the screenshot command when the display is off you can signal that the TV is in soft-off mode by configuring libSoftPowerOff.so to run two scripts on power on/off. When you load the libSoftPowerOff library, use the following options:

Code: Select all

CMD_ON:/mnt/scripts/onPowerOn.sh CMD_OFF:/mnt/scripts/onPowerOff.sh 
The onPowerOn.sh/onPowerOff.sh scripts (among other functionality) should set a flag by creating a file called

Code: Select all

/dtv/tvIsSleeping
:
  • onPowerOn.sh: rm -f /dtv/tvIsSleeping
  • onPowerOff.sh: touch /dtv/tvIsSleeping
If you don't use libSoftPowerOff, the TV powers off and the web API is no longer accessible.

Startup
:

Code: Select all

/mnt/etc/init.d/99_99_samygo_web_api.init start
On first run the startup script will generate a unique challenge which will be printed by the startup screen. This challenge is generated in

Code: Select all

/mnt/etc/samygo-web-api.challenge
. You will need to supply this challenge string on all requests. The security is equivalent to HTTP Simple Auth and should protect you against somebody scanning your system, but will not protect you from a man-in-the middle attack! Also, don't use over unencrypted internet!

API Usage
:

to get the current information, request for action=CHANNELINFO:

Code: Select all

$ wget -O - "http://tv-ip:1080/cgi-bin/samygo-web-api.cgi?challenge=oyd4uIz5WWAkWPo5MzfxBFraI05C3FDorSPE7xiMLCVAQ40a&action=CHANNELINFO"

{"source":"TV (0)","pvr_status":"NONE","powerstate":"Normal","tv_mode":"Cable (1)","volume":"9","channel_number":"45","channel_name":"Nat Geo HD","program_name":"Planeta dezastrelor","resolution":"1920x1080","error":false}
to reboot TV request for action=REBOOT:

Code: Select all

$ wget -O - http://tv-ip:1080/cgi-bin/samygo-web-api.cgi?challenge=oyd4uIz5WWAkWPo5MzfxBFraI05C3FDorSPE7xiMLCVAQ40a&action=REBOOT
to send key events request for action=KEY and key=KEY_1:

Code: Select all

$ wget -O - http://tv-ip:1080/cgi-bin/samygo-web-api.cgi?challenge=oyd4uIz5WWAkWPo5MzfxBFraI05C3FDorSPE7xiMLCVAQ40a&action=KEY&key=KEY_1

{"error":false,"message":"Sent key 4"}
The list and codes of supported keys are available inside the script in the $KEYS array: https://github.com/mad-ady/samygo-web/b ... eb-api.cgi

to get a snapshot from the TV request for action=SNAPSHOT:

Code: Select all

$ wget -O /tmp/image.jpg http://tv-ip:1080/cgi-bin/samygo-web-api.cgi?challenge=oyd4uIz5WWAkWPo5MzfxBFraI05C3FDorSPE7xiMLCVAQ40a&action=SNAPSHOT
to run a widget on your TV request for action=WIDGET&name=YouTube (name is case-sensitive):

Code: Select all

$ wget -O - http://tv-ip:1080/cgi-bin/samygo-web-api.cgi?challenge=oyd4uIz5WWAkWPo5MzfxBFraI05C3FDorSPE7xiMLCVAQ40a&action=WIDGET&name=YouTube
to display an onscreen message use action=ALERT&message=This+is+a+test&type=CENTER. You can also use blinks=4&delay=1000 to blink for 4 seconds:

Code: Select all

$ wget -O - http://tv-ip:1080/cgi-bin/samygo-web-api.cgi?challenge=oyd4uIz5WWAkWPo5MzfxBFraI05C3FDorSPE7xiMLCVAQ40a&action=ALERT&type=CENTER&message=This+is+a+test
Real world applications examples: Integrating your TV into Home Assistant: viewtopic.php?f=79&t=11882
Last edited by mad_ady on Tue Jun 05, 2018 10:08 am, edited 3 times in total.
H6400, firmware 2602.2 downgraded to 2130
User avatar
lekron
SamyGO Project Donor
Posts: 40
Joined: Thu Apr 28, 2016 12:59 pm
Location: Germany

Re: [API] SamyGO web API

Post by lekron »

Nice project man!
UE40H6740 T-MST2130
UE40MU6179 T-KTM1145.0
mad_ady
SamyGO Project Donor
Posts: 268
Joined: Sun May 03, 2015 10:42 am

Re: [API] SamyGO web API

Post by mad_ady »

I accept push requests for bug fixes or new features. Also, from what I've read the functionality exists also on tizen TVs, but with different APIs. If somebody can give me shell access to their J+ tv (or at least some outputs), I can update the API as well.
H6400, firmware 2602.2 downgraded to 2130
User avatar
prairie
SamyGO Project Donor
Posts: 303
Joined: Wed May 04, 2011 10:30 pm

Re: [API] SamyGO web API

Post by prairie »

I tested this on F-series for fun and works nicely with CHANNELINFO and REBOOT. SNAPSHOT returns a 0 length file (lib works ok on TV)

Code: Select all

Connecting to 192.168.0.15:1080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 0 [image/jpeg]
Saving to: ‘STDOUT’
PN60F8500AFXZA
T-FXPAKUC 1206.3 + SamyGO

"BrickMaster 2015"
mad_ady
SamyGO Project Donor
Posts: 268
Joined: Sun May 03, 2015 10:42 am

Re: [API] SamyGO web API

Post by mad_ady »

Ok, can you tell me what parameters you use to get a screenshot on your TV? The parameters I used are for H series and may differ.

Also, does cjpeg run on your TV?
H6400, firmware 2602.2 downgraded to 2130
User avatar
prairie
SamyGO Project Donor
Posts: 303
Joined: Wed May 04, 2011 10:30 pm

Re: [API] SamyGO web API

Post by prairie »

Hi

For screenshot I have a key mapped to:

Code: Select all

samyGOso -d -A -B -l /mnt/opt/privateer/usr/libso/libScreenShot.so PATH:/mtd_rwcommon/Screenshots ALERT SOURCE ALT
output of "cjpeg":

Code: Select all

cjpeg: error while loading shared libraries: libjpeg.so.62: cannot open shared object file: No such file or directory
I can find libjpeg.so, libjpeg.so.8, and libjpeg.so.8.0.2 at /mtd_exe/Runtime/lib/
PN60F8500AFXZA
T-FXPAKUC 1206.3 + SamyGO

"BrickMaster 2015"
mad_ady
SamyGO Project Donor
Posts: 268
Joined: Sun May 03, 2015 10:42 am

Re: [API] SamyGO web API

Post by mad_ady »

Ok, I'll look into it. Can libScreenShot create jpeg screenshots on your system? On mine it crashes the TV, so that's why I had to use cjpeg.
H6400, firmware 2602.2 downgraded to 2130
zoelechat
SamyGO Moderator
Posts: 8615
Joined: Fri Apr 12, 2013 7:32 pm
Location: France

Re: [API] SamyGO web API

Post by zoelechat »

mad_ady wrote: Mon Oct 30, 2017 3:11 pm Can libScreenShot create jpeg screenshots on your system? On mine it crashes the TV
Even using ALT switch?

...or if you need static cjpeg maybe?
I do NOT receive any PM. Please use forum.
User avatar
prairie
SamyGO Project Donor
Posts: 303
Joined: Wed May 04, 2011 10:30 pm

Re: [API] SamyGO web API

Post by prairie »

mad_ady wrote: Mon Oct 30, 2017 3:11 pm Ok, I'll look into it. Can libScreenShot create jpeg screenshots on your system? On mine it crashes the TV, so that's why I had to use cjpeg.
Thanks and yes but only using ALT method. This was best method for my TV though I can't remember what the problem with bmp's was.
PN60F8500AFXZA
T-FXPAKUC 1206.3 + SamyGO

"BrickMaster 2015"
mad_ady
SamyGO Project Donor
Posts: 268
Joined: Sun May 03, 2015 10:42 am

Re: RE: Re: [API] SamyGO web API

Post by mad_ady »

zoelechat wrote:
mad_ady wrote: Mon Oct 30, 2017 3:11 pm Can libScreenShot create jpeg screenshots on your system? On mine it crashes the TV
Even using ALT switch?

...or if you need static cjpeg maybe?
Sadly yes, even with ALT switch. I will look into cjpeg dependency as well, but if the library already produces jpegs, it shouldn't be needed.
H6400, firmware 2602.2 downgraded to 2130

Post Reply

Return to “[H] Software”