Digital Loggers

Visual Basic.NET Example




Special thanks to our valued customer Alan Holmes for this straightforward Visual Basic.NET example. It's usable with:

Web Power Switch
Ethernet Power Controller
220V PDU
PoE Injectors
DC Power Switch
DIN Relay
 

Hope this saves you some time:

 

Imports System.Net
  Imports System.IO
  Imports System.Text

  Module Module1

    Sub Main()
        Dim webResponse = ""
        Dim req As HttpWebRequest
        Dim res As HttpWebResponse
        Console.ReadKey() ' hit a key to turn the switch on
        req = WebRequest.Create("http://192.168.0.100/outlet?1=ON")
        Dim Encoded As String = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("admin:1234"))
        req.Headers.Add("Authorization", "Basic " + Encoded)
        res = req.GetResponse() ' Send Request
        Console.ReadKey() ' hit a key to turn the switch off
        req = WebRequest.Create("http://192.168.0.100/outlet?1=OFF")
        req.Headers.Add("Authorization", "Basic " + Encoded)
        res = req.GetResponse() ' Send Request
        Console.ReadKey() ' hit a key to exit program
    End Sub

  End Module