from pysnmp.hlapi import *
import time # Import the time module
SNMP parameters
snmp_community = "private" # Replace with your SNMP community string
snmp_target = ("192.168.1.100", 161) # Replace with your device's IP address and SNMP port
for name, val in varBinds:
print(f"OID: {name}, Value: {val}")
# Add a delay (pause) after sending the command
time.sleep(delay_seconds)
except Exception as e:
print(f"Error: {e}" )
Loop to switch off relays 1 to 9 with a 2-second delay between each relay
for relay_number in range(0, 10):
value = 0 # Switch off the relay (0 for off)
delay_seconds = 2 # Specify the delay duration in seconds
send_snmp_set_with_delay(snmp_community, "192.168.1.100", 161, relay_number, value, delay_seconds)
from pysnmp.hlapi import * import time # Import the time module
SNMP parameters
snmp_community = "private" # Replace with your SNMP community string snmp_target = ("192.168.1.100", 161) # Replace with your device's IP address and SNMP port
Function to send an SNMP SET command with delays
def send_snmp_set_with_delay(community, ip, port, relay_number, value, delay_seconds): try: relay_oid = f"1.3.6.1.4.1.42505.6.2.3.1.3.{relaynumber}" , , , varBinds = next( setCmd(SnmpEngine(), CommunityData(community), UdpTransportTarget((ip, port)), ContextData(), ObjectType(ObjectIdentity(relay_oid), Integer(value))) )
Loop to switch off relays 1 to 9 with a 2-second delay between each relay
for relay_number in range(0, 10): value = 0 # Switch off the relay (0 for off) delay_seconds = 2 # Specify the delay duration in seconds send_snmp_set_with_delay(snmp_community, "192.168.1.100", 161, relay_number, value, delay_seconds)
send_snmp_set_with_delay(snmp_community, "192.168.1.100", 161, 13, 0, 0)
print("Lifetime stopped again") input("Press Enter to exit...")
Any help with this specific error or where am I wrong Error: name 'setCmd' is not defined