Giter VIP home page Giter VIP logo

Comments (40)

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

Could you please show me your code that is supposed to be working ?

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

Could you please show me your code that is supposed to b3 working ?

using MiHomeLib;
using System;
using System.Linq;

namespace MiHomeServer
{
    class Program
    {
        static void Main(string[] args)
        {
            bool pause = false;

            using (var miHome = new MiHome("233c0hrpctwp5sxt"))
            {
                var devices = miHome.GetDevices();
                if (devices.Any())
                {
                    pause = true;
                    foreach (var miHomeDevice in miHome.GetDevices())
                    {
                        Console.WriteLine($"{miHomeDevice.Sid}, {miHomeDevice.GetType()}, {miHomeDevice}");
                    }
                }

                if (miHome.GetGateway() != null)
                {
                    pause = true;
                    Console.WriteLine($"{miHome.GetGateway()?.Sid}");
                }
            }

            if (pause)
            {
                Console.ReadLine();
            }
        }
    }
}

from mi-home.

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

Is your GW and PC where you running your code in the same LAN subnet (without any routers/firewalls/etc) ?
I'm asking this because it's not clear why do you configuring your FW rules

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

Is your GW and PC where you running your code in the same LAN subnet (without any routers/firewalls/etc) ?

GW is connected to the wi-fi network of my router. PC wich I used to test the code, I sent in the previous message, is also connected to the same router via Ethernet cable.

I also tried that example code on the notebook connected to the same wi-fi hotspot (with the gateway) and result is the same.

I'm asking this because it's not clear why do you configuring your FW rules

I just tries all possible solution that can help in my opinion.

from mi-home.

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

Could you please add a small pause after using and before GetDevices method like Thread.Sleep or Task.Delay for 5 seconds and check if any devices obtained from your GW ?

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

Could you please add a small pause after using and before GetDevices method like

Thread.Sleep or Task.Delay for 5 seconds and check if any devices obtained from your GW ?
Tested it on my PC connected to the same with Gateway router via Ethernet cable.
Deley did not help. miHome.GetDevices() is still empty collection. And miHome.GetGateway() is still null. :(

from mi-home.

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

Do you use any technologies like VirtualBox or VPN that may block UDP multicast traffic on your PC ? I saw similar symptoms in another issue #7 (comment)

from mi-home.

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

Also please try to run this simple python script on some device inside your LAN

import struct
from socket import *

print("Start listening socket ...")
s = socket(AF_INET, SOCK_DGRAM, SOL_UDP)
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
s.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, struct.pack('4sL', inet_aton('224.0.0.50'), INADDR_ANY))
s.bind(('', 9898))
s.sendto('{\"cmd\":\"get_id_list\"}'.encode(),  ('224.0.0.50', 9898))

while True:
	data, x = s.recvfrom(2046)
	print(x, data)

You should see that data are going back and forth, if they not it means that something is blocking your UDP multicasts.
What it could be ? This is a very interesting question.
From my experience it could be everything starting from your OS network settings till router/firewall.

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

Do you use any technologies like VirtualBox or VPN that may block UDP multicast traffic on your PC ? I saw similar symptoms in another issue #7 (comment)

I had only this driver
image
But it is already disabled.
Have no other ideas about what can block the traffic.

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

Also please try to run this simple python script on some device inside your LAN

I tried it on my PC and Notebook.
When the script is started on PC and I start it on Notebook - 1 more log line appends on PC (last 3 lines).
image

When I start the new script instance on PC with an already launched instance on Notebook - log with 192.168.0.101 appends.
image

So, as for me, result of this investigation are:

  • PC is on 192.168.0.101
  • Notebook is on 192.168.0.103
  • The UDP multicast connection is not blocked by anything.

from mi-home.

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

This logs shows that UDP traffic is blocked by something because you don't get any response

from mi-home.

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

This is how NOT blocked UDP multicast should looks like

