SamsungRemote 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SamsungRemote --version 1.0.0                
NuGet\Install-Package SamsungRemote -Version 1.0.0                
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.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SamsungRemote --version 1.0.0                
#r "nuget: SamsungRemote, 1.0.0"                
#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.0

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

SamsungRemote

Overview

SamsungRemote is a .NET 6.0 library used to communicate with Samsung TV over Wi-Fi. WebSocket client is used to maintain connection to TV which is implemented using fork of 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() // A delay is required between sending two keys for TV to receive them properly
        remote.Press(Keys.VOLDOWN);
    }
}
// GenerateNewToken() will update settings.Token with new token value which can be saved for subsequent connections

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 Framework net is compatible. 
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 225 5/13/2023
1.0.1 135 5/12/2023
1.0.0 133 5/11/2023