Heren,
Ik heb onderstaande code van DJ`s site gedownload en aangepast naar mijn eigen smaak.
(Ik wil deze gebruiken om de temperatuur van mijn Netgear NAS uit te lezen)
Code: Select all
Imports SNMPDll
Sub Main(parm as object)
Dim strDevice As String = "192.168.2.1"
Dim strPublic As String = "public"
Dim strPrivate As String = "public"
Dim myMib As Mib = new Mib()
Dim a As SNMPAgent = New SNMPAgent(strDevice, strPublic, strPrivate)
myMib.loadDirectoryMib("C:\Program Files\HomeSeer HSPRO\SNMP\")
'GetSNMP(<type>,<snmp-address>,<device>,<debug>,a) (do NOT change the 'a')
'DJ: debug 0=write 1=write+log 2=log
GetSNMP("NAS_temperatuur", ".1.3.6.1.4.1.4526.18.5.1.2.", "V1", 1, a)
'GetSNMP("HD_temp2",".1.3.6.1.4.1.24681.1.2.11.1.3.2","",0,a)
'GetSNMP("HD_status1",".1.3.6.1.4.1.24681.1.2.11.1.4.1","",2,a)
'GetSNMP("HD_status2",".1.3.6.1.4.1.24681.1.2.11.1.4.2","",0,a)
'GetSNMP("HD_smartInfo1",".1.3.6.1.4.1.24681.1.2.11.1.7.1","",2,a)
'GetSNMP("HD_smartInfo2",".1.3.6.1.4.1.24681.1.2.11.1.7.2","",0,a)
'GetSNMP("HD_volumeFreeSize1",".1.3.6.1.4.1.24681.1.2.17.1.5.1","T9",1,a)
'GetSNMP("HD_volumeFreeSize2",".1.3.6.1.4.1.24681.1.2.17.1.5.2","",2,a)
'
End Sub
Function GetSNMP(SNMPname,SNMPstring,device,debug,b)
Dim strSNMPvalue as String
GetSNMP = new SNMPObject(SNMPstring)
strSNMPvalue = Cstr(GetSNMP.getSimpleValue(b))
Select Case Left(SNMPname,Len(SNMPname)-1)
Case "NAS_temperatuur"
strSNMPvalue = Left(strSNMPvalue, 2)
If debug < 2 And device <> "" Then hs.setdevicevalue(device, CInt(strSNMPvalue))
strSNMPvalue = strSNMPvalue + " " + Chr(176)
End Select
If debug > 0 then hs.WriteLog("SNMP_02", "<i>" & SNMPname & "</i>: " & strSNMPvalue)
If debug < 2 and device <> "" then hs.setdevicestring(device,strSNMPvalue,TRUE)
End Function
Ik krijg onderstaande foutmelding in mijn Log:
Code: Select all
15-2-2013 19:26:50 - Error - Scripting runtime error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack) at scriptcode6.scriptcode6.GetSNMP(Object SNMPname, Object SNMPstring, Object device, Object debug, Object b) at scriptcode6.scriptcode6.Main(Object parm) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Scheduler.VsaScriptHost.Invoke(String ModuleName, String MethodName, Object[] Arguments)
Ik heb de netgear MIB file (READYNAS-MIB.mib) in de aangegeven directory gezet.
De SNMP functie in mijn NAS aangezet met het IP adres van mijn homeseer server.
Maar toch gaat het nog niet goed.
Heeft iemand enig idee waar ik de mist in ga?