Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'setCmd' is not defined #462

Open
A-Belean opened this issue Aug 5, 2024 · 1 comment
Open

'setCmd' is not defined #462

A-Belean opened this issue Aug 5, 2024 · 1 comment

Comments

@A-Belean
Copy link

A-Belean commented Aug 5, 2024

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.{relay_number}"
_, _, _, varBinds = next(
setCmd(SnmpEngine(),
CommunityData(community),
UdpTransportTarget((ip, port)),
ContextData(),
ObjectType(ObjectIdentity(relay_oid), Integer(value)))
)

    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)

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

@lextm
Copy link

lextm commented Aug 5, 2024

Posting issues here is invalid. Please read #429 for more details.

Known issue due to breaking changes in release 6.2, https://docs.lextudio.com/pysnmp/upgrade#upgrade-to-6-2-releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants