This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Auto opening widget, Changing camera view in 1 small widget
#4
Here are two examples created by our community member Erwin van der Zwart

1. The script to get snapshot from IP camera and send it to mailbox.

Code:
--***********************************************************--
--** Email image attachment created by Erwin van der Zwart **--
--***********************************************************--
--******************* Start of parameters *******************--
--***********************************************************--

--Gmail (smtp) username !IMPORTANT!
user = 'YOUR.ADDRESS@GMAIL.COM'

--Gmail (smtp) password !IMPORTANT!
password = 'YOUR GMAIL PASSWORD'

--Sender for e-mail
from = '<your.address@gmail.com>'
alias_from = 'YOUR FULL NAME'

--Recipient for e-mail
to = '<recipient@domain.com>'
alias_to = 'recipient full name'

--Subject for e-mail
subject = 'Snapshot from camera automaticly send by homeLYnk'

--Attachment and filetype (set filetype as 'gif', 'png', 'bmp', 'jpg' or 'jpeg' according image source)
image_type = 'jpeg'
image_name_attachment = 'snapshot'
source_image_url = 'http://your.camara.ip/snapshot.jpeg'
image_description = 'Snapshot from IP Camera'

--Message on bottom of email (will only be showed when client don't understand attachment)
epilogue = 'End of message'

--***********************************************************--
--******************** End of parameters ********************--
--***********************************************************--
--********** DON'T CHANGE ANYTHING UNDER THIS LINE **********--
--***********************************************************--

--Get remote (from HTTP) image and put image file to HL (will be deleted when end of script)
os.execute('wget -O /www/scada/vis/' .. image_name_attachment .. '.' .. image_type .. ' ' .. source_image_url .. '')

--Create filename and location
local fileName = '/www/scada/vis/' .. image_name_attachment .. '.' .. image_type

--Create table to include mail settings
local settings = {
   from = from,
   rcpt = to,
   user = user,
   password = password,
   server = 'smtp.gmail.com',
   port = 465,
   secure = 'sslv23',
}

--Load required modules to send email with attachment
local smtp = require("socket.smtp")
local mime = require("mime")
local ltn12 = require("ltn12")

--Create e-mail header
settings.source = smtp.message{
headers = {
         from = '' .. alias_from .. ' ' .. from .. '',
         to = '' .. alias_to .. ' ' .. to .. '',
         subject = subject
},

--Load attachment inside body    
body = {
preamble = "",
[1] = {  
     headers = {
       ["content-type"] = 'image/' .. image_type .. '; name="' .. image_name_attachment .. '.' .. image_type .. '"',
       ["content-disposition"] = 'attachment; filename="' .. image_name_attachment .. '.' .. image_type .. '"',
       ["content-description"] = '' .. image_description .. '',
       ["content-transfer-encoding"] = "BASE64"
     },
             
     body = ltn12.source.chain(
     ltn12.source.file(io.open(fileName, "rb")),
     ltn12.filter.chain(
     mime.encode("base64"),
     mime.wrap()
       )
     )
   },
     epilogue = epilogue
 }
}

--Send the email
r, e = smtp.send(settings)

--Create alert when sending gives an error with error message
if (e) then
    alert("Could not send email: ", e, "\n")
end

--Delete downloaded image file from HL
os.remove(fileName)

2. Another script allows to perform a jump to a specific visualization page when call from intercom is received. You need to write page number to the object and visualization will jump to it automatically.


Code:
-- * 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)
Reply


Messages In This Thread
RE: Auto opening widget, Changing camera view in 1 small widget - by edgars - 19.01.2016, 10:27

Forum Jump: