rkaczorek / virtualgps

Virtual GPS simulates GPS receiver available on pseudo terminal
GNU General Public License v3.0
21 stars 11 forks source link

Virtualgps service error #8

Closed Astro-Otter-Space closed 1 year ago

Astro-Otter-Space commented 2 years ago

Hi, it seems i have the same problem than issue #3 , i've remove the symlink like you say, stop service.

hamham@astroloutre:~/www/virtualgps$ sudo systemctl stop virtualgps.service
hamham@astroloutre:~/www/virtualgps$ sudo rm -rf /tmp/vgps
hamham@astroloutre:~/www/virtualgps$ python3 virtualgps.py 
# nothing...
hamham@astroloutre:~/www/virtualgps$ sudo rm -rf /tmp/vgps
hamham@astroloutre:~/www/virtualgps$ sudo -u gpsd python3 virtualgps.py
# nothing...

My file /etc/location.conf :

# Location Grabels (34), France
[default]
latitude  = 43.64741
longitude = 3.803566
elevation = 85.0

I'm starting service :

hamham@astroloutre:~/www/virtualgps$ sudo systemctl restart virtualgps.service
hamham@astroloutre:~/www/virtualgps$ sudo -u gpsd python3 virtualgps.py
Traceback (most recent call last):
  File "virtualgps.py", line 93, in <module>
    os.symlink(pty,virtualgps_dev)
FileExistsError: [Errno 17] File exists: '/dev/pts/2' -> '/tmp/vgps'

Service status :

