#!/usr/bin/python import requests import sys,json,os #find current ip address of preferred NIC routes = json.loads(os.popen("ip -j -4 route").read()) for r in routes: if r.get("dev") == "wlan0" and r.get("prefsrc"): ip = r['prefsrc'] continue bcast=ip.split(".") bcastAdd = bcast[0] + "." + bcast[1] + "." + bcast[2] + ".255" #broadcast address bcastport = 4001 #whatever port is required #############login and get a key session = requests.session() URL = 'http://localhost:3000/signalk/v1/auth/login' login_data = { 'action': 'login', 'username': 'admin', 'password': 'secretPassword!' } r = session.post(URL,data=login_data) jauthkey=session.cookies.get_dict()['JAUTHENTICATION'] ###################### #update UDP NMEA0183 with what might be a new address. headers = {"Cookie":"JAUTHENTICATION=" + jauthkey,"content-type":"application/json"}#credentials fetched from above. destinations = {"configuration":{"destinations":[{"broadcastAddress": bcastAdd,"port": bcastport,"nmea0183": True,"nmea0183out": False,"lineDelimiter": "None"}]},"enabled": True} s = session.post('http://127.0.0.1:3000/skServer/plugins/udp-nmea-sender/config',json = destinations,headers=headers) print(s.text)