luisllamasbinaburo / EwelinkNET

eWeLink API for .NET Standard (Windows, Linux and Mac)
https://www.luisllamas.es
Apache License 2.0
35 stars 9 forks source link

SwitchDevice TurnOff method doesn't work for my Sonoff S-Series socket #6

Closed NGancevich closed 3 years ago

NGancevich commented 3 years ago

I tried multiple times but no any action. I didn't get any error while executing device.TurnOff(); from method below

[Fact] public async void TurnOffDevice() { var ewelink = new Ewelink(Email, Password, Region); var credentials = await ewelink.GetCredentials(); await ewelink.GetDevices();

        var device = ewelink.Devices.First(x => x.deviceid == deviceId) as SwitchDevice;
        device.TurnOff();
    }
luisllamasbinaburo commented 3 years ago

I can't test, i don't have a Sonoff S-Series. If anyone can test it, any contribution are welcome

johndupreez commented 3 years ago

I don't have a Sonoff S-Series. However I am having the same issue with my BasicR3 Sonoff device.

Both device.TurnOn() and device.TurnOff() do not work, with no error reported. I run the unit tests for TurnOnDevice and TurnOffDevice with no action on the device.

The test-data.json is correct because I can call GetCredentials fine. GetDevices also works fine to get the list of devices, and the correct device is selected from the list before calling TurnOn or TurnOff.

The switch does turn on and off fine when using the ewelink app. The switch does turn on and off fine when using the ewelink webiste https://web.ewelink.cc/ GetState works fine to get the state of the device after turning on and off via app or website.

The SDK used to work fine a few months ago to turn the device on and off. I wonder if something has changed on the ewelink listener side? Let me know if you need any more info to help get to the bottom of this.

johndupreez commented 3 years ago

I have the same experience with the SetStartup test method. The test runs fine with no error, but the device startup mode is not set to on.

Setting startup to on via the ewelink app works fine.

edelbit commented 3 years ago

Cattura

i tried with my sonoff basic version 3.5.0 , firmware ita-gz1-gl getcredentials, getstate works but on and off not working. i tried to update payloads but nothing to do. regards

mzumbo commented 3 years ago

maybe the url for WS changed.

urls.cs

public static string GetWebsocketUrl(string region) { return $"wss://{region}-pconnect3.coolkit.cc:8080/api/ws"; }

edelbit commented 3 years ago

thank you mzumbo, changing url i've this message now: Cattura

mzumbo commented 3 years ago

Now I's working for me

I had to change:

1) constants.cs internal const string VERSION = "8";

2) wsupdatepaylod.cs internal WsUpdatePayload(string deviceId, string apiKey, object @params) { var seq = CoolkitHelper.MakeSequence();

        action = "update";
        apikey = apiKey;
        deviceid = deviceId;
        this.@params = @params;
        userAgent = "app";
        sequence = seq.sequence;
        ts = "0";
    }

3) wscredentialspayload.cs internal WsCredentialsPayload(string accessToken, string apiKey) { var seq = CoolkitHelper.MakeSequence();

        action = "userOnline";
        at = accessToken;
        apikey = apiKey;
        appid = "oeVkj2lxxxxxxxxxxx"; //your appid
        nonce = CoolkitHelper.MakeNonce();
        ts = seq.timestamp;
        userAgent = "app";
        sequence = seq.sequence;
        version = AppData.VERSION;            
    }

4) websocket.cs public void UpdateDevice(string apiKey, string deviceId, object @params) { var wsUpdatePayload = new WsUpdatePayload(deviceId, apiKey, @params); Thread.Sleep(100);
websocket.Send(wsUpdatePayload.AsJson()); }

edelbit commented 3 years ago

Yes! Great! it works! thank you mzumbo!

luisllamasbinaburo commented 3 years ago

Thanks mzumbo for your contribution. If you want, make a PR and I will check compatibility