PyVantagePro help

I am attempting to use the package PyVantagePro (PyVantagePro · PyPI) to connect to my Davis Vantage Pro2 personal weather station. My problem is in the line:
device = VantagePro2.from_url(‘tcp:host-ip:port’)
in my case this is:
device = VantagePro2.from_url(‘tcp:192.168.1.20:5’)
The resulting error message says “WinError 10061 No connection could be made because the target machine actively refused it.”
I know the usb device works because Davis software successfully communicates with the weather station.
I know the device driver port number because Windows device manager reports USBXpress device 5, hub 5.
I know that this is the device in question because I plug/unplug the weather station to isolate it.
However, when I change the port number is my code to e.g. 99, I get the same error message. Consequently, I don’t think I am understanding what “port” means. Any insights would be helpful. Thanks in advance.
(more data: “pyvantagepro --version” from command line results in error)

Port numbers used in the TCP/IP protocol are used as an extension of the IP address. For example, a HTTP server will ‘listen’ on port 80. A ftp server, on port 21 and so on. So, what you’ll need to discover is which port the device is setup to ‘listen’ on.

You can use a ‘port scanner’ for this, but it’s not guaranteed to work, because scanners can be blocked at the receiving end.

Do you have any documentation for the Weather Station, that tells you which TCP/IP port number to use?

To add: my best guess is that the device has built-in http server, to which you can connect via port 80, but that would be for (again, my best guess) configurations and the like and may very well use a different port number for whatever it is that PyVantagePro is doing.

In the examples I see here port 1111 is being used.

Indeed, this is fallacious. Windows uses its own numbering for locally connected devices just to keep track of how many things are connected. A TCP port number is entirely unrelated to that. They’re used, basically, so that a given device (with a specific IP address, like 192.168.1.20 in your case) can provide multiple different Internet services (email, HTTP, etc.). Most application-specific uses will use a port number 1024 and up (to the limit of 65535, as the value is represented in the underlying protocol with an unsigned 16-bit number).

The Wikipedia chart suggests port 22222 is used by Davis devices, but I couldn’t find confirmation of that on the Davis web site. As Rob noted, the documentation examples show port 1111.

If you have packet-sniffing software such as Wireshark, you could try using it while the Davis software is running, to see what port it uses for communication.

This is most likely a separate problem that does not help understand the current one; but with a complete error message we may be able to figure it out as well.

Hi Rob & Karl - thank you both for your quick and insightful suggestions which pointed me in the right direction. But I didn’t get very far. I have tried all of the port numbers suggested as well as several others found on the web and suggested by chatGPT (!). I am pretty sure that 22222 is the port number, but that still does not work (same error message). Using the Davis/Weatherlink software I can select the TCP/IP port whose default setting is 22222, consequently, I think the problem may be with the pyvantagepro package - I’m working on it - thanks again.

You’re welcome.

I have this basic script that I’ve pulled together. It may or may not be of help to you, but it could help you to discover what your device is responding to:

#!/usr/bin/python3

import socket
import os


def portscanner(host, port):
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client:
        socket.setdefaulttimeout(3)
        if client._closed:
            print(f"Port {port} is closed")
            port_open = False
        else:
            try:
                client.connect((host, port))
                print(f"Port {port} is open and excepting connections.\n")
                port_open = True
            except socket.timeout as timed_out:
                print(f"Port {port} {timed_out}; possibly blocked by a Firewall.\n")
                port_open = False
            except ConnectionRefusedError as error:
                print(f"Port {port} {error}")
                print("The port either does not exist or is in stealth mode.\n")
                port_open = False
        if port == 80 and port_open:
            port_80(client, host)
    return port_open


def port_80(client, host):
    # send some data
    data = bytes(f"GET / HTTP/1.1\r\nHost: {host}\r\n\r\n", 'UTF-8')
    client.send(data)
    # receive some data
    response = client.recv(4096)
    print(response.decode())
    return


ip_address = '192.168.1.1'  # you'll need to change this to your device IP Address
port_scan = [21, 22, 80]  # include any port number you need here

for port in port_scan:
    portscanner(ip_address, port)

I’ve not run this on a MS Windows OS as I’m a Linux user, so it may or may not work for you, as is.

Thank you, Rob. I am focusing on the pyvantagepro package errors and investigating using a serial connection.

1 Like