webnar01

Teltonika_Nextcloud

Nov 4th, 2020 (edited)
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.62 KB | None | 0 0
  1. #!/bin/sh
  2. # 20191009 - phonetracker.sh created by Martin Loewe
  3. # 20201013 - removed spaces from string after update (W3B)
  4. # 20201102 - added log file for offline (W3B)
  5. # 20201104 - send log file to nextcloud when connection resumes (W3B)
  6.  
  7.  
  8. # Put your nextcloud server url in here
  9. URL="https://nextcloud.bla.com"
  10.  
  11. # Put your Session ID in here
  12. SESSION="132456789abcdefghijkl"
  13.  
  14. # Put your device name in here
  15. NAME="deviceName"
  16.  
  17. # Log file name and location
  18. FILE="/root/offline.log"
  19.  
  20. # Put your update delay in here in seconds
  21. DELAY=5
  22.  
  23. while :
  24.   do
  25.     FIX=$(/usr/sbin/gpsctl -s) # get GPS fix status
  26.     if [ $FIX = "1" ] # check if GPS fix is ok
  27.         then
  28.                 LAT=$(/usr/sbin/gpsctl -i) # get latitude
  29.                 if [ "$LAT" != "$LATOLD" ] # check if new latitude is different from old latitude
  30.                 then
  31.                         LATOLD=$LAT # set old latitude to new one
  32.                         SPD=$(/usr/sbin/gpsctl -v) # get ground speed
  33.                         LON=$(/usr/sbin/gpsctl -x) # get longitude
  34.                         SAT=$(/usr/sbin/gpsctl -p) # get connected sattelites
  35.                         ALT=$(/usr/sbin/gpsctl -a) # get altitude
  36.                         ACC=$(/usr/sbin/gpsctl -u) # get accuracy
  37.                         TIMESTAMP=$(/usr/sbin/gpsctl -t) # get gps timestamp
  38.                         GPSResults="$URL/index.php/apps/phonetrack/log/gpslogger/$SESSION/$NAME?lat=$LAT&lon=$LON&sat=$SAT&alt=$ALT&acc=$ACC&speed=$SPD&timestamp=$TIMESTAMP"
  39.                         DataCheck=$(ifconfig | awk '/^qmimux0/ { iface = getline; sub("addr:", ""); print $2 }') #Check modem IP
  40.                         ip_full=$(echo $DataCheck | sed -n 's/^\(\(\([1-9][0-9]\?\|[1][0-9]\{0,2\}\|[2][0-4][0-9]\|[2][5][0-4]\)\.\)\{3\}\([1-9][0-9]\?\|[1][0-9]\{0,2\}\|[2][0-4][0-9]\|[2][5][0-4]\)\)$/\1/p') #Validate IP
  41.                         if [ $ip_full != "" ] #If Valid IP
  42.                         then
  43.                                 curl ${GPSResults// /} # Send data to nextcloud
  44.                                 if [ -f $FILE ] #If File exists
  45.                                 then
  46.                                         while IFS= read -r line
  47.                                         do
  48.                                                 curl $line
  49.                                         done <"$FILE"
  50.                                         rm $FILE #Remove file
  51.                                 fi
  52.                         else
  53.                                 echo ${GPSResults// /} >> $FILE  #log GPS data in file
  54.                         fi
  55.                 fi
  56.     fi
  57.   sleep $DELAY
  58.  done
  59.  
Add Comment
Please, Sign In to add comment