This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from SebastianSchildt/feature/traccar-client
Feature/traccar client
- Loading branch information
Showing
12 changed files
with
1,351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.tar | ||
*.bz2 | ||
build.sh | ||
Dockerfile | ||
*.md | ||
*.pyc | ||
*.sh | ||
*.build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM arm64v8/python:3.6-alpine AS build-env | ||
|
||
COPY qemu-aarch64-static /usr/bin/qemu-aarch64-static | ||
|
||
|
||
ADD . /app | ||
WORKDIR /app | ||
COPY requirements.txt ./ | ||
RUN pip install --target=./ --no-cache-dir -r requirements.txt | ||
RUN ls /usr/local/lib | ||
RUN rm ./requirements.txt | ||
RUN rm /usr/bin/qemu-aarch64-static | ||
WORKDIR /app | ||
#CMD python -u traccar-client.py | ||
#CMD ["traccar-client.py"] | ||
|
||
|
||
FROM arm64v8/python:3.6-alpine | ||
COPY --from=build-env /app /app | ||
ENV PYTHONPATH=/usr/local/lib/python3.5/site-packages | ||
ENV PYTHONUNBUFFERED=yes | ||
WORKDIR /app | ||
CMD python -u traccar-client.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Traccar client | ||
|
||
Simple KUKSA app that can send location data to the Traccar GPS tracking suite (https://www.traccar.org). | ||
|
||
Does not use any KUKSA cloud service, instead it demonstrates how the platform can interact with existing cloud services | ||
|
||
## Requirements | ||
The client can access GPSD. For this it uses the gps3 library: https://pypi.org/project/gps3 or https://github.com/wadda/gps3 | ||
It uses python requests for talking to Traccar | ||
|
||
Install it with | ||
|
||
`sudo pip3 install -r ./requirements.txt` | ||
|
||
|
||
## Configuration file | ||
The client triess to read traccar-client.ini in the current working directory, if that file is not found it tries /etc/traccar-client.ini | ||
|
||
## Testing | ||
How to get "real" GPS data easily on a PC. | ||
|
||
Install gpsd on your Linux machine. If your distro starts it automatically stop it. In Ubuntu like this: | ||
|
||
`sudo systemctl stop gpsd` | ||
`sudo systemctl stop gpsd.socket` | ||
|
||
|
||
Then start gpsd in Debug mode | ||
|
||
`sudo gpsd -G -n -N -D4 udp://*:3333` | ||
|
||
|
||
Now GPSd awaits GPS data in NMEA format via UDP on port 3333. Many Android Apps can provide it, a totally free one is GPSDClient | ||
|
||
https://play.google.com/store/apps/details?id=io.github.tiagoshibata.gpsdclient&rdid=io.github.tiagoshibata.gpsdclient | ||
|
||
Start it, and let is stream to the ip of the computer you run GPSD on port 3333. | ||
|
||
_Caveat_: It will only work if your phone has a _real_ GPS fix. (Just becasue Google maps shows some location guestimated form WiFi/cell towers is not enough) | ||
|
||
## Test deplyoment | ||
The start.sh script is suitable to be used for kuksa-hawkbit prototype in kuksa.invehicle | ||
|
||
## Build install images | ||
Small helper to build app packages suitable to be deployed with the prototype kuksa-downloader, in this folder execute | ||
|
||
`./mktestpackage.sh` | ||
|
||
Build SIMPLE_ and DOCKER_images. to save time (or if you have no docker installed) set `BUILD_DOCKER` to 0 in the script | ||
|
||
### Kill and mark uninstalled | ||
`pkill -ef traccar-client.py` | ||
|
||
If pkill is not available use grep and xargs. | ||
|
||
`rm /tmp/gps_installed` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env bash | ||
|
||
VERSION=$(git log -1 --pretty=format:%h) | ||
if [ -z "$VERSION" ]; then | ||
echo "Failed to extract version string" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
EXPERIMENTAL=`docker version | grep Experimental | tail -n 1 | xargs` | ||
if [ "$EXPERIMENTAL" != "Experimental: true" ]; then | ||
echo "Please enable the docker engine's experimental features" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
function build { | ||
ARCH=$1 | ||
|
||
# generate Dockerfile.build | ||
case ${ARCH} in | ||
'amd64') | ||
sed -e "s/arm64v8/amd64/g" Dockerfile > Dockerfile.build | ||
sed -i -e "s/^.*qemu-aarch64-static.*$//g" Dockerfile.build | ||
;; | ||
'arm64') | ||
cp /usr/bin/qemu-aarch64-static ./ | ||
if [ "$?" != "0" ]; then | ||
echo "Please install the qemu-user-static package" 1>&2 | ||
exit 1 | ||
fi | ||
cp Dockerfile Dockerfile.build | ||
;; | ||
'armhf') | ||
cp /usr/bin/qemu-arm-static ./ | ||
if [ "$?" != "0" ]; then | ||
echo "Please install the qemu-user-static package" 1>&2 | ||
exit 1 | ||
fi | ||
sed -e "s/arm64v8/armhf/g" Dockerfile > Dockerfile.build | ||
sed -i -e "s/qemu-aarch64-static/qemu-arm-static/g" Dockerfile.build | ||
;; | ||
*) | ||
echo "Unsupported architecture: $ARCH" 1>&2 | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# build image | ||
docker build --platform linux/$ARCH -f ./Dockerfile.build -t ${ARCH}/kuksa-traccar:${VERSION} . | ||
|
||
# cleanup | ||
rm -f Dockerfile.build | ||
rm -f qemu-aarch64-static | ||
rm -f qemu-arm-static | ||
} | ||
|
||
ARCHS="$@" | ||
if [ -z "$ARCHS" ]; then | ||
ARCHS="amd64 arm64 armhf" | ||
fi | ||
|
||
for ARCH in $ARCHS; do | ||
build $ARCH | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (c) 2018 Eclipse KUKSA project | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0 | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
|
||
BUILD_SIMPLE=1 | ||
BUILD_DOCKER=1 | ||
|
||
|
||
SIMPLE_TARGET=/tmp/SIMPLE_traccar.tar.bz2 | ||
DOCKER_TARGET=/tmp/DOCKER_traccar.tar.bz2 | ||
|
||
|
||
function build_simple { | ||
echo "Making SIMPLE_ package for Hawkbit" | ||
tar cvjf "$SIMPLE_TARGET" . | ||
|
||
echo "Package saved to $SIMPLE_TARGET" | ||
ls -ahl "$SIMPLE_TARGET" | ||
} | ||
|
||
function build_docker { | ||
echo "Making DOCKER_ package for Hawkbit" | ||
sudo docker build -t trac_packaging . | ||
sudo docker save trac_packaging | bzip2 -9 > "$DOCKER_TARGET" | ||
echo "Package saved to $DOCKER_TARGET" | ||
ls -ahl "$DOCKER_TARGET" | ||
} | ||
|
||
|
||
if [ $BUILD_SIMPLE -eq 1 ] | ||
then | ||
echo "Making simple package" | ||
build_simple | ||
fi | ||
|
||
|
||
|
||
if [ $BUILD_DOCKER -eq 1 ] | ||
then | ||
echo "Making Docker export" | ||
build_docker | ||
fi | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/python3 | ||
|
||
# Copyright (c) 2018 Eclipse KUKSA project | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0 | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: Robert Bosch GmbH | ||
# | ||
# This provider gets data from gpsd (http://www.catb.org/gpsd/) | ||
|
||
from gps3 import gps3 | ||
import sys | ||
import threading | ||
lock=threading.Lock() | ||
|
||
|
||
position = { "valid":False, "lat":"0", "lon":"0", "alt":"0", "hdop":"0", "speed":"0" } | ||
|
||
def loop(gpsd_socket): | ||
global position,lock | ||
print("gpsd receive loop started") | ||
data_stream = gps3.DataStream() | ||
gpsd_socket.watch() | ||
for new_data in gpsd_socket: | ||
if new_data: | ||
data_stream.unpack(new_data) | ||
print("GPSD data....") | ||
|
||
lock.acquire() | ||
position['lat']=data_stream.TPV['lat'] | ||
position['lon']=data_stream.TPV['lon'] | ||
position['alt']=data_stream.TPV['alt'] | ||
position['speed']=data_stream.TPV['speed'] | ||
if "hdop" in data_stream.SKY: | ||
position['hdop']=data_stream.SKY['hdop'] | ||
|
||
#check if position valid | ||
if 'n/a' in position.values(): | ||
position['valid']=False | ||
else: | ||
position['valid']=True | ||
lock.release() | ||
|
||
|
||
def getPosition(): | ||
global position, lock | ||
lock.acquire() | ||
p=position | ||
lock.release() | ||
return p | ||
|
||
|
||
def connect(host,port): | ||
gpsd_socket = gps3.GPSDSocket() | ||
gpsd_socket.connect(host, port) #TODO: Find out when it fails | ||
|
||
# loop(gpsd_socket) | ||
t = threading.Thread(target=loop, args=(gpsd_socket,)) | ||
t.start() | ||
|
||
def initProvider(config): | ||
print("Init gpsd provider...") | ||
if "Provider.gpsd" not in config: | ||
print("Provider.gpsd section missing from configuration, exiting") | ||
sys.exit(-1) | ||
|
||
provider_config=config['Provider.gpsd'] | ||
gpsd_host=provider_config.get('host','127.0.0.1') | ||
gpsd_port=provider_config.get('port','2947') | ||
|
||
print("Trying to connect gpsd at "+str(gpsd_host)+" port "+str(gpsd_port)) | ||
connect(gpsd_host,gpsd_port) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/python3 | ||
|
||
# Copyright (c) 2018 Eclipse KUKSA project | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0 | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: Robert Bosch GmbH | ||
# | ||
# This provider gets data from a simple log file which contains lines | ||
# formatted | ||
# lat,lon | ||
# All other values will be reported as 0 | ||
|
||
|
||
import csv | ||
import time | ||
import threading | ||
|
||
|
||
position = { "valid":False, "lat":"0", "lon":"0", "alt":"0", "hdop":"0", "speed":"0" } | ||
|
||
simplelog_interval=1 | ||
lock=threading.Lock() | ||
|
||
def loop(csv_reader): | ||
global simplelog_interval,lock | ||
for line in csv_reader: | ||
time.sleep(simplelog_interval) | ||
if not len(line) == 2: | ||
print("Simplelog skipping invalid line "+str(line)) | ||
continue | ||
|
||
try: | ||
lat=float(line[0]) | ||
lon=float(line[1]) | ||
except ValueError: | ||
print("Simplelog skipping invalid line "+str(line)) | ||
continue | ||
|
||
lock.acquire() | ||
position["lat"]=float(line[0]) | ||
position["lon"]=float(line[1]) | ||
position["valid"]=True | ||
lock.release() | ||
|
||
print("Line is "+str(line)) | ||
|
||
print("Simplelog: FINISHED") | ||
|
||
def initProvider(config): | ||
global simplelog_interval | ||
print("Init simplelog provider...") | ||
if "Provider.simplelog" not in config: | ||
print("Provider.simplelog section missing from configuration, exiting") | ||
sys.exit(-1) | ||
|
||
provider_config=config['Provider.simplelog'] | ||
simplelog_file=provider_config.get('file','log.csv') | ||
simplelog_interval=provider_config.getint('interval',1) | ||
|
||
print("Trying to read simeplelog from "+str(simplelog_file)+" with a position every "+str(simplelog_interval)+" s") | ||
|
||
csv_f=open(simplelog_file) | ||
csv_reader=csv.reader(csv_f, delimiter=',') | ||
|
||
#loop(csv_reader) | ||
t = threading.Thread(target=loop, args=(csv_reader,)) | ||
t.start() | ||
|
||
|
||
|
||
def getPosition(): | ||
global position, lock | ||
lock.acquire() | ||
p=position | ||
lock.release() | ||
return p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests | ||
gps3 |
Oops, something went wrong.