Hope you can shed some light on this for me. I have created a module, that uses an API to retrieve some data.
The token to communicate with this API is stored in the database.
When my module loads, I retrieve the token from database, and generate some HTML + CSS. This works all great in the preview Layout screens.
However when this Layout loads on my remote Xibo devices, I see the following errors in the log:
[errormsg]mysql_query() expects parameter 2 to be resource, null given[/errormsg]
[errornum]2[/errornum]
[errortype]Warning[/errortype]
[scriptname]/home/samsonit/public_html/…/…/modules/module_db_mysql.php[/scriptname]
[scriptlinenum]67[/scriptlinenum]
My guess is that the Xibo devices cannot make a database connection? Can anyone enlighten me on this subject? Should I choose another approach?
Another question. I’m using CMS 1.7.9.
In the module the constructor receives a “database $db” variable. This is the one I am using. However, I see that the parent Module class (“module.class.php”) uses the $dbh = PDOConnect::init(); database handler.
You’re using Xibo Player 1.6? The Xibo players don’t have direct access to the CMS database. You need to make a web call at the least. I’m not sure what you’re doing exactly so without more ‘code’ it will be hard to see where you’re going wrong. For the second question variable names can vary between functions and especially classes. The name you gave it when you passed it in your function is what you will use.
I use Xibo player 1.8 for Android. I understand the Xibo player itself does not have direct access to the CMS. But, in the module, I create a variable called $token. This is generated in the PHP layer.
When the module loads in the player, there will be a $token variable, just as you would pass a $title variable. What I wonder is, on a full page refresh, will the player retrieve a fully new generated HTML page? I experienced after some testing that the page loaded in the Xibo player contains ‘old’ data.
In other words, the token retrieven from the database is an old one! So it looks like the module is not really accessing the database, but getting a cached record from database.
I can’t really explain it any better.
For code, it looks like this:
public function GetResource($displayId = 0)
{
$token = $this->db->GetSingleRow(“SELECT * FROM token”)
$token = $token[‘authentication’];
…
$templateVariables[‘token’] = $token;
The contents of GetResource are cached by the player for a default of 5 minutes - if you want to make that happen quicker you will need to save an option on your widget for updateInterval and set it to a number of minutes, or 0 for update immediately.
Players don’t have any access to the CMS database - they only render the HTML provided by GetResource. If you have an updateInterval of 0, each time the widget is rendered it will call GetResource and download new HTML for the NEXT time it is shown (i.e. after its own widget duration has expired).
I am not sure what the purpose of the token is, but it should change each time.
Thanks Dan for your answer, this explains a lot. I now understand what I am seeing.
The purpose of my token is for API communication (through JavaScript). Since the contents is cached default for 5 min. this explains why I sometimes see an ‘old’ token. I have multiple screens, and the token comes from database. But as 1 screen was ‘refreshing’ and also refreshing the token in the database, other screens might still have the ‘cached’ version, which was then already obsolete causing the API communication to stall.
(My screens talk to an API endpoint with use of JavaScript)
Anyway, this means I have to redefine my architecture to work around this issue.
If your token was valid for 2x the duration you set in updateInterval and if 2x tokens could be valid at one time - i think your current architecture would probably work.