基于traccar快捷搭建gps轨迹应用

0. 环境

- win10 +虚拟机ubuntu18
- i5 ubuntu22笔记本
- USB-GPS模块一台,比如华大北斗TAU1312-232板
- 双笔记本组网设备:路由器,使得win10笔记本ip:192.168.123.x,而i5笔记本IP是192.168.123.215。
- 安卓 手机

1. 搭建traccar服务

1.0 环境

ubuntu22 + i5笔记本

1.1 安装docker

$ sudo apt remove docker docker-engine docker && 
sudo apt update && 
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common && 
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - && 
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" && 
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8
$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io
$ sudo systemctl status docker
$ sudo systemctl restart docker
$ sudo docker run hello-world

1.2 跟着教程安装docker traccar


1.2.1 Create work directories:

mkdir -p /opt/traccar/logs

1.2.2 Get default traccar.xml:

docker run 
--rm 
--entrypoint cat 
traccar/traccar:latest 
/opt/traccar/conf/traccar.xml > /opt/traccar/traccar.xml

1.2.3 Create container:

docker run 
--name traccar 
--hostname traccar 
--detach --restart unless-stopped 
--publish 80:8082 
--publish 5000-5150:5000-5150 
--publish 5000-5150:5000-5150/udp 
--volume /opt/traccar/logs:/opt/traccar/logs:rw 
--volume /opt/traccar/traccar.xml:/opt/traccar/conf/traccar.xml:ro 
traccar/traccar:latest

 

 

2. 手机测试效果

安卓手机安装traccar client 。
手机浏览器打开https://www.traccar.org/client/,下载apk后安装。服务器地址改为搭建了traccar服务的i5笔记本ip,默认端口是5055。

 

 

电脑登录traccar服务器的web,添加手机设备编码到账户下。

设置完毕后,可以看到手机在线。注意手机和服务器在同一个路由器下。 

 

 

3. win10笔记本作为客户端


3.0 环境

ubuntu18虚拟机 + gps机

3.1 验证gps

minicom -s 配置ttyUSB0,波特率115200
有数据再进行下一步。

注意:如果没有收到 GPS 数据,可能是权限问题导致的。执行下面命令将当前用户(非 root 用户)添加到 dialout 用户组,然后重启系统后再次尝试。
 

sudo usermod -a -G dialout $USER
reboot


 
3.2 apt直接安装gpsd

sudo apt install gpsd gpsd-clients

 
以 systemd 方式启动 gpsd 服务

sudo systemctl start gpsd

以 systemd 方式停止 gpsd 服务,原因是gpsd默认的配置不正常,不是ttyUSB0

sudo systemctl stop gpsd.socket

查看 gpsd 服务状态

sudo systemctl status gpsd

启动一个新的gpsd实例,该实例将正确的串行端口的数据重定向到套接字:

sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock

启动 cgps 客户端观测数据:

cgps

启动 gpsmon 客户端观测数据:

gpsmon

3.3 获取gpsd-traccar脚本

https://gist.github.com/linuxsocist/55e10998e88f61af9e6ec12c12bbb04e

3.4 运行测试

把IP修改为192.168.123.215为部署了traccar的电脑ip.

运行测试

sudo apt install jd
chmod +x gpsd-traccar.sh
./gpsd-traccar.sh

登录web,看到位置。

 

traccar带有报表功能,可以查看客户到过的轨迹、地区。

不过docker里面的数据库,如果未经过额外的设置,退出docker后,数据库数据会被清空。

4. 感想

这个服务是占用的端口比较多,昨晚1C2G的服务器也不够我部署用,实际部署占用了i5笔记本2.5G内存。这个应用比较惊艳,用了几个短视频APP都会获取用户的位置数据信息。真的后背有点凉。


参考:

如何在Raspberry Pi 4中使用GPS接收器模块,https://www.yiboard.com/thread-1381-1-1.html
Install Traccar on DigitalOcean VPS,https://www.traccar.org/install-digitalocean/
Traccar 记录你的足迹,https://zhuanlan.zhihu.com/p/98380567
[进阶教程] traccar从零开始到完美使用完全教程,https://bbs.hassbian.com/thread-7568-1-1.html
traccar从零开始到完美使用完全教程,https://bbs.iobroker.cn/t/topic/772

 

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码

)">
< <上一篇
下一篇>>