Skip to main content
Skip table of contents

LUA Code: BaViDi to Show an Emergency Display upon Closure of Barionet 400 Inputs

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.

Barionet application

The application that allows us to achieve our goal is written in Lua. Any Barionet unit comes with Lua interpreter.

CODE
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.

  1. Open the Barionet web configuration interface and locate the "Custom App" tab

  2. Select the file and upload the script

  3. Give the application a name. i.e. bavidi

  4. Click on SUBMIT

  5. Now select the application "bavidi" from the drop down menu 

  6. Flag "run at boot" - This will force Barionet to start the application at every boot

  7. Flag “enable log” - This will enable the log function of the application

  8. Execution command: lua bavidi.lua (change it according to the name you assigned to the app)

  9. SAVE

  10. RUN 

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:

  1. Send the C,AS command to the connected screen

  2. Display the specified resource passed in the parameter of the command

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.