Git Product home page Git Product logo

luvaihassanali / samsungremote Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 27 KB

.NET library used to send commands to Samsung TV over Wi-Fi

Home Page: https://luvaihassanali.github.io/portfolio/

License: MIT License

C# 99.98% Smalltalk 0.02%
remote samsung samsung-tv c-sharp control csharp http https ip net-core remote-control samsung-remote tcp tcp-ip websocket websockets wi-fi wifi net48 net6

samsungremote's Introduction

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 sta/websocket-sharp#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

samsungremote's People

Contributors

luvaihassanali avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

karimnov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.