hamham@astroloutre:~/www/virtualgps$ systemctl status virtualgps.service 
● virtualgps.service - Virtual GPS
     Loaded: loaded (/etc/systemd/system/virtualgps.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-08-11 13:46:18 CEST; 1min 38s ago
    Process: 2865 ExecStartPost=/bin/sleep 3 (code=exited, status=0/SUCCESS)
    Process: 2868 ExecStartPost=/usr/sbin/gpsdctl add /tmp/vgps (code=exited, status=0/SUCCESS)
   Main PID: 2864 (python3)
      Tasks: 1 (limit: 1864)
     CGroup: /system.slice/virtualgps.service
             └─2864 /usr/bin/python3 /usr/bin/virtualgps.py

août 11 13:46:18 astroloutre systemd[1]: Started Virtual GPS.
août 11 13:46:21 astroloutre gpsdctl[2868]: gpsd_control(action=add, arg=/tmp/vgps) # this line is in red on CLI
août 11 13:46:21 astroloutre gpsdctl[2868]: reached a running gpsd

Did i miss something ?

Conf: Raspberry Pi 3 model b+ Ubuntu Mate 20.04

rkaczorek commented 2 years ago

If you run this:

hamham@astroloutre:~/www/virtualgps$ sudo systemctl restart virtualgps.service
hamham@astroloutre:~/www/virtualgps$ sudo -u gpsd python3 virtualgps.py

you obviously get error because after the first command the script is running as a service and /tmp/vgps exists. That's why the second command complaints about it. No compaints means everything is ok, so #nothing means OK. Stop the service, remove the file, start the service, check service status, run gpsmon or cgps and check your virtual location.

Astro-Otter-Space commented 2 years ago

Here's what i have doing following your instructions after boot my rpi :

# stop service
hamham@astroloutre:~$ sudo systemctl stop virtualgps.service

# delete /tmp/vgps
hamham@astroloutre:~$ sudo rm /tmp/vgps
rm: cannot remove '/tmp/vgps': No such file or directory

# restart and check status
hamham@astroloutre:~$ sudo systemctl start virtualgps.service
hamham@astroloutre:~$ sudo systemctl status virtualgps.service
● virtualgps.service - Virtual GPS
     Loaded: loaded (/etc/systemd/system/virtualgps.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-08-17 17:35:14 CEST; 7s ago
    Process: 2534 ExecStartPost=/bin/sleep 3 (code=exited, status=0/SUCCESS)
    Process: 2535 ExecStartPost=/usr/sbin/gpsdctl add /tmp/vgps (code=exited, status=0/SUCCESS)
   Main PID: 2533 (python3)
      Tasks: 1 (limit: 1864)
     CGroup: /system.slice/virtualgps.service
             └─2533 /usr/bin/python3 /usr/bin/virtualgps.py

août 17 17:35:14 astroloutre systemd[1]: Started Virtual GPS.
août 17 17:35:17 astroloutre gpsdctl[2535]: gpsd_control(action=add, arg=/tmp/vgps)
août 17 17:35:17 astroloutre gpsdctl[2535]: reached a running gpsd

Line gpsd_control(action=add, arg=/tmp/vgps) is in red (error ?)

I'm checking if copy are OK :

hamham@astroloutre:~$ ll /usr/bin/ | grep virtualgps
-rw-r--r--  1 root root        4576 août  10 15:16 virtualgps.py

hamham@astroloutre:~$ ll /etc/systemd/system/ | grep virtualgps
-rw-r--r--  1 root root  380 août  10 15:16 virtualgps.service

Seems OK

I'm checking with cgps command :

┌───────────────────────────────────────────┐┌──────────────────Seen  0/Used  0┐
│ Time:            n/a                      ││     PRN  Elev   Azim   SNR  Use │
│ Latitude:        n/a                      ││                                 │
│ Longitude:       n/a                      ││                                 │
│ Alt (HAE, MSL):        n/a,       n/a     ││                                 │
│ Speed:           n/a                      ││                                 │
│ Track (true, var):                n/a deg ││                                 │
│ Climb:           n/a                      ││                                 │
│ Status:         NO FIX (0 secs)           ││                                 │
│ Long Err  (XDOP, EPX):  n/a ,  n/a        ││                                 │
│ Lat Err   (YDOP, EPY):  n/a ,  n/a        ││                                 │
│ Alt Err   (VDOP, EPV):  n/a ,  n/a        ││                                 │
│ 2D Err    (HDOP, CEP):  n/a ,  n/a        ││                                 │
│ 3D Err    (PDOP, SEP):  n/a ,  n/a        ││                                 │
│ Time Err  (TDOP):       n/a               ││                                 │
│ Geo Err   (GDOP):       n/a               ││                                 │
│ ECEF X, VX:              n/a    n/a       ││                                 │
│ ECEF Y, VY:              n/a    n/a       ││                                 │
│ ECEF Z, VZ:              n/a    n/a       ││                                 │
│ Speed Err (EPS):        n/a               ││                                 │
│ Track Err (EPD):        n/a               ││                                 │
│ Time offset:            n/a               ││                                 │
│ Grid Square:            n/a               ││                                 │
└───────────────────────────────────────────┘└─────────────────────────────────┘

{"class":"VERSION","release":"3.20","rev":"3.20","proto_major":3,"proto_minor":14}
{"class":"DEVICES","devices":[]}
{"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false}

and gpsmon return this :

tcp://localhost:2947          JSON slave driver>
(82) {"class":"VERSION","release":"3.20","rev":"3.20","proto_major":3,"proto_minor":14}
(32) {"class":"DEVICES","devices":[]}
(122) {"class":"WATCH","enable":true,"json":false,"nmea":false,"raw":2,"scaled":false,"timing":false,"split24":false,"pps":true}
rkaczorek commented 2 years ago

Please run ls -al /tmp/vgps after running sudo systemctl status virtualgps.service and post the output here

Astro-Otter-Space commented 2 years ago
hamham@astroloutre:~$ sudo systemctl status virtualgps.service
● virtualgps.service - Virtual GPS
     Loaded: loaded (/etc/systemd/system/virtualgps.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-08-17 17:35:14 CEST; 52min ago
   Main PID: 2533 (python3)
      Tasks: 1 (limit: 1864)
     CGroup: /system.slice/virtualgps.service
             └─2533 /usr/bin/python3 /usr/bin/virtualgps.py

août 17 17:35:14 astroloutre systemd[1]: Started Virtual GPS.
août 17 17:35:17 astroloutre gpsdctl[2535]: gpsd_control(action=add, arg=/tmp/vgps)
août 17 17:35:17 astroloutre gpsdctl[2535]: reached a running gpsd

hamham@astroloutre:~$ ls -al /tmp/vgps
lrwxrwxrwx 1 gpsd dialout 10 août  17 17:35 /tmp/vgps -> /dev/pts/0
rkaczorek commented 2 years ago

It looks like /tmp/vgps file is accessible to gpsd service but it is not addedd/recognized. Strange, I must say. What is you /etc/default/gpsd content?

Astro-Otter-Space commented 2 years ago
hamham@astroloutre:~$ more /etc/default/gpsd
# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES=""

# Other options
ecalandrini commented 1 year ago

hi! i'm not an expert but i had the same problem and i found a solution here

https://chollinger.com/blog/2022/09/tiny-telematics-tracking-my-trucks-location-offline-with-a-raspberry-pi-redis-kafka-and-flink-part-2/

longstory short: using apparmor and set /usr/sbin/gpsd to complain mode

sudo apt install apparmor-profiles apparmor-utils sudo aa-complain /PATH/TO/gpsd

please @rkaczorek check if this solution could work for everybody

rkaczorek commented 1 year ago

It looks like apparmor prevents gpsd from accessing virtual gps device file (/tmp/vgps -> /dev/pts/[0-9]) The best way to approach it is adding /dev/pts/[0-9] rw, to /etc/apparmor.d/usr.sbin.gpsd just below /tmp/gpsfake-*.sock rw,. Then run sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.gpsd to reload the apparmor profile