Start listening socket ...
(('192.168.1.14', 9898), '{"cmd":"get_id_list"}')
(('192.168.1.12', 9898), '{"cmd":"get_id_list_ack","sid":"34ce0088db36","token":"mWnYERoTKhukKxKQ","data":"[\\"158d0001826509\\",\\"158d00015dc662\\",\\"158d00015dc6cc\\",\\"158d000182e561\\",\\"158d000182e3aa\\",\\"158d0001826527\\",\\"158d000182dfbc\\",\\"158d000187437b\\",\\"158d00011c0754\\",\\"158d000156a94b\\",\\"158d0001874ad8\\",\\"158d00015a9b17\\",\\"158d0001214e1f\\",\\"158d00015da18e\\",\\"158d0001255529\\",\\"158d0001255565\\",\\"158d00012554c0\\",\\"158d0001116fec\\",\\"158d0001d545d0\\",\\"158d0001d593e2\\",\\"158d0001db9340\\",\\"158d0001d8f839\\",\\"158d0001d948a0\\",\\"158d0001d8f8f7\\"]"}')
(('192.168.1.12', 4321), '{"cmd":"heartbeat","model":"gateway","sid":"34ce0088db36","short_id":"0","token":"gnj2xHQfFHq6LjlG","data":"{\\"ip\\":\\"192.168.1.12\\"}"}')
(('192.168.1.12', 4321), '{"cmd":"report","model":"motion","sid":"158d0001214e1f","short_id":19149,"data":"{\\"status\\":\\"motion\\"}"}')

There are requests and responses here from GW here
In your case something is blocking UDP responses from GW, probably non-standard OS network stack configuration

from mi-home.

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

@shatulsky could you please temporary uninstall VirtualBox NDIS driver (reboot) and double check UDP traffic again ?

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

@shatulsky could you please temporary uninstall VirtualBox NDIS driver (reboot) and double check UDP traffic again ?

The results are the same.

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

I looked at Wireshark report and I'm actually receiving some responses from 192.168.0.102 device
Maybe it will help you
image

Here are different logs related to 192.168.0.102

15483	1177.329532	192.168.0.102	224.0.0.251	MDNS	365	Standard query response 0x0000 A, cache flush 192.168.0.102 SRV, cache flush 0 0 54321 lumi-gateway-v3_miio259423508.local PTR lumi-gateway-v3_miio259423508._miio._udp.local TXT, cache flush
14600	1072.813689	192.168.0.102	224.0.0.251	MDNS	489	Standard query 0x0000 ANY lumi-gateway-v3_miio259423508.local, "QM" question ANY 102.0.168.192.in-addr.arpa, "QU" question ANY lumi-gateway-v3_miio259423508._miio._udp.local, "QU" question A 192.168.0.102 PTR lumi-gateway-v3_miio259423508.local SRV 0 0 54321 lumi-gateway-v3_miio259423508.local TXT
14615	1074.533231	192.168.0.102	224.0.0.251	MDNS	440	Standard query response 0x0000 A, cache flush 192.168.0.102 PTR lumi-gateway-v3_miio259423508.local SRV, cache flush 0 0 54321 lumi-gateway-v3_miio259423508.local PTR lumi-gateway-v3_miio259423508._miio._udp.local TXT, cache flush
14583	1070.654840	XIAOMIEl_f6:7c:b5	Broadcast	XID	60	Basic Format; Type 1 LLC (Class I LLC); Window Size 1
14588	1070.795978	Tp-LinkT_3d:d1:42	Broadcast	ARP	60	Who has 192.168.0.102? Tell 192.168.0.1
14589	1071.315964	XIAOMIEl_f6:7c:b5	Broadcast	ARP	60	Who has 192.168.0.102? (ARP Probe)
14599	1072.763936	XIAOMIEl_f6:7c:b5	Broadcast	ARP	60	ARP Announcement for 192.168.0.102
14615	1074.533231	192.168.0.102	224.0.0.251	MDNS	440	Standard query response 0x0000 A, cache flush 192.168.0.102 PTR lumi-gateway-v3_miio259423508.local SRV, cache flush 0 0 54321 lumi-gateway-v3_miio259423508.local PTR lumi-gateway-v3_miio259423508._miio._udp.local TXT, cache flush

from mi-home.

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

@shatulsky could you please change multicast addr in the python script above from 224.0.0.50 to 224.0.0.51 and run it again ?
Maybe in newer version of GW or firmware they changed multicast address.

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

224.0.0.51

It did not help.
What about router settings? As for now, I have
image
image
image

The router supports 2 more modes for IPTV
image
image

from mi-home.

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

