This article contains an application that can be used on any Barionet 400 to trigger an HTTP request to a BaViDi device when any one of the 4 digital inputs is closed.
The code can be easily adapted to other use cases and scenarios, the scope is to introduce the user into the Barionet 400 programming to become more proficient.
What do you need:
Barionet 400 running FW v2.17.2
BaViDi running v1.0.2 and with content preloaded (how to load content in BaViDi)
PC used to produce the lua file and upload it into Barionet
All devices should be reachable within the network where they operate.
The application that allows us to achieve our goal is written in Lua. Any Barionet unit comes with Lua interpreter.
time = require "os" http = require "socket.http" function httpCall(ip,port,appkey,command) local body, code, headers, status = http.request("http://"..ip..":"..port.."/?appkey="..appkey.."&command="..command.."") print(status, code, body) end print(time.date('%c')..": application started") while true do for i = 1,4,1 do input = io.open("/dev/gpio/in"..i.."/value") iRead = input:read('*n') if iRead == 1 then httpCall('192.168.3.163','8080','wsh728jn','Y,Tsunami/Tsunami.html') print(time.date('%c')..": INPUT "..i.." CLOSED - HTTP REQUEST SENT") end input:close() socket.sleep(0.1) end end
In order for the above code to work in your setup, replace in line 15:
IP ADDRESS of your BaViDi device
appkey to match the appkey provided by Barix
The command to display the desired content on Bavidi. In the above example a Tsunami warning display was preloaded into BaViDi. The ‘Y' command on Bavidi combines the C,AS (CEC command to switch to the bavidi’s active HDMI input) and the D command to display the content specified by the parameter ('Tsunami/Tsunami.html' in our example)
Once you have your script modified according to your environment, you are ready to copy it into Barionet400.
Open the Barionet web configuration interface and locate the "Custom App" tab
Select the file and upload the script
Give the application a name. i.e. bavidi
Click on SUBMIT
Now select the application "bavidi" from the drop down menu
Flag "run at boot" - This will force Barionet to start the application at every boot
Flag “enable log” - This will enable the log function of the application
Execution command: lua bavidi.lua (change it according to the name you assigned to the app)
To confirm the application is running click on ‘Open log’, you should see the timestamp of when the application was started.
Tue Nov 17 17:01:02 2020: application started
Now, every time any one of the 4 inputs is closed the HTTP request is sent and BaViDi will:
Send the C,AS command to the connected screen
Display the specified resource passed in the parameter of the command