Logic Machine Forum
HTTP event from camera - 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: HTTP event from camera (/showthread.php?tid=4559)



HTTP event from camera - 2MAX - 06.02.2023

Hi, i connect camera HTTP event to LM and i need to write group adress on the bus if event {alarm} is true.

this is log from LM
* table:
["alarm_2"]
  * bool: true

this is .lp script
<?

require('apps')
vars = getvars()
log(vars)


RE: HTTP event from camera - admin - 06.02.2023

Try this:
Code:
<?

require('apps')
vars = getvars()

if vars.alarm_2 then
  grp.write('1/1/1', true)
end



RE: HTTP event from camera - 2MAX - 06.02.2023

(06.02.2023, 11:54)admin Wrote: Try this:
Code:
<?

require('apps')
vars = getvars()

if vars.alarm_2 then
  grp.write('1/1/1', true)
end

Thanks, what if alarm_2 wil be false?


RE: HTTP event from camera - admin - 06.02.2023

Nothing will happen. It cannot be really false. It can be either nil, true or a string. You can add an else clause to write a different value to the object if needed.


RE: HTTP event from camera - 2MAX - 06.02.2023

(06.02.2023, 12:04)admin Wrote: Nothing will happen. It cannot be really false. It can be either nil, true or a string. You can add an else clause to write a different value to the object if needed.

Ok, this is works fine. I want to use scritp with 16 cam, each camera has diferent event name ( alarm_1, alarm_2, alarm_3,.....a, alarm_16) for log from witch is alarm send.
how to change script to works with this changing event name?


RE: HTTP event from camera - admin - 06.02.2023

You can do it like this, alarm_1 will write to 1/1/1, alarm_2 to 1/1/2 and so on.
Code:
<?

require('apps')
vars = getvars()

for i = 1, 16 do
  if vars['alarm_' .. i] then
    grp.write('1/1/' .. i, true)
  end
end
But you cannot use else clause here because it will reset all other alarms. Either the alarm variable should have some value (like 1/0) or you should check the IP address of the camera that sent this event.


RE: HTTP event from camera - 2MAX - 06.02.2023

(06.02.2023, 12:17)admin Wrote: You can do it like this, alarm_1 will write to 1/1/1, alarm_2 to 1/1/2 and so on.
Code:
<?

require('apps')
vars = getvars()

for i = 1, 16 do
  if vars['alarm_' .. i] then
    grp.write('1/1/' .. i, true)
  end
end
But you cannot use else clause here because it will reset all other alarms. Either the alarm variable should have some value (like 1/0) or you should check the IP address of the camera that sent this event.

ok, i thank for your help, only one adress i need to write, but log each of event, something like this:
Code:
<?
require('apps')
vars = getvars()
for i = 1, 16 do
  if vars['alarm_' .. i] then
    grp.write('33/2/1', true)
  end
end
log(vars)

it looks to work from each cam