Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net.Sockets
- Const mType As String = "drhs_SamsungTV"
- Const tvip As String = "1.1.1.1" 'Set a static IP address for your TV and edit this string to match that.
- Const tvport As Int32 = 55000 'This is the standard port that the TV listens on. Do not change it.
- Const mymac = "00-00-00-00-00-00" ' Enter your HS host MAC address here. This is used for the access control/validation, but not after that AFAIK
- Const appstring = "iphone..iapp.samsung" ' What the iPhone app reports
- Const tvappstring = "iphone.UN55C8000.iapp.samsung" ' Might need changing to match your TV type
- Const remotename = "Homeseer Samsung Remote" ' What gets reported when it asks for permission/also shows in General->Wireless Remote Control menu
- Public Sub Main(ByVal Params As Object)
- If Params IsNot Nothing Then
- Dim tcpClient As New System.Net.Sockets.TcpClient()
- tcpClient.Connect(tvip, tvport)
- Dim networkStream As NetworkStream = tcpClient.GetStream()
- If networkStream.CanWrite Then
- Dim Messagepart3 As String = ""
- Dim ByteArrayOut() As Byte = StrToByteArray(MessagePart1)
- networkStream.Write(ByteArrayOut, 0, ByteArrayOut.Length)
- ByteArrayOut = StrToByteArray(MessagePart2)
- networkStream.Write(ByteArrayOut, 0, ByteArrayOut.Length)
- Dim argv As String() = Params.ToString.Split("|")
- If Left(UCase(argv(0)),4) = "KEY_" Then
- Dim mp3 As String = Chr(0) & Chr(0) & Chr(0) & Chr(Len(Base64Encode(argv(0)))) & Chr(0) & Base64Encode(argv(0))
- MessagePart3 = Chr(0) & Chr(Len(tvappstring)) & Chr(0) & tvappstring & Chr(Len(mp3)) & Chr(0) & mp3
- Else
- Dim mp3 As String = Chr(1) & Chr(0) & Chr(0) & Chr(Len(Base64Encode(argv(0)))) & Chr(0) & Base64Encode(argv(0))
- MessagePart3 = Chr(1) & Chr(Len(tvappstring)) & Chr(0) & tvappstring & Chr(Len(mp3)) & Chr(0) & mp3
- End If
- ByteArrayOut = StrToByteArray(MessagePart3)
- networkStream.Write(ByteArrayOut, 0, ByteArrayOut.Length)
- networkStream.Close()
- tcpClient.Close()
- End If
- End If
- End Sub
- Private Function MessagePart1() As String
- 'Dim myip As String = hs.GetIPAddress ' Doesn't seem to be really used
- Dim myip as String = "2.2.2.2" 'Set your HS Host IP address here
- Dim messagepart1x As String = Chr(&H64) & Chr(0) & Chr(Len(Base64Encode(myip))) & Chr(0) & Base64Encode(myip) & Chr(Len(Base64Encode(mymac))) & Chr(0) & Base64Encode(mymac) & Chr(Len(Base64Encode(remotename))) & Chr(0) & Base64Encode(remotename)
- Dim part1 As String = Chr(0) & Chr(Len(appstring)) & Chr(0) & appstring & Chr(Len(messagepart1x)) & Chr(0) & messagepart1x
- Return part1
- End Function
- Private Function MessagePart2() As String
- Dim messagepart2x As String = Chr(&HC8) & Chr(0)
- Dim part2 As String = Chr(0) & Chr(Len(appstring)) & Chr(0) & appstring & Chr(Len(messagepart2x)) & Chr(0) & messagepart2x
- Return part2
- End Function
- Private Function Base64Encode(ByVal InputString As String)
- Dim byt As Byte() = System.Text.Encoding.UTF8.GetBytes(InputString)
- Return Convert.ToBase64String(byt)
- End Function
- Private Function StrToByteArray(str As String) As Byte()
- Dim ByteArray(Len(str)-1) as Byte
- For n As Short = 0 To UBound(ByteArray)
- ByteArray(n) = Asc(Mid(str,n + 1,1))
- Next
- Return ByteArray
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement