Logic Machine Forum
Lost object changes - workaround? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Lost object changes - workaround? (/showthread.php?tid=439)



Lost object changes - workaround? - Thomas - 24.10.2016

Hi
I've a visualisation with 157 unique bulbs in one sheet (one big hall). Every single bulb is switchable and dimable individually. On the opposite side there's a "Whole hall on-off" button for the whole hall. These are a requests.


I use 6 Jung DALIs module for controlling the hall lights.
Showed that it's not possible to transfer 157 feedbacks via KNX. Therefore I used DALI's "cumulative feedback". Cumulative feedback is a feedback which sends state of every lamp encoded into byte value. Which means instead of 64 feedbacks per 1 DALI I get only 4 cumulative feedbacks.

On LM side I decode this byte value by bit.lshift() etc. Then I "fake" original switching and brightness feedbacks (using grp.update).

The problem I'm fighting with is I lost some of "faked" feedbacks. Probably for two reasons:
1. I send plenty of changes in a small time. Maybe there's some buffer which gets full? (I changed "Maximum telegrams in queue" parameter in settings to 1000 but it hasn't helped).
2. Events are processed asynchronously not in order they arrive. From time to time I get 2 datagrams from one DALI because DALI is too slow. The first is 00FF (8 bulbs are off and 8 are on). The second is FFFF (which is correct, all 16 bulbs are on). But in LM these two changes are sometimes processed in reverted order. Maybe because the script is too complex. My opinion is grp.getvalue and grp.update are too slow.

So the questions are:
Can I switch object changes processing somehow from paralel to serial with correct time order?
Can I show a global value or a result of a function in visualisation directly without mapping to group object?

Is there anybody who solved this or similar problem?

LM4,firmware from 2016/07/14

Thank you for any idea

FYI my DALI decode function:
Code:
function ecl_fake_on_off_feedbacks(ll_hall_adr_1,ll_dali_nr,ll_event_nr,ll_hex_val)
 -- function sends fake feedbacks from collective on-off feedback
 -- ll_hall_adr_1 = 1st number of Group Address
 -- ll_dali_nr = Number of Dali - Must correspond to Dali table below
 -- ll_event_nr = Nr. of Event. Every Dali sends 4 events (1-16,17-32,33-48,49-64)
 -- ll_hex_val = Group address value taken from Object
 local ll_on_off
 local lb_on_off
 local ll_addr
 local ls_fulladdr
 local ll_end
 local lb_changed
  local dali={
   {
       { 1,2,3,4,13,14,15,16,25,26,27,28,37,38,39,40}  -- D1 ev 1
   ,
       { 49,50,51,52,61,64,62,63,73,74,75,76,85,86,87,88 } -- D1 ev 2
   ,
       {97,98,99,100,109,110,111,112}  -- D1 ev 3
   ,
       {}   -- D1 ev 4
   },
    {
       { 5,6,7,8,17,18,29,20,29,30,31,32,41,42,43,44}  -- D2 ev 1
   ,
       { 53,54,55,56,65,66,67,68,77,78,79,80,89,90,91,92 } -- D2 ev 2
   ,
       {101,102,103,104,113,114,115,116}  -- D2 ev 3
   ,
       {}   -- D2 ev 4
   },
   {
   { 9,10,11,12,21,22,23,24,33,34,35,36,45,46,47,48}  -- D3 ev 1
   ,
       { 57,58,59,60,69,70,71,72,81,82,83,84,93,94,95,96 } -- D3 ev 2
   ,
       {105,106,107,108,117,118,119,120}  -- D3 ev 3
   ,
       {}   -- D3 ev 4
     }
   }

 if (dali[ll_dali_nr] == nil) then
   log("Dali "..ll_dali_nr.." has no record in Dali table")
   return
 end
 if (dali[ll_dali_nr][ll_event_nr] == nil) then
   log("Dali "..ll_dali_nr.." Event "..ll_event_nr.." has no record in Dali table")
   return
 end
 ll_end=table.maxn(dali[ll_dali_nr][ll_event_nr])
 for i = 1,ll_end , 1 do
     ll_on_off=bit.band(ll_hex_val,1)
     lb_on_off=toboolean(ll_on_off)
     ll_addr=dali[ll_dali_nr][ll_event_nr][i]
     ls_fulladdr=ll_hall_adr_1.."/1/"..ll_addr
       ls_fulladdr_brightness_fb=ll_hall_adr_1.."/3/"..ll_addr
   lb_changed=ecl_update_changed(ls_fulladdr,lb_on_off)
   if (lb_on_off) then
     if (lb_changed) then
       -- we must really read the value
       grp.read(ls_fulladdr_brightness_fb)
    --   ecl_update_changed(ls_fulladdr_brightness_fb,100)
     end
   else
     -- switched off - brightness = always zero
     ecl_update_changed(ls_fulladdr_brightness_fb,0)
   end
   
     ll_hex_val=bit.rshift(ll_hex_val,1)
 end

