SamsungRemote 1.0.2

dotnet add package SamsungRemote --version 1.0.2
NuGet\Install-Package SamsungRemote -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SamsungRemote" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SamsungRemote --version 1.0.2
#r "nuget: SamsungRemote, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SamsungRemote as a Cake Addin
#addin nuget:?package=SamsungRemote&version=1.0.2

// Install SamsungRemote as a Cake Tool
#tool nuget:?package=SamsungRemote&version=1.0.2

SamsungRemote

Overview

SamsungRemote is a .NET library used to communicate with Samsung TV over Wi-Fi. WebSocket client is used to maintain connection to TV which is implemented using websocket-sharp.

Features

Usage

See SamsungRemoteDemo for more detailed example

Settings settings = new Settings(
    appName: "SamsungRemoteDemo", // converted to base64 string as ID for TV
    ipAddr: "192.168.1.100", // IP of TV
    subnet: "255.255.255.255", // Subnet (required for TurnOn() function)
    macAddr: "00-A1-B2-C3-D4-E5", // MAC address of TV (required for TurnOn() function)
    port: 8002, // Port for WebSocket communication
    token: null, // Authorization token
    debug: true); // Control Debug.WriteLine statements in SamsungRemote class
    
using (SamsungRemote remote = new SamsungRemote(settings))
{
    remote.TurnOn();
    if (remote.IsTvOn(2000))
    {
        // Since token is null Connect() will call GenerateNewToken() method
        // Token being null will show dialog on TV for user to accept new connection
        remote.Connect();
        remote.Press(Keys.VOLDOWN);
        Task.Delay(200).Wait() // Delay is required between sending two keys
        remote.Press(Keys.VOLDOWN);
    }
}
// GenerateNewToken() will update settings.Token with new token value 
// Saved token is used on next initialization so TV will not show new connection dialog 

How to get MAC address

To be able to turn on TV, the MAC address (and subnet) is required to be set. These are some options to determine what it is:

  1. The MAC address may be displayed in Network Settings of TV
  2. Login to router home page (e.g. 192.168.1.1) and check connected client information
  3. Use Wireshark/Fiddler to capture packets sent by existing mobile apps with power on functionality (myTifi worked in my case)

Notes

⚠️ TurnOn() and IsTvOn() functions will fail if called within 20-30 seconds of turning TV off ⚠️

  • During testing it was observed if TurnOn() or IsTvOn() were called within 20-30 seconds of TV being turned off, then TurnOn() would do nothing or produce delayed power on, and IsTvOn() would return true
  • A delay is required in between sending keys repeadeatly (200ms is good, not tested with a lower interval)
  • MAC address and subnet can be omitted but exception will be thrown if TurnOn() function is called
  • Currently WebSocketSharp async methods use BeginInvoke which is not supported for .NET Core https://github.com/sta/websocket-sharp/pull/712 (wrap methods in await Task.Run(() ⇒ { Function(); }) as a workaround)
  • If acceptance prompt is ignored with a supplied token, commands will work but prompt will display again on next connect, until accepted

References

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 157 5/13/2023
1.0.1 104 5/12/2023
1.0.0 100 5/11/2023