Open IP camera visualization page when intercom call is received
Example: Open IP camera visualization page when intercom call is received
Task
The example below shows how to automatically open respective IP camera floor/plan when intercom call is received.
Resident script
Add the following resident script and run once.
- -- * Jump to Page Module Version 1.2 Created by Erwin van der Zwart * --
- -- * This script perform automaticly all needed actions to support jump to page * --
- -- After running script once refresh browser and write value to object for result --
- -- ******************************** SET PARAMETERS ****************************** --
-
- -- Group address to trigger the page jump(s)
- Trigger_Group_Address = '0/0/33' -- !! MUST BE A 2 BYTE UNSIGNED INTEGER OBJECT !!
-
- -- Create automaticly iframe with jumps.html on startpage
- Create_Automatic = true -- Set to false to disable auto create and run script once
-
- -- Delete HTML jump function from controller
- Delete_HTML = false -- Set to true to delete this function and run script once
-
- -- ******************************** END PARAMETERS ****************************** --
- -- ********************* DON'T CHANGE ANYTHING UNDER THIS LINE ****************** --
-
- -- Create HTML content
- page = [[
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>homeLYnk Page Jumps</title>
- <style type="text/css">
- body {
- background-color: transparent;
- }
- </style>
- </head>
- <body>
- <script type="text/javascript">
-
- // ***** Make link to parent from iframe *****
- var p = window.parent, root, addr;
- var ip = location.host;
- var URL = "http://" + ip + "/scada/resources/img/";
-
- if (p && p.objectStore) {
- addr = p.Scada.encodeGroupAddress(']] .. Trigger_Group_Address .. [[');
- p.objectStore.addListener(addr, function(obj, type) {
- /* to avoid jump on opening page */
- if (type == 'init') {
- return;
- }
-
- if (obj.value == 0) {
- return;
- }
-
- if ( p.currentPlanId != obj.value ){
- p.showPlan(obj.value);
- }
-
- if ( obj.value != 0 ){
- p.setObjectValue({ address: ']] .. Trigger_Group_Address .. [[', rawdatatype: 7 }, 0, 'text');
- }
-
- });
- }
-
- </script>
- </div>
- </body>
- </html>
- ]]
-
- -- Create HTML file to write to controller
- io.writefile("/www/scada/resources/img/jumps.html", page)
-
- -- use this as frame URL -> /scada/resources/img/jumps.html
-
- -- Check if html must be automaticly created inside iframe with jumps.html on startpage
- if Create_Automatic == true then
-
- -- Get default startpage
- query = 'SELECT id, usermode_param FROM visfloors'
- for _, floor in ipairs(db:getall(query)) do
- if floor.usermode_param == "D" then
- default_startpage = floor.id
- end
- end
-
- -- Check if default page excists else exit script
- if default_startpage == nil then
- alert("Default page does not excists, exit HTML creation")
- --Exit script
- return
- end
-
- -- Check if object already exist
- object_exists = false
- query = 'SELECT floor, type, name, params FROM visobjects'
- for _, visobject in ipairs(db:getall(query)) do
- if visobject.floor == default_startpage and (visobject.type == 9 or visobject.type == "9") and visobject.name == "jumps" then
- object_exists = true
- end
- end
-
- -- Create if object doesn't exist
- if object_exists == false then
- db:insert('visobjects', {floor = default_startpage, type = 9, params = '{"source":"url","url":"/scada/resources/img/jumps.html","width":50,"height":50}', locx = 0 , locy = 0, name = "jumps", notouch = 1, nobg = 1,})
- end
-
- end
-
- -- Check if HTML logout function must be deleted from the controller
- if Delete_HTML == true then
-
- -- Get default startpage
- query = 'SELECT id, usermode_param FROM visfloors'
- for _, floor in ipairs(db:getall(query)) do
- if floor.usermode_param == "D" then
- default_startpage = floor.id
- end
- end
-
- -- Check if default page excists else exit script
- if default_startpage == nil then
- alert("Default page does not excists, exit HTML deletion")
- --Exit script
- return
- end
-
- -- Select all entrys from DB inside table 'visobjects'
- query = 'SELECT id, floor, type, name, params FROM visobjects'
- for _, visobject in ipairs(db:getall(query)) do
- if visobject.floor == default_startpage and (visobject.type == 9 or visobject.type == "9") and visobject.name == "jumps" then
- current = visobject.id
- db:delete('visobjects', { id = current })
- end
- end
-
- --Delete HTML file from HL dir
- os.remove("/www/scada/resources/img/jumps.html")
-
- end
-
- -- Disable script when done automaticly
- script.disable(_SCRIPTNAME)