Giter VIP home page Giter VIP logo

Comments (14)

sergey-brutsky avatar sergey-brutsky commented on May 30, 2024 1

Okay! I'll try to do the support for wifi version when I'll have time. Is there a way where I can reach you if I have questions about it?

Just create an issue and start the discussion

from mi-home.

sergey-brutsky avatar sergey-brutsky commented on May 30, 2024

Hi, could you please show me what code snippet did you run ?
Also please clarify where did you run your c# code and python code, from your laptop ?

from mi-home.

Ts1rke avatar Ts1rke commented on May 30, 2024

I tried exactly the example snippets from the readme file. I run the codes on my desktop PC which is connected with cable to the same network as the gateway.

from mi-home.

sergey-brutsky avatar sergey-brutsky commented on May 30, 2024

README file contains a lot of snippets.
Please show me the code that (possibly) is not working correctly and describe what exactly you want to achieve ?
Do you want to turn on/off your socket plug ? Get events from the cube ?

from mi-home.

Ts1rke avatar Ts1rke commented on May 30, 2024

Primarily I would like to turn on/off the socket plug, but if I'd manage it to work, I would also do other stuff maybe.

I've tried these for example:

The device searching:

public static void Main(string[] args)
{
    using var miHome = new MiHome();

    miHome.OnAnyDevice += (_, device) =>
    {
        Console.WriteLine($"{device.Sid}, {device.GetType()}, {device}");
    };

    Console.ReadLine();
}

The gateway light truning on/off:

public static void Main(string[] args)
{
    using var miHome = new MiHome();

    miHome.OnGateway += (_, gateway) =>
    {
        gateway.EnableLight();
        Task.Delay(3000).Wait();
        gateway.DisableLight();
    };
}

from mi-home.

sergey-brutsky avatar sergey-brutsky commented on May 30, 2024

Please make sure that:

  1. Your gateway version is supported (DGNWG02LM)
  2. Gateway ports are not blocked (udp port 9898 should be opened)
  3. Your OS or any other installed software like (Virtual Box, Hyper-V, pcap) are not blocking UDP multicast traffic

In order to work with devices like gateway and socket plug you need to get a developers token, please check this link https://www.domoticz.com/wiki/Xiaomi_Gateway_(Aqara)#Adding_the_Xiaomi_Gateway_to_Domoticz

And use this token in your code snippets like this

public static void Main(string[] args)
{
    using var miHome = new MiHome("your developer password here");

    miHome.OnGateway += (_, gateway) =>
    {
        gateway.EnableLight();
        Task.Delay(3000).Wait();
        gateway.DisableLight();
    }

from mi-home.

Ts1rke avatar Ts1rke commented on May 30, 2024

I can't find my gateway version, it isn't shown in the Mi Home app neither. Do you have any idea where to check it?
The ports aren't blocked, there is a firewall rule set to allow it and no software like these are running.

Side note: as I see, this description on Domoticz website isn't valid anymore as there is no About option in the gateway menu in the most recent Mi Home app. 😮 But I already had the token, so at least that isn't a problem.

The same (nothing) happens if I run the snippet with the token, but now I checked with Wireshark, and there is a communication.
When I start the application (more specifically when I declare the MiHome class), it sends a multicast message and I got a response for it directly to my PC's IP from the gateway's IP. This is received the data:
{"cmd":"get_id_list_ack","sid":"7c49eb88f719","token":"HJH5Va127DfnC2WO","data":"[\"158d0002c7f582\",\"158d00029aae2c\"]"}
But I just see it with Wireshark, there isn't anything happening in my application.

from mi-home.

sergey-brutsky avatar sergey-brutsky commented on May 30, 2024
{"cmd":"get_id_list_ack","sid":"7c49eb88f719","token":"HJH5Va127DfnC2WO","data":"[\"158d0002c7f582\",\"158d00029aae2c\"]"}

This means that library is able to see 2 devices with sids from this array [\"158d0002c7f582\",\"158d00029aae2c\"]
and you can listen to events from this devices and send commands.

Here is a code snippet that works perfectly fine on my laptop against library version 1.0.12

public static void Main(string[] args)
{
    using var miHome = new MiHome("developer password here");

    miHome.OnSocketPlug += (_, socketPlug) =>
    {
        if (socketPlug.Sid == "158d00015dc662") // sid of my socket plug
        {
            Console.WriteLine(socketPlug); 
            socketPlug.TurnOff();
            Task.Delay(5000).Wait();
            socketPlug.TurnOn();
        }
    };

    Console.ReadLine();
}

Output is Status: on, Inuse: 1, Load Power: 2.46V, Power Consumed: 94897W, Voltage: 3.6V

Could you please double check that you are using a correct developer password ? Here is an instruction how to obtain it.

from mi-home.

Ts1rke avatar Ts1rke commented on May 30, 2024

Oh, I've just found the main problem... As I haven't seen any guide about this here, until now I've used .NET Framework (4.7.2) for trying the library, because I usually work with .NET Framework. But I've just noticed that your code must be written for .NET Core, so I tried that and now it works as it should be, yay!

Unfortunately I still can't reach my socket plug, as the two device what I can see is the cube and the switch. My plug looks exactly the same as the one you show in the readme. The only difference I noticed between the plug and the cube/switch in the Mi Home app is that the plug isn't a child device of the gateway. I tried to add it as a child device to the gateway to check if is it the problem, but I just can't configure it when I'm trying to add it as a child, only if I add it as a normal device separately from the gateway. Do you have your socket plug as a child device of your gateway, is it necessary? Do you have any further idea about this maybe?

from mi-home.

sergey-brutsky avatar sergey-brutsky commented on May 30, 2024

As far as I know there are two types of xiaomi smart socket plug: wifi version and zigbee version.
wifi version can work separately (no need to pair with gateway)
zigbee doesn't work as a separate device (need to pair with gateway)

I have only zigbee version of this adapter, this is the version that was implemented in this library.
If you have a desire to implement support for wifi version I will be happy.

from mi-home.

Ts1rke avatar Ts1rke commented on May 30, 2024

I see, I would happily implement that if I can for sure! Do you have any guideline or special instructions for that or do you think I could do that based on the implementation of other devices?

from mi-home.

sergey-brutsky avatar sergey-brutsky commented on May 30, 2024

As far as I know all wifi-based devices are implemented on top of MIIO protocol.
I recently started supporting this protocol.
The only device that I have right now that is working on top of MIIO is Mi Air Humidifier.
Please take a look at the sources for this device, this might get a clue how to implement support for mi socket plug.
There is no special guideline/instructions at the moment, probably I'll add this instructions once the process settles down

from mi-home.

sergey-brutsky avatar sergey-brutsky commented on May 30, 2024

@Ts1rke if there are no other questions in this issue I suggest to close it

from mi-home.

Ts1rke avatar Ts1rke commented on May 30, 2024

Okay! I'll try to do the support for wifi version when I'll have time. Is there a way where I can reach you if I have questions about it?

from mi-home.

Related Issues (14)

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.