je cherche a piloter une prise IQTS-IP200 en SNMP via script lua
j'arrive à la piloter via un interrupteur virtuel mais je n'arrive pas à récupèrer son état (afin d'étre sur que la prise a bien pris en compte la commande).
voici mon script lua
Code : Tout sélectionner
commandArray = {}
if (devicechanged['iqts'])
then
-- envoi commande OFF
if otherdevices['iqts'] == "Off" then
local command = 'snmpset -v 1 -c public -O qv 192.168.1.71 0.1.3.6.1.4.1.21287.16.1.0 string 0'
local handle = assert(io.popen(command))
end
-- envoi commande On
if otherdevices['iqts'] == "On" then
local command = 'snmpset -v 1 -c public -O qv 192.168.1.71 0.1.3.6.1.4.1.21287.16.1.0 string 1'
local handle = assert(io.popen(command))
handle:close()
end
-- Recupereartion de l'état
local command2 = 'snmpget -v 1 -c public -O qv 192.168.1.71 0.1.3.6.1.4.1.21287.16.1.0 | cut -c 2'
local handle2 = assert(io.popen(command2))
-- si létat est 0 alors on eteint l'interrupteur d'état
if handle2 == '0'
then
commandArray['iqts_etat'] = 'On'
end
-- si létat est 1 alors on allume l'interrupteur d'état
if handle2 == '1'
then
commandArray['iqts_etat'] = 'Off'
end
handle2:close()
end
return commandArrayquand je tape dans un terminal
snmpget -v 1 -c public -O qv 192.168.1.71 0.1.3.6.1.4.1.21287.16.1.0
ça me renvoi "0" ou "1". Le fait d'ajouter | cut -c 2 permet de n'afficher que 0 ou 1.
je pense que le pb vient du format de la réponse, (fichier) je n'arrive pas à le comparer à 1 ou 0 pour changer l'état de mon interrupteur iqts_etat.
j'ai essayé de faire un print ('etat ----------------------------: ' .. handle2)
j'obtiens: "attempt to concatenate a FILE* value (local 'handle2')"
avec print ('etat ----------------------------: ' .. tostring(handle2))
j'obtiens : "etat ----------------------------: file (0x6345fb70)"
avec print ('etat ----------------------------: ' .. tonumber(handle2))
j'obtiens : [string "--..."]:49: attempt to concatenate a nil value
merci de votre aide.