Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
app-notes:set-fixed-frame [2026/09/30 10:55] – [3. Additional information] grayapp-notes:set-fixed-frame [2026/09/30 15:05] (current) – [3. Additional information] gray
Line 142: Line 142:
 ~ $ vi /etc/lxc/guest0/config ~ $ vi /etc/lxc/guest0/config
                                                                                                                        
-# Setting up a USB flash drive in the LXC container +# Setting up a USB drive in the LXC container 
 lxc.cgroup.devices.allow = c 188:1 rwm lxc.cgroup.devices.allow = c 188:1 rwm
 lxc.mount.entry = /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file 0 0    lxc.mount.entry = /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file 0 0   
Line 156: Line 156:
 <konsole> <konsole>
 ~ $ lxc-attach guest0 ~ $ lxc-attach guest0
-root@LXCNAME:~# apt install gpsd python3-gpsapt gpsd-clients python3-paramiko nano+root@LXCNAME:~# apt install gpsd python3-gps gpsd-clients python3-paramiko nano
 root@LXCNAME:~# root@LXCNAME:~#
 </konsole> </konsole>
Line 359: Line 359:
 <konsole> <konsole>
 root@LXCNAME:~/ubx_neo_m8l# python3 ssh_start.py 10 root@LXCNAME:~/ubx_neo_m8l# python3 ssh_start.py 10
-Setze gpsd.0.status=0 ... +Setze gpsd.1.status=0 ... 
-Versuch 1/2: rufe set_cfg_rate_neom8l.py auf...+Versuch 1/2: call set_cfg_rate_neom8l.py on...
 STDOUT:  STDOUT: 
 STDERR: 2026-09-30 10:39:20,427 INFO     instantiating GnssUBlox on tty STDERR: 2026-09-30 10:39:20,427 INFO     instantiating GnssUBlox on tty
Line 368: Line 368:
 root@LXCNAME:~/ubx_neo_m8l# root@LXCNAME:~/ubx_neo_m8l#
 </konsole> </konsole>
 +
 +Then test the whole thing with a get script.
 +
 +<konsole>
 +root@LXCNAME:~/ubx_neo_m8l# python3 get_cfg_rate_neom8l.py 
 +2026-09-30 11:53:44,917 INFO     instantiating GnssUBlox on tty
 +2026-09-30 11:53:44,917 INFO     using device /dev/ttyUSB1
 +UBX-CFG-RATE cls:06 id:08
 +  measRate: 100
 +  navRate: 1
 +  timeRef: 0
 +root@LXCNAME:~/ubx_neo_m8l# 
 +</konsole>
 +
  
 ---- ----
Line 397: Line 411:
     rate_hz = int(sys.argv[1])     rate_hz = int(sys.argv[1])
     if not (1 <= rate_hz <= 10):     if not (1 <= rate_hz <= 10):
-        raise ValueError+        raise ValueErro
 except ValueError: except ValueError:
     print("Error: frame interval must be an integer between 1 and 10")     print("Error: frame interval must be an integer between 1 and 10")
