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.

Source code    
  1. -- * Jump to Page Module Version 1.2 Created by Erwin van der Zwart * --
  2. -- * This script perform automaticly all needed actions to support jump to page * --
  3. -- After running script once refresh browser and write value to object for result --
  4. -- ******************************** SET PARAMETERS ****************************** --
  5.  
  6. -- Group address to trigger the page jump(s)
  7. Trigger_Group_Address = '0/0/33' -- !! MUST BE A 2 BYTE UNSIGNED INTEGER OBJECT !!
  8.  
  9. -- Create automaticly iframe with jumps.html on startpage
  10. Create_Automatic = true -- Set to false to disable auto create and run script once
  11.  
  12. -- Delete HTML jump function from controller
  13. Delete_HTML = false -- Set to true to delete this function and run script once
  14.  
  15. -- ******************************** END PARAMETERS ****************************** --
  16. -- ********************* DON'T CHANGE ANYTHING UNDER THIS LINE ****************** --
  17.  
  18. -- Create HTML content
  19. page = [[
  20. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  21. <html xmlns="http://www.w3.org/1999/xhtml">
  22. <head>
  23. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  24. <title>homeLYnk Page Jumps</title>
  25. <style type="text/css">
  26. body {
  27. background-color: transparent;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <script type="text/javascript">
  33.  
  34. // ***** Make link to parent from iframe *****
  35. var p = window.parent, root, addr;
  36. var ip = location.host;
  37. var URL = "http://" + ip + "/scada/resources/img/";
  38.  
  39. if (p && p.objectStore) {
  40. addr = p.Scada.encodeGroupAddress(']] .. Trigger_Group_Address .. [[');
  41. p.objectStore.addListener(addr, function(obj, type) {
  42. /* to avoid jump on opening page */
  43. if (type == 'init') {
  44. return;
  45. }
  46.  
  47. if (obj.value == 0) {
  48. return;
  49. }
  50.  
  51. if ( p.currentPlanId != obj.value ){
  52. p.showPlan(obj.value);
  53. }
  54.  
  55. if ( obj.value != 0 ){
  56. p.setObjectValue({ address: ']] .. Trigger_Group_Address .. [[', rawdatatype: 7 }, 0, 'text');
  57. }
  58.  
  59. });
  60. }
  61.  
  62. </script>
  63. </div>
  64. </body>
  65. </html>
  66. ]]
  67.  
  68. -- Create HTML file to write to controller
  69. io.writefile("/www/scada/resources/img/jumps.html", page)
  70.  
  71. -- use this as frame URL -> /scada/resources/img/jumps.html
  72.  
  73. -- Check if html must be automaticly created inside iframe with jumps.html on startpage
  74. if Create_Automatic == true then
  75.  
  76. -- Get default startpage
  77. query = 'SELECT id, usermode_param FROM visfloors'
  78. for _, floor in ipairs(db:getall(query)) do
  79. if floor.usermode_param == "D" then
  80. default_startpage = floor.id
  81. end
  82. end
  83.  
  84. -- Check if default page excists else exit script
  85. if default_startpage == nil then
  86. alert("Default page does not excists, exit HTML creation")
  87. --Exit script
  88. return
  89. end
  90.  
  91. -- Check if object already exist
  92. object_exists = false
  93. query = 'SELECT floor, type, name, params FROM visobjects'
  94. for _, visobject in ipairs(db:getall(query)) do
  95. if visobject.floor == default_startpage and (visobject.type == 9 or visobject.type == "9") and visobject.name == "jumps" then
  96. object_exists = true
  97. end
  98. end
  99.  
  100. -- Create if object doesn't exist
  101. if object_exists == false then
  102. 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,})
  103. end
  104.  
  105. end
  106.  
  107. -- Check if HTML logout function must be deleted from the controller
  108. if Delete_HTML == true then
  109.  
  110. -- Get default startpage
  111. query = 'SELECT id, usermode_param FROM visfloors'
  112. for _, floor in ipairs(db:getall(query)) do
  113. if floor.usermode_param == "D" then
  114. default_startpage = floor.id
  115. end
  116. end
  117.  
  118. -- Check if default page excists else exit script
  119. if default_startpage == nil then
  120. alert("Default page does not excists, exit HTML deletion")
  121. --Exit script
  122. return
  123. end
  124.  
  125. -- Select all entrys from DB inside table 'visobjects'
  126. query = 'SELECT id, floor, type, name, params FROM visobjects'
  127. for _, visobject in ipairs(db:getall(query)) do
  128. if visobject.floor == default_startpage and (visobject.type == 9 or visobject.type == "9") and visobject.name == "jumps" then
  129. current = visobject.id
  130. db:delete('visobjects', { id = current })
  131. end
  132. end
  133.  
  134. --Delete HTML file from HL dir
  135. os.remove("/www/scada/resources/img/jumps.html")
  136.  
  137. end
  138.  
  139. -- Disable script when done automaticly
  140. script.disable(_SCRIPTNAME)