Is it possible to stop firewall on your router ?

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

Is it possible to stop firewall on your router ?

It was already disabled before I created this issue. I double-checked it, still disabled.

Have you any example of code that will simulate the multicast server. I can try to test this code on the notebook connected to the Wi-Fi hotspot and listen to it using python script, you already sent, from PC. It will help to determine on what side the problem is, network configuration or HUB broadcasting

from mi-home.

sealbro avatar sealbro commented on May 29, 2024

Hello guys! I have the same problem.
After I turn off "VirtualBox Host-Only Network", the python script got useful information

('192.168.1.36', 9898) b'{"cmd":"get_id_list"}' ('192.168.1.52', 9898) b'{"cmd":"get_id_list_ack","sid":"04cf8c982f33","token":"","data":"[\\"158d00031b32c1\\",\\"158d00032170b8\\",\\"158d0002ec3079\\",\\"158d00028999e8\\"]"}' ('192.168.1.52', 4321) b'{"cmd":"heartbeat","model":"gateway","sid":"04cf8c982f33","short_id":"0","token":"","data":"{\\"ip\\":\\"192.168.1.52\\"}"}' ('192.168.1.52', 4321) b'{"cmd":"heartbeat","model":"gateway","sid":"04cf8c982f33","short_id":"0","token":"","data":"{\\"ip\\":\\"192.168.1.52\\"}"}' ('192.168.1.36', 9898) b'{"cmd":"get_id_list"}' ('192.168.1.52', 9898) b'{"cmd":"get_id_list_ack","sid":"04cf8c982f33","token":"","data":"[\\"158d00031b32c1\\",\\"158d00032170b8\\",\\"158d0002ec3079\\",\\"158d00028999e8\\"]"}'

but from dotnet code I get nothing

from mi-home.

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

@pachman could you please specify what version of .net runtime do you use ?
As far as I remember on .net core 2.1 there were some issues with UDP multicast traffic

from mi-home.

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

@shatulsky could you please provide me with the information what .net runtime do you use for your project and OS ?

from mi-home.

sealbro avatar sealbro commented on May 29, 2024

@pachman could you please specify what version of .net runtime do you use ?
As far as I remember on .net core 2.1 there were some issues with UDP multicast traffic

I am using the latest version 3.1

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

@shatulsky could you please provide me with the information what .net runtime do you use for your project and OS ?

The console app is on .net framework 4.7.2.
The installed version is .net framework 4.8

from mi-home.

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

@shatulsky I will try to run your piece of code on the framework mentioned above against my setup router + gw and let you know if it is working

from mi-home.

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

@pachman could you please specify what version of .net runtime do you use ?
As far as I remember on .net core 2.1 there were some issues with UDP multicast traffic

I am using the latest version 3.1

Could you please paste here non-working code ?

from mi-home.

fadidevv avatar fadidevv commented on May 29, 2024

Hi,

your library works with Token Aqara Gateway method or is i need to enable LAN MODE from MI app to get the Password? As you know MI app does not allow anymore to enable LAN MODE from the APP so cannot get password but this library works with UDP mode? Is my Aqara have to connected in my WIFI network to use this library? I test with my Aqara Gateway latest version hardware with wireshark and UDP i can copy but when i use Packet sender to send command via UDP nothing happens is it mean my network have no UDP allow?

Thank you.

from mi-home.

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

hi @fadidevv

  1. This is not necessary, password is required only when you want to "send" commands to your mi home devices like "switch light on" or "turn radio on gw". If you just "read" data from your sensors, password is not needed.

  2. Your application using library MUST run on the same lan segment where your GW is.
    For example if your GW has ip/netmask 192.168.1.1/255, your app must run in the segment 192.168.1.x/255

  3. Not clear what do you mean by "when i use Packet sender to send command via UDP nothing happens". Could you please elaborate a little bit ?

from mi-home.

fadidevv avatar fadidevv commented on May 29, 2024

Thanks for the reply, i see your library use Multicast Traffic method like LAN MODE and you said in docs have to open MI Home app to enable the LAN mode? i tested your library in Aqara HUB v3 but not working i'm on wifi same IP of device and my computer, i try to use UDP method by using wireshark but when i send request with HEX packet nothing shows in devices nothing returns!

from mi-home.

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