Line 421: Line 435:
 </code> </code>
 ++++ ++++
 +
 +----
 +
 +Download the ''ssh_start.py'' python script:
 +
 +++++show code| 
 +<code – ssh_start.py>
 +#!/usr/bin/python3
 +"""
 +Establish an SSH connection (key-based) to the router, briefly disable gpsd
 +(wwanmd toggles the port from down to up, leaving it briefly free), and within that window
 +call set_cfg_rate_neom8l.py with the desired rate_hz value, and then
 +re-enable gpsd.
 +
 +Calling the subroutine:
 +python3 run_set_rate.py <rate_hz>
 +"""
 +import paramiko
 +import subprocess
 +import time
 +import sys
 +
 +HOST = "192.168.1.1"                  # The router's IP address as seen from the container
 +PORT = 22
 +USER = "root"
 +SSH_KEY_PATH = "/root/.ssh/id_rsa"    # Path to the private SSH key
 +RETRY_COUNT = 2                       # attempts
 +RETRY_DELAY = 0.5                     # Seconds between attempts
 +
 +
 +def run_remote_command(client, cmd):
 +    stdin, stdout, stderr = client.exec_command(cmd)
 +    out = stdout.read().decode().strip()
 +    err = stderr.read().decode().strip()
 +    status = stdout.channel.recv_exit_status()
 +    return status, out, err
 +
 +
 +def main():
 +    if len(sys.argv) != 2:
 +        print(f"Usage: {sys.argv[0]} <rate_hz>   (allowed: 1-10)")
 +        sys.exit(1)
 +
 +    try:
 +        rate_hz = int(sys.argv[1])
 +        if not (1 <= rate_hz <= 10):
 +            raise ValueError
 +    except ValueError:
 +        print("Error: rate_hz must be an integer between 1 and 10.")
 +        sys.exit(1)
 +
 +    # Establish an SSH Connection to the Router ''Key-Based''
 +    key = paramiko.RSAKey.from_private_key_file(SSH_KEY_PATH)
 +
 +    client = paramiko.SSHClient()
 +    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
 +    client.connect(HOST, port=PORT, username=USER, pkey=key, timeout=10)
 +
 +    try:
 +        # Disable gpsd -> wwanmd toggles the port; it is open for a short time
 +        print("Set gpsd.1.status=0 ...")
 +        run_remote_command(client, 'cli set -s gpsd.1.status="0"')
 +
 +        success = False
 +        for attempt in range(1, RETRY_COUNT + 1):
 +            print(f"Experiment {attempt}/{RETRY_COUNT}: call set_cfg_rate_neom8l.py on...")
 +            result = subprocess.run(
 +                ["python3", "set_cfg_rate_neom8l.py", str(rate_hz)],
 +                capture_output=True, text=True, timeout=10
 +            )
 +            print("STDOUT:", result.stdout)
 +            if result.stderr:
 +                print("STDERR:", result.stderr)
 +
 +            if result.returncode == 0 and "SerialException" not in result.stderr:
 +                success = True
 +                break
 +
 +            time.sleep(RETRY_DELAY)
 +
 +        if not success:
 +            print("Note: set_cfg_rate_neom8l.py failed to run successfully in all attempts.")
 +
 +    finally:
 +        # Turn gpsd back on
 +        print("Set gpsd.0.status=1 ...")
 +        run_remote_command(client, 'cli set -s gpsd.1.status="1"')
 +        client.close()
 +
 +if __name__ == "__main__":
 +    main()
 +</code>
 +++++
 +
 +----
 +Download the library ''ubxlib'':
 +
 +
 +Program library ''ubxlib'' for the Python script / [[https://files.netmodule.com/share/JoIjsXPj|Link]]
 +
 +The password for downloading the library : ''gnss_cfg_rate''
 +
 +----
 +
 +Download the ''get_cfg_rate_neom8l.py'' python script: 
 +
 +++++show code| 
 +<code – get_cfg_rate_neom8l.py>
 +#!/usr/bin/python3
 +"""
 +Retrieves the current UBX-CFG-RATE configuration (navigation rate) from the module
 +"""
 +import logging
 +
 +from ubxlib.server_tty import GnssUBlox
 +from ubxlib.ubx_cfg_rate import UbxCfgRatePoll   
 +
 +FORMAT = '%(asctime)-15s %(levelname)-8s %(message)s'
 +logging.basicConfig(format=FORMAT)
 +logger = logging.getLogger('ubxlib')
 +logger.setLevel(logging.INFO)
 +
 +ubx = GnssUBlox('/dev/ttyUSB1')
 +ubx.setup()
 +
 +poll_msg = UbxCfgRatePoll()
 +response = ubx.poll(poll_msg) 
 +print(response)
 +
 +ubx.cleanup()
 +</code>
 +++++
 +
 +----
 +