Page 1 of 1

MAC detect in the same network

Posted: Monday 30 January 2023 12:28
by ssk17051980
Hello,

I ask to AI ( chat.openai) to make a scrip in dzvents to detect an device connected to the network (based on MAC) and signaling in domoticz with an ON/OFF switch.
what information did I give him:
all devices are on the same network. Some by cable, others wi-fi.
I gave him the idx of the button and the name of the button in domoticz.
I told him how to signal the connected device (with ON/OFF switch)
it returned me the script below but it doesn't work.
I have no error in Domoticz LOG
I use domoticz 2002.2 instaled on raspberry 4


return {
on = {
timer = {
'every minute'
}
},
execute = function(domoticz, device)
-- Specify the MAC address of the device
local macAddress = 'ac:00:03:85:00:00'
--Specify the IDX of the virtual button
local deviceIdx = 133
-- It executes the arp command and saves the result in a variable
local handle = io.popen('arp -a -n | grep -i ' .. macAddress .. ' | wc -l')
local result = handle:read("*a")
handle:close()
-- Check if the value is 1 or 0
if (tonumber(result) == 1) then
-- The value is 1, the device is connected
domoticz.devices(deviceIdx).switchOn().silent()
else
-- Vallo is not 1, the device is not connected
domoticz.devices(deviceIdx).switchOff().silent()
end
end

}

I check the arp comand, whit some MAC and i get the corect result. 1 or 0, depending on the MAC.

Re: MAC detect in the same network

Posted: Monday 30 January 2023 13:01
by mgugu
Maybe the ARP table is not updated with that MAC. You can try to issue a ping command before. With IP if you know it or broadcast address if not.

Re: MAC detect in the same network

Posted: Monday 30 January 2023 13:32
by waltervl
Do not trust AI ( chat.openai) and read trhe dzVents documentation.
Especially the part where it describes the running of os commands (like arp): https://www.domoticz.com/wiki/DzVents:_ ... _execution

Re: MAC detect in the same network

Posted: Monday 30 January 2023 15:37
by ssk17051980
my knowledge in programming, etc. is below sea level. I can't do it alone

Re: MAC detect in the same network

Posted: Monday 30 January 2023 16:09
by waltervl
You can use the ping function of Domoticz to check if devices are live. You have to get the devices a fixed IP by your router.
https://www.domoticz.com/wiki/System_Al ... ker_(Ping)
Else search for presence detection domoticz for some other plugins and functions.

Re: MAC detect in the same network

Posted: Monday 30 January 2023 21:19
by ssk17051980
I solved it with the PING function. Thanks, I prefer MAC because it's about mobile phones and sometimes the router makes mistakes and doesn't reserve their IP. I found a script for domoticz iDetect, but it gives me errors during installation and I was not able to complete the process