MAC detect in the same network
Posted: Monday 30 January 2023 12:28
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.
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.