end

function ecl_update_changed(ls_addr,la_val)
  local la_test =grp.getvalue(ls_addr)
  if (not (la_test == la_val)) then
      grp.update(ls_addr,la_val)
    return true
  end
  return false
end



RE: Lost object changes - workaround? - Erwin van der Zwart - 24.10.2016

Hi,

It's possible to create a custom HTML page and decode the 4 cumulative feedback values on the client side.

This way you don't need to put them to a lot of KNX objects.

Are you familiar with HTML5, CSS and JavaScript?

BR,

Erwin van der Zwart


RE: Lost object changes - workaround? - Thomas - 25.10.2016

It sound's like good idea in case there's no LM way how to solve this problem. Is there an API documentation/example etc. how to write my own web page communicating to LM?


RE: Lost object changes - workaround? - Erwin van der Zwart - 25.10.2016

(25.10.2016, 10:52)Thomas Wrote: It sound's like good idea in case there's no LM way how to solve this problem. Is there an API documentation/example etc. how to write my own web page communicating to LM?

How do you want to create the page? By iframe inside normal visu or full external by apps?

By iframe is much easier but then it must run inside normal visu as we refer to parent then..

BR,

Erwin


RE: Lost object changes - workaround? - Thomas - 25.10.2016

As iframe. I didn't know there's any other option.


RE: Lost object changes - workaround? - Erwin van der Zwart - 25.10.2016

Hi Thomas,

Use this as framework, the rest is up to you (;

You have 4 object listeners now in this framework that respond on KNX values.

Code:
<!DOCTYPE html">
<head>
 <title>homeLYnk by Schneider Electric</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;
 if (p && p.objectStore){
 
   // Add event listeners on KNX addresses

   addr1 = p.Scada.encodeGroupAddress('1/1/1');    
   p.objectStore.addListener(addr1, function(obj, type) {
     // to avoid (re)trigger on opening page */
     if (type == 'init') {
        return;
       // Or do your JavaScript actions on received value on page load
     } else {
       // Do your JavaScript actions on new received value
     }
   });

   addr2 = p.Scada.encodeGroupAddress('1/1/2');    
   p.objectStore.addListener(addr2, function(obj, type) {
     // to avoid (re)trigger on opening page */
     if (type == 'init') {
        return;
       // Or do your JavaScript actions on received value on page load
     } else {
       // Do your JavaScript actions on new received value
     }
   });

   addr3 = p.Scada.encodeGroupAddress('1/1/3');    
   p.objectStore.addListener(addr3, function(obj, type) {
     // to avoid (re)trigger on opening page */
     if (type == 'init') {
        return;
       // Or do your JavaScript actions on received value on page load
     } else {
       // Do your JavaScript actions on new received value
     }
   });

   addr4 = p.Scada.encodeGroupAddress('1/1/4');    
   p.objectStore.addListener(addr4, function(obj, type) {
     // to avoid (re)trigger on opening page */
     if (type == 'init') {
        return;
       // Or do your JavaScript actions on received value on page load
     } else {
       // Do your JavaScript actions on new received value
     }
   });
    }
</script>
</body>
</html>

If you look in custom javascript section you can find a newer version of the object listener (something like grp.listen), but this one i had copy-paste ready (;

BR,

Erwin