--
You received this message because you are subscribed to the Google Groups "Signal K" group.
To unsubscribe from this group and stop receiving emails from it, send an email to signalk+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/signalk/c2e3e139-df0b-44b7-b498-e21222cd7e04n%40googlegroups.com.
import paramiko
import time
import requests
def connect_to_victron(hostname, port, username, password, remote_port):
try:
# Initialize the SSH client
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect to the Victron device via SSH
print("Connecting to Victron device...")
ssh.connect(hostname, port=port, username=username, password=password)
# Open an SSH tunnel to the Signal K server port (default is usually 3000 or similar)
transport = ssh.get_transport()
print("Setting up port forwarding...")
channel = transport.open_channel("direct-tcpip", ("localhost", remote_port), ("127.0.0.1", 0))
print("Connection established. Ready to access Signal K server through the tunnel.")
# Perform any additional steps, such as making requests to the Signal K server here
# BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
url = f"http://192.168.1.175:3000/signalk/v1/vessels/self"
try:
# Send a request to the Signal K server
response = requests.get(url)
response.raise_for_status() # Raise an error for bad status codes
data = response.json() # Parse JSON response
# Output the Signal K server data
print("Signal K Server Data:", data)
except requests.RequestException as e:
print("Error accessing Signal K server:", e)
#BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBb
time.sleep(10) # Keep connection open for testing; adjust as needed
# Close the SSH connection and tunnel after use
channel.close()
ssh.close()
print("Connection closed.")
except Exception as e:
print(f"An error occurred: {e}")
# Replace these variables with your Victron GX device details
hostname = "192.168.1.175" # IP of the Victron device
port = 22 # Default SSH port
username = "root"
password = "tombraider"
remote_port = 3000 # Port of the Signal K server on the Victron GX device
# Connect to the device
connect_to_victron(hostname, port, username, password, remote_port)
To view this discussion visit https://groups.google.com/d/msgid/signalk/CAODtcde5Ba4agwvujseJ0c%3DGSn4yULgCF49wordaafzp4QUfFw%40mail.gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/signalk/CAODtcde5Ba4agwvujseJ0c%3DGSn4yULgCF49wordaafzp4QUfFw%40mail.gmail.com.