Xibo and Arduino help please

Dear All,

can anybody help me if it is possible to interact with arduino from Xibo commands ?

is it possibale ?

Regards,
Bashar

With a 1.8 series CMS you can yes - using the newer API.

The issue with Arduino is the speed of the CPU on there makes communication over SSL impossible, so you might be beter looking at something like NodeMCU. That way, you can connect to your CMS over SSL and have secure communication.

In terms of accessing the API, it’s just a simple series of HTTP requests you’ll need to make to get an access key, and then call the methods you want to call.

I do actually have a NodeMCU project here which calls the 1.8 API to change a layout based on detecting motion from a PIR sensor. I’m intending to write it up at some point but haven’t had the time recently. It’s written in Lua so may not be of use to you, but I’ve put the sequence of HTTP calls below so you can see the workflow:

Generate an API access token. These last for 1 hour so you’ll need to ensure you either store it, and then refresh it before that time.

function gentoken()
    print("Generating API access token")
    cmsConfig = dofile("confload.lc")("cms-conf.lc")
    collectgarbage()
    local auth = cmsConfig.url .. "/authorize/access_token"
    print("CMS is at " .. auth)
    local body = "grant_type=client_credentials&client_id=" .. cmsConfig.appKey .. '&client_secret=' .. cmsConfig.appSecret

    http.post(auth, 'Content-Type: application/x-www-form-urlencoded\r\n', body, handletoken)

    auth = nil
    body = nil
    collectgarbage()   
end

function handletoken(code, body)
    if (code < 0) then
         print("HTTP Token Refresh Failed")
    else
         -- token is returned json encoded
         -- {"access_token":"mFQOjLmcOALpTwm3RWiILAPnKssWFFWA1r2l68UU","token_type":"Bearer","expires_in":3600}
         local tokbegin = string.find(body, 'en":"') + 5
         local tokend = string.find(body, '"', tokbegin) - 1
         token = string.sub(body, tokbegin, tokend)

         tokbegin = nil
         tokend = nil
         collectgarbage()
    end
end

Then to change the running layout to another one temporarily, you can make a call like this using that token

local endpoint = cmsConfig.url .. '/displaygroup/' .. cmsConfig.displayGroupId .. '/action/changeLayout'
local body = 'layoutId=' .. cmsConfig.layoutId .. '&downloadRequired=true&duration=10&changeMode=replace'
http.post(endpoint, 'Content-Type: application/x-www-form-urlencoded\r\nAuthorization: Bearer ' .. token .. '\r\n', body, nil)

That will trigger a change to the layout specified for 10 seconds, and then it will revert back to schedule.

It should be fairly simple to translate those calls over to Arduino if that’s what you decide to use, but keep in mind you won’t be able to talk to a CMS that uses SSL.

1 Like

Dear Alex,

thanks for your replay, it will sure help me out on other part of the project i am working on, but what i really needed is the otherway around.

i have an arduino board connected to LED Strip and i have the code to change the color of the led using serial commands from pc, what i wanted to achieve is to trigger a command from xibo to arduino when the layout changes.

so i was thinking of adding command to a region on my layout, the will send to arduino connected to my player with usb.

so do you have any idea what is my options here.

and do you think that what i need is possibal with NodeMCU ?

Regards,
Bashar

If you’re running a shell command which talks directly to your Arduino over USB, then Xibo basically has no role in the process? It’s just a case of developing whatever command line tool you want, and making it work, and then using Xibo to call it.

You could do it with NodeMCU, but if you’re not talking to the API and you know Arduino already, then I’d stick with that.

my problem is i was not able to find any article about usbtoserial connection command line tool for linux android that i can call from xibo shell commands !!

if you know any thing about that or if you have any article please let me know

Regards,
Bashar

Talking to an Arduino over a serial cable is well outside the scope of Xibo I’m afraid.

You’d need to find a forum or mailing list related to Arduino and ask there.