@fadidevv could you please at first run python script mentioned above in order to check that UPD multicast traffic is working in your lan segment ?

from mi-home.

fadidevv avatar fadidevv commented on May 29, 2024

@fadidevv could you please at first run python script mentioned above in order to check that UPD multicast traffic is working in your lan segment ?

Hi,

Screen Shot 2020-02-21 at 3 40 40 PM

Nothing returns, my device gateway is paired with my WIFI HOTSPOT in the same network from where i ran this python script.

from mi-home.

fadidevv avatar fadidevv commented on May 29, 2024

And here is the Wireshark logs same as @shatulsky Looks like Aqara Hub Gateway UDP ip has changed take a look @sergey-brutsky

Screen Shot 2020-02-21 at 3 45 22 PM

from mi-home.

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

@shatulsky @fadidevv could you please check that required ports are open on your GW version
nmap -sU <ip of your gw here> -p 9898,4321,54321

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

nmap -sU <ip of your gw here> -p 9898,4321,54321

Starting Nmap 7.80 ( https://nmap.org ) at 2020-02-22 00:02 Oeieyiaey (ceia)
Nmap scan report for 192.168.0.102
Host is up (0.087s latency).

PORT      STATE         SERVICE
4321/udp  closed        rwhois
9898/udp  closed        monkeycom
54321/udp open|filtered bo2k
MAC Address: 04:CF:8C:F6:7C:B5 (Xiaomi Electronics,co.)

Nmap done: 1 IP address (1 host up) scanned in 2.09 seconds

from mi-home.

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

@shatulsky @fadidevv it looks like that manufacturer on some versions of GW closed ports required for normal UDP multicast working.
Please check this issue --> https://community.openhab.org/t/solved-openhab2-xiaomi-mi-gateway-does-not-respond/52963/107

I found an instruction how to open required ports --> https://community.openhab.org/t/solved-openhab2-xiaomi-mi-gateway-does-not-respond/52963/114

Could you guys check if the library working after opening ports by using the instructions above ?
Thanks

from mi-home.

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

@shatulsky @fadidevv guys, did you have a chance to check if the method mentioned above is working ?

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

@shatulsky @fadidevv guys, did you have a chance to check if the method mentioned above is working ?

I tried the suggested method. But my putty output is empty.
I'm going to make a few more attempts soon. I'll keep in touch.

from mi-home.

fadidevv avatar fadidevv commented on May 29, 2024

@sergey-brutsky Nothing returns everything is empty, as i understand the new hardware models from Aqara don't work anymore with local-LAN networks i apply for Aqara Cloud and they approve my account and can only use Aqara Cloud APIS via HTTP, LAN mode only works with some Aqara devices.

I'm going to reverse the Aqara or MI Home APP and bypass the security like signatures-random in request headers and i will make HTTP APIS for Aqara.

from mi-home.

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

@fadidevv what is this command nmap -sU <ip of your gw here> -p 9898,4321,54321 output ?

from mi-home.

shatulsky avatar shatulsky commented on May 29, 2024

@shatulsky @fadidevv guys, did you have a chance to check if the method mentioned above is working ?

I successfully changed network.open_pf property on Gateway using this instruction. I have one more clarification that may help someone in the future. On the screenshot attached to the instruction RX and TX are the gateway connectors but not UART cable. So you should connect UART RX to TX on the screenshot and UART TX to RX on the screenshot.

After that gateway opened its ports.

nmap -sU 192.168.0.102 -p 9898,4321,54321
4321/udp  open|filtered rwhois
9898/udp  open          monkeycom
54321/udp open|filtered bo2k

Python script receives some data -

Start listening socket ...
('192.168.0.103', 9898) b'{"cmd":"get_id_list"}'
('192.168.0.102', 9898) b'{"cmd":"get_id_list_ack","sid":"04cf8cf67cb5","token":"adRtLQrrjS2QrO7m","data":"[\\"158d00034de7ed\\"]"}'
('192.168.0.102', 4321) b'{"cmd":"heartbeat","model":"gateway","sid":"04cf8cf67cb5","short_id":"0","token":"Kw8DMSRNp2oRsTkl","data":"{\\"ip\\":\\"192.168.0.102\\"}"}'

And now I can see gateway responses using your library.
image

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.