Screenly Forum

API calls from Screenly or other software (screen synchronising)

Hi all those who are smarter than me (or at least know screenly better)

I used Screenly in the past (still have 1 screen running it continuously) but as I read a while back about the API call possibility in the newer Screenly, it became really interesting to me to use Screenly again for an upcoming project.

I want to hang 3 screens side by side that ‘interact’ with eachother. I want to be able to stretch a single message over the 3 screens, only to have them do their own thing afterwards. (i.e. have an image (5760x1080) cut in 3 parts, and have each of the 3 pi’s the image-part that corresponds to their location in the row of screens).

As far as I can gather from the doc’s, it is now easy to do an API call to all three screens to imediatly activate the asset in question and create the illusion of a single message.

Now I need to make that API call to each of the three screens. I have thought of 3 options for now:

  • Have a seperate Pi that runs some software that does the api-calls at the intervals wanted. I must be able to alter the settings from anywhere in the world, with any device. (I was thinking domoticz with dzvents actions. p.s. I only know Screenly as taking the whole OS, but I might try to install domoticz or a better program on one of the pi’s running screenly, thus no need for a 4th pi after all)
  • Have cron instructions on one of the three pies, that does the API calling. (This however is not really easy to change if you’re on the road and have only your smartphone to change the settings.)
  • Have the first Pi’s screenly send a API call to the second Pi (and the second Pi to the third pi) as soon as it is about to load the asset. (Easiest and cheapest solution, but as far as I know, Screenly does not support doing an Api-call upon loading an asset)

As I am most likely not the first to use multiple screens side by side and have them synchronised on occasion, I wonder what others have done to do so.

[EDIT]
p.s. Just thought of a fourth option. I do not yet know how to implement it exactly, but as I remember, I can call a web-page from screenly. What if I would set up a web-server on the first of the three pi’s, next to screenly. I then might have the 1st screenly having one asset that calls a web-page on the same pi, that webpage in turn would just do 3 API-calls, thus also would straight away remove its own focus as screenly now got the command to show the asset it needed to display in the first place, along with its 2 neighbours.

As nobody apparently knows how to do this, I got my own pi and a new SD card to try it out. I think I have found a good way to do it, so I post it here for others to use.

I created a script called start02.sh and put it in a “script” directory under my home directory:

#!/bin/bash

declare -a devicelist # Creates mandatory list of devices
declare -a assetlist0 # For each device a list must be created, start with 0
declare -a assetlist1 # Not enough lists will crash the script, extras wont

# ONLY ALTER BELOW THIS

devicelist=(“192.168.1.163”) # All IP addresses of the Screenly devices
assetlist0=(fa8370d3acf040c3a8c6df6d29b291f0) # First item is shown every time
assetlist0+=(5f568543703f4fccbc4d39d2250b48c8) # Additional items shown to the max of maxassets
assetlist0+=(fc8885a5f15d430b9beff09bb5a558d1) # When less items, the call will be ignored for those

maxassets=3 # What is the max number of additional items?
sleeptime=45 # Delay before showing the additional asset?
minuteseparation=1 # How often is this script called (once per X minutes}

# ONLY ALTER ABOVE THIS

function docall {
assetnr=$2
totaldevices=${#devicelist[*]}
for (( listnr=0; listnr<=$(( $totaldevices -1 )); listnr++ ))
do
active=assetlist${listnr}[${assetnr}]
activeasset=${!active}
if [ ! -z $activeasset ]; then
docurl=“http://${devicelist[$listnr]}/api/v1/assets/control/asset&${activeasset}”
curl $docurl &> /dev/null
fi
done
}

minutes=$(date +%M)
let minutes=${minutes}/${minuteseparation}
let assetcall=${minutes}%${maxassets}
let assetcall+=1

docall 0 0
sleep $sleeptime
docall 0 $assetcall

Then I altered the cron-file with “sudo crontab -e” and added

*/1 * * * * /home/pi/scripts/start02.sh &

Now I have my main screens showing every minute on the minute, and after 45 seconds it shows a screen with additional information for 15 seconds.

USAGE:
I use this for a snackbar (small restaurant, more like fish & chips but with a much larger selection). In the final set up I have 3 screens to show all the items one can order. So I intend to show the largest part of the list spread out over 3 screens, at the top of the minute. After 45 seconds it can either show the items that are not on the main list (like drinks, special menu’s, etc), but I can also advertise a special menu item, spreading out over the 3 screens. It may even advertise a third party event in this way.

The only places to alter anything is between the two lines stating this, with one exception. This set-up is ready for 2 screens, but when you need more, then you need to create aditional lines of “declare -a assetlist {+ number}” just above this block.

Within the block:

  • Add your local IP addresses to the divicelist
  • Fill the assetlist for each device (starting with 0). This can be done on one line, but for clarity and possibility to easily add and alter, I separated the items to have a row each. The first item is the main item and will be shown each time.
  • State the maximum amount of assets for one screen. When a screen has less assets, there will not be a call (thus the main screen should stay on)
  • The sleeptime defines how much time between the main-screen call and the other assets call. In this case 45 seconds
  • Minuteseperation is currently set to 1, stating I will call this script once every minute. When you set this different in the crontab, change it here aswell.

Within Screenly, you can have all assets set to OFF. Only have a single asset (company logo?) to be shown when other assets are not loaded (i.e. when booting or when the cron fails). All the other assets should have a long enough duration to be shown, even when the next asset fails (I set it to 1000 seconds for each asset)

Good luck with it!

Thanks for sharing @Marque1968!