SNMP send orders - nmedalacabeza - 24.11.2023
How could I send a start order from SNMP to the generator set?
Thank you
Code: ---Vale para la lectura de varios Dispositivos SNMP de lectura ---------------
if not devices then
require('snmp')
devices = {
{
ip = '192.168.1.33', -- Grupo Electrogeno
mapping = {
{ oid = '1.3.6.1.4.1.41809.1.1.0', addr = '35/1/0' }, --Frecuencia red
{ oid = '1.3.6.1.4.1.41809.1.2.0', addr = '35/1/1' }, --Tensión red entre fases 12
{ oid = '1.3.6.1.4.1.41809.1.3.0', addr = '35/1/2' }, --Tensión red entre fases 23
{ oid = '1.3.6.1.4.1.41809.1.4.0', addr = '35/1/3' }, --Tensión red entre fases 31
{ oid = '1.3.6.1.4.1.41809.1.5.0', addr = '35/1/4' }, --Tensión red fase 1
{ oid = '1.3.6.1.4.1.41809.1.6.0', addr = '35/1/5' }, --Tensión red fase 2
{ oid = '1.3.6.1.4.1.41809.1.7.0', addr = '35/1/6' }, --Tensión red fase 3
{ oid = '1.3.6.1.4.1.41809.1.8.0', addr = '35/1/7' }, --Frecuencia grupo
{ oid = '1.3.6.1.4.1.41809.1.9.0', addr = '35/1/8' }, --Tensión grupo entre fases 12
{ oid = '1.3.6.1.4.1.41809.1.10.0', addr = '35/1/9' }, --Tensión grupo entre fases 23
{ oid = '1.3.6.1.4.1.41809.1.11.0', addr = '35/1/10' }, --Tensión grupo entre fases 31
{ oid = '1.3.6.1.4.1.41809.1.12.0', addr = '35/1/11' }, --Tensión grupo fase 1
{ oid = '1.3.6.1.4.1.41809.1.13.0', addr = '35/1/12' }, --Tensión grupo fase 2
{ oid = '1.3.6.1.4.1.41809.1.14.0', addr = '35/1/13' }, --Tensión grupo fase 3
{ oid = '1.3.6.1.4.1.41809.1.15.0', addr = '35/1/14' }, --Corriente fase 1
{ oid = '1.3.6.1.4.1.41809.1.16.0', addr = '35/1/15' }, --Corriente fase 2
{ oid = '1.3.6.1.4.1.41809.1.17.0', addr = '35/1/16' }, --Corriente fase 3
{ oid = '1.3.6.1.4.1.41809.1.18.0', addr = '35/1/17' }, --flagsCurrent
{ oid = '1.3.6.1.4.1.41809.1.23.0', addr = '35/1/18' }, --Potencia activa
{ oid = '1.3.6.1.4.1.41809.1.24.0', addr = '35/1/19' }, --Potencia aparente
{ oid = '1.3.6.1.4.1.41809.1.25.0', addr = '35/1/20' }, --Potencia reactiva
{ oid = '1.3.6.1.4.1.41809.1.27.0', addr = '35/1/21' }, --Nivel combustible
{ oid = '1.3.6.1.4.1.41809.1.28.0', addr = '35/1/22' }, --Tensión alternador carga batería
{ oid = '1.3.6.1.4.1.41809.1.29.0', addr = '35/1/23' }, --Tensión batería
{ oid = '1.3.6.1.4.1.41809.1.35.0', addr = '35/1/24' }, --totalInstant Power
{ oid = '1.3.6.1.4.1.41809.1.40.0', addr = '35/1/25' }, --totalRunningTime
{ oid = '1.3.6.1.4.1.41809.1.42.0', addr = '35/1/26' }, --successfulStarts
{ oid = '1.3.6.1.4.1.41809.1.43.0', addr = '35/1/27' }, --unsuccessfulStarts
{ oid = '1.3.6.1.4.1.41809.1.45.0', addr = '35/1/28' }, --Contador total energía grupo
{ oid = '1.3.6.1.4.1.41809.1.46.0', addr = '35/1/29' }, --status Estado de la central CEA7 / CEM7 representado en mapa de bits:
--(R G Al Bt B T Mn Au P A) pasar valor de hex (que da ) a bin
--El valor activo indica: hex 518 a bin 1 0 1 0 0 0 1 1 0 0 0
-- EJEMPLO R Al Mn Au
--1. R: Contactor de red cerrado
--2. G: Contactor de grupo cerrado
--3. Al: Alarma activa
--4. Bt: Bomba trasiego
--5. B: Modo Bloqueo
--6. T: Modo Test
--7. Mn: Modo Manual
--8. Au: Modo Automático
--9. P: Motor Parado
--10. M: Motor Arrancado
{ oid = '1.3.6.1.4.1.41809.1.47.0', addr = '35/1/30' }, --alarmBitMapHigh
{ oid = '1.3.6.1.4.1.41809.1.48.0', addr = '35/1/31' }, --alarmBitMapLow
{ oid = '1.3.6.1.4.1.41809.2.52.0', addr = '35/1/32' }, --start stop Grupo Electrogeno
{ oid = '1.3.6.1.4.1.41809.2.53.0', addr = '35/1/33' }, --mode Grupo Electrogeno
}
},
{
ip = '192.168.1.35, --Sai
mapping = {
{ oid = '1.3.6.1.4.1.318.1.1.1.2.1.1.0', addr = '35/0/0' }, -- BatteryStatus
{ oid = '1.3.6.1.4.1.318.1.1.1.2.1.2.0', addr = '35/0/1' }, --BatteryTimeOnBattery
{ oid = '1.3.6.1.4.1.318.1.1.1.2.1.3.0', addr = '35/0/3' }, -- BatteryLastReplaceDate
{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.1.0', addr = '35/0/4' }, --BatteryCapacity
{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.2.0', addr = '35/0/5' }, -- BatteryTemperature
{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.3.0', addr = '35/0/6' }, --BatteryRunTimeRemaining
{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.4.0', addr = '35/0/7' }, -- BatteryReplaceIndicator
{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.7.0', addr = '35/0/8' }, --NominalVoltage
{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.8.0', addr = '35/0/9' }, -- ActualVoltage
{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.9.0', addr = '35/0/10' }, --BatteryCurrent
-- { oid = '1.3.6.1.4.1.318.1.1.1.2.2.17.0', addr = '35/0/11' }, -- BatteryChargerStatus
--{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.21.0', addr = '35/0/12' }, --BatteryRecommendedReplaceDate
--{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.23.0', addr = '35/0/13' }, -- BatteryCondition
--{ oid = '1.3.6.1.4.1.318.1.1.1.2.2.25.0', addr = '35/0/14' }, --BatteryTotalCapacity
{ oid = '1.3.6.1.4.1.318.1.1.1.3.2.1.0', addr = '35/0/15' }, -- InputLineVoltage
{ oid = '1.3.6.1.4.1.318.1.1.1.3.2.4.0', addr = '35/0/16' }, --InputFrequency
--{ oid = '1.3.6.1.4.1.318.1.1.1.3.2.11.0', addr = '35/0/17' }, -- InputTotalApparentPower
--{ oid = '1.3.6.1.4.1.318.1.1.1.3.2.12.0', addr = '35/0/18' }, --InputTotalActivePower
--{ oid = '1.3.6.1.4.1.318.1.1.1.3.2.13.0', addr = '35/0/19' }, -- InputBypassTotalApparentPower
--{ oid = '1.3.6.1.4.1.318.1.1.1.3.2.14.0', addr = '35/0/20' }, --InputBypassTotalActivePower
--{ oid = '1.3.6.1.4.1.318.1.1.1.4.1.3.0', addr = '35/0/21' }, -- SystemStatus
{ oid = '1.3.6.1.4.1.318.1.1.1.11.1.1.0', addr = '35/0/22' }, --StateOutputState
--{ oid = '1.3.6.1.4.1.318.1.1.1.11.1.2.0', addr = '35/0/23' }, --StateAlarmStatusr
}
},
}
end
for _, dev in ipairs(devices) do
local conn, err = snmp.open({
version = snmp.SNMPv1,
community = 'public',
port = dev.port or 161,
peer = dev.ip,
})
if conn then
for _, map in ipairs(dev.mapping) do
local res, err = conn:get(map.oid)
if res and res.value ~= nil then
grp.checkwrite(map.addr, res.value)
else
alert('SNMP read from %s %s failed (%s)', dev.ip, map.oid, tostring(err))
end
end
conn:close()
else
alert('SNMP connection to %s failed (%s)', dev.ip, tostring(err))
end
end
RE: SNMP send orders - admin - 27.11.2023
See this thread for examples: https://forum.logicmachine.net/showthread.php?tid=1573&pid=13456#pid13456
Look for ":set" function calls.
RE: SNMP send orders - nmedalacabeza - 16.12.2023
(27.11.2023, 08:37)admin Wrote: See this thread for examples: https://forum.logicmachine.net/showthread.php?tid=1573&pid=13456#pid13456
Look for "et" function calls. I can't get it to work, I send it 1 and it gives me an error
snmp set to 192,168,1,33 1.3.6.1.4.1.41809.2.52.0 failed: snmp bad type(2) prim=0 in index 1
thank you
Code: require('snmp')
function setSNMPValue(ip, oid, value, type)
type = type or snmp.INTEGER -- Valor predeterminado: snmp.INTEGER si no se especifica el tipo
local conn, err = snmp.open({
version = snmp.SNMPv1,
community = 'public',
peer = ip,
})
if conn then
local res, err = conn:set({
{
oid = oid,
value = value,
type = type,
}
})
if err then
alert('snmp set to ' .. ip .. ' ' .. oid .. ' failed: ' .. tostring(err))
else
alert('snmp set to ' .. ip .. ' ' .. oid .. ' ok')
-- Realizar una operación GET para verificar si el valor se ha establecido correctamente
local res_get, err_get = conn:get(oid)
if res_get and res_get.value == value then
alert('Verification: snmp get for ' .. ip .. ' ' .. oid .. ' successful')
else
alert('Verification: snmp get for ' .. ip .. ' ' .. oid .. ' failed')
end
end
conn:close()
else
alert('snmp connection to ' .. ip .. ' failed: ' .. tostring(err))
end
end
-- Ejemplos de uso con valores enteros
setSNMPValue('192.168.1.33', '1.3.6.1.4.1.41809.2.52.0', 1, snmp.INTEGER)
setSNMPValue('192.168.1.33', '1.3.6.1.4.1.41809.2.53.0', 3, snmp.INTEGER)
-- Agrega más llamadas según sea necesario para otros dispositivos o parámetros SNMP
RE: SNMP send orders - admin - 18.12.2023
Correct type constant is snmp.TYPE_INTEGER, not snmp.INTEGER.
RE: SNMP send orders - nmedalacabeza - 19.12.2023
(18.12.2023, 07:36)admin Wrote: Correct type constant is snmp.TYPE_INTEGER, not snmp.INTEGER.
ok, thanks working
|