知乎专栏 |
apt install gpsd gpsd-clients gpsd-tools
root@homeassistant:~# stty speed 115200 -F /dev/ttyACM0 9600
配置 GPS 设备,修改 /etc/default/gpsd 配置文件
root@homeassistant:~# cat /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="/dev/ttyACM0" # Other options you want to pass to gpsd GPSD_OPTIONS="" # Automatically hot add/remove USB GPS devices via gpsdctl USBAUTO="true"
默认 gpds 开启 ipv6,有些系统已经禁用了ipv6,就会出现下面的错误
Jun 26 17:11:11 homeassistant systemd[15955]: gpsd.socket: Failed to create listening socket ([::1]:2947): Cannot assign requested address Jun 26 17:11:11 homeassistant systemd[1]: gpsd.socket: Failed to receive listening socket ([::1]:2947): Input/output error Jun 26 17:11:11 homeassistant systemd[1]: gpsd.socket: Failed to listen on sockets: Input/output error Jun 26 17:11:11 homeassistant systemd[1]: gpsd.socket: Failed with result 'resources'. Jun 26 17:11:11 homeassistant systemd[1]: Failed to listen on GPS (Global Positioning System) Daemon Sockets. Jun 26 17:13:14 homeassistant systemd[16112]: gpsd.socket: Failed to create listening socket ([::1]:2947): Cannot assign requested address Jun 26 17:13:14 homeassistant systemd[1]: gpsd.socket: Failed to receive listening socket ([::1]:2947): Input/output error Jun 26 17:13:14 homeassistant systemd[1]: gpsd.socket: Failed to listen on sockets: Input/output error Jun 26 17:13:14 homeassistant systemd[1]: gpsd.socket: Failed with result 'resources'. Jun 26 17:13:14 homeassistant systemd[1]: Failed to listen on GPS (Global Positioning System) Daemon Sockets.
屏蔽 #ListenStream=[::1]:2947 这行
root@homeassistant:~# vim /lib/systemd/system/gpsd.socket [Unit] Description=GPS (Global Positioning System) Daemon Sockets [Socket] ListenStream=/run/gpsd.sock #ListenStream=[::1]:2947 ListenStream=127.0.0.1:2947 # To allow gpsd remote access, start gpsd with the -G option and # uncomment the next two lines: # ListenStream=[::]:2947 # ListenStream=0.0.0.0:2947 SocketMode=0600 BindIPv6Only=yes [Install] WantedBy=sockets.target
root@homeassistant:~# systemctl daemon-reload root@homeassistant:~# systemctl restart gpsd.socket root@homeassistant:~# systemctl status gpsd.socket ● gpsd.socket - GPS (Global Positioning System) Daemon Sockets Loaded: loaded (/lib/systemd/system/gpsd.socket; enabled; vendor preset: enabled) Active: active (listening) since Mon 2023-06-26 17:14:51 CST; 4min 0s ago Triggers: ● gpsd.service Listen: /run/gpsd.sock (Stream) 127.0.0.1:2947 (Stream) Tasks: 0 (limit: 2182) Memory: 8.0K CGroup: /system.slice/gpsd.socket Jun 26 17:14:51 homeassistant systemd[1]: Listening on GPS (Global Positioning System) Daemon Sockets. root@homeassistant:~# systemctl restart gpsd root@homeassistant:~# systemctl status gpsd ● gpsd.service - GPS (Global Positioning System) Daemon Loaded: loaded (/lib/systemd/system/gpsd.service; disabled; vendor preset: enabled) Active: active (running) since Mon 2023-06-26 17:22:12 CST; 5s ago TriggeredBy: ● gpsd.socket Process: 16904 ExecStart=/usr/sbin/gpsd $GPSD_OPTIONS $OPTIONS $DEVICES (code=exited, status=0/SUCCESS) Main PID: 16905 (gpsd) Tasks: 1 (limit: 2182) Memory: 508.0K CGroup: /system.slice/gpsd.service └─16905 /usr/sbin/gpsd /dev/ttyACM0 Jun 26 17:22:12 homeassistant systemd[1]: Starting GPS (Global Positioning System) Daemon... Jun 26 17:22:12 homeassistant systemd[1]: Started GPS (Global Positioning System) Daemon.