Korrekt wäre:
if gps_g.lat>0 and gps_g.lon>0 and gps_g.utc!="": # GPS-Daten valide?
In den älteren Script-Versionen wird die Zeile auch existieren - lediglich die Zeilennummer wird kleiner 519 sein.
if -90<=gps_g.lat<=90 and -180<=gps_g.lon<=180 and gps_g.utc!="": # GPS-Daten valide?
Anlegen einer Datei /usr/local/bin/mountusb mit folgendem Inhalt:
ACTION=="add", SUBSYSTEMS=="usb", KERNEL=="sd*", RUN+="/bin/bash /usr/local/bin/mountusb mount /dev/%k"
ACTION=="remove", SUBSYSTEMS=="usb", KERNEL=="sd*", RUN+="/bin/bash /usr/local/bin/mountusb umount /dev/%k"
Ausführbar machen:
#!/bin/bash
# Verzeichnis fuer den USB-Stick definieren
MountPoint=/home/dede/usbstick
# Kommandozeilen-Parameter
ACTION=$1
DEVICE=$2
if [ "$ACTION" = "mount" ]; then
# falls nicht vorhanden -> Mountpoint anlegen
[ ! -d $MountPoint ] && mkdir -p $MountPoint
# USB-Stick einhaengen
/bin/mount $DEVICE $MountPoint
elif [ "$ACTION" = "umount" ]; then
# USB-Stick aushaengen
/bin/umount -f $DEVICE
fi
sudo chmod +x
/usr/local/bin/mountusb |
sudo chmod 777 /home/dede/usbstick |
sudo apt-get
install hostapd |
Dann in /etc/default/hostapd das conf-File eintragen:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.2.1
netmask 255.255.255.0
Und es anlegen als /etc/hostapd/hostapd.conf mit dem Inhalt:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Danach Installation des DHCP-Servers mit:
interface=wlan0
ssid=RaspAP
hw_mode=g
channel=6
beacon_int=100
auth_algs=3
wmm_enabled=1
sudo apt-get
install dnsmasq |
Damit klappt es (nach Reboot) bereits, sich per WLAN mit dem RasPi zu verbinden.
interface=wlan0
dhcp-range=192.168.2.20,192.168.2.50,255.255.255.0,12h
address=/#/192.168.2.1 #redirect all DNS requests to 192.168.2.1
dhcp-host=d0:5b:a8:e1:1f:d7, ZTEBlade, 192.168.2.10, 3h
Mit stopAP.sh wird der AccessPoint deaktiviert und damit automagisch die Fritzbox für die Namens-Auflösung eingestellt.
root@rp3:/home/dede# cat bin/startAP.sh
#!/bin/bash
sudo service hostapd start
sudo service dnsmasq start
cat /etc/resolv.conf
root@rp3:/home/dede# cat bin/stopAP.sh
#!/bin/bash
sudo service hostapd stop
sudo service dnsmasq stop
cat /etc/resolv.conf
sudo apt-get
install gpsd python-gps |
apt-get install gpsd-clients |
cgps -s |
Sechs genutzte Satelliten sind für diese Position schon ziemlich gut.
┌───────────────────────────────────────────┐┌─────────────────────────────────┐
│ Time: 2016-06-23T12:52:49.000Z ││PRN: Elev: Azim: SNR: Used: │
│ Latitude: 54.805109 N ││ 2 24 047 21 Y │
│ Longitude: 9.524913 E ││ 4 46 290 34 Y │
│ Altitude: 44.0 m ││ 5 12 087 00 Y │
│ Speed: 0.0 kph ││ 9 01 000 00 Y │
│ Heading: 54.6 deg (true) ││ 12 14 112 10 Y │
│ Climb: 0.0 m/min ││ 14 01 231 00 Y │
│ Status: 3D FIX (25 secs) ││ │
│ Longitude Err: +/- 13 m ││ │
│ Latitude Err: +/- 11 m ││ │
│ Altitude Err: +/- 75 m ││ │
│ Course Err: n/a ││ │
│ Speed Err: +/- 96 kph ││ │
│ Time offset: 0.204 ││ │
│ Grid Square: JO44st ││ │
└───────────────────────────────────────────┘└─────────────────────────────────┘
sudo apt-get
install lighttpd |
sudo bash lighty-enable-mod cgi mkdir /var/www/cgi-bin cd /etc/lighttpd/conf-enabled mv 10-cgi.conf 10-cgi.conf.bak nano 10-cgi.conf |
Danach noch:
# /usr/share/doc/lighttpd/cgi.txt
server.modules += ( "mod_cgi" )
alias.url += ( "/cgi-bin/" => "/var/www/cgi-bin/" )
$HTTP["url"] =~ "/cgi-bin/" {
cgi.assign = (
".pl" => "/usr/bin/perl",
".py" => "/usr/bin/python",
".py3" => "/usr/bin/python3",
".cgi" => "/bin/bash",
)
}
sudo chown -R
dede:www-data /var/www |
sudo apt-get
install python3 |
kann man (bei aktiviertem AccessPoint und damit verbundenem Smartphone) im Webbrowser die Adresse
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import cgi
import subprocess
import time
print("Content-type: text/html\n")
print('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">')
print('<title>RasPi GPS Tracker Status</title>')
print('<meta name="viewport" content="width=device-width, initial-scale=1" />')
print('<meta http-equiv="refresh" content="5">')
print('</head><body>')
print('<h1><center>RasPi GPS tracker</center></h1>')
print("<h3>Datum/Zeit: %s</h3>"%(time.strftime("%d.%m.%Y %H:%M:%S")))
process=subprocess.Popen(["uptime", "-p"], stdin =subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
rc=process.communicate()[0]
print("<h3>Uptime: %s</h3><p>"%(rc.decode(),))
process=subprocess.Popen(["df", "-hT"], stdin =subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
rc=process.communicate()[0]
if rc.decode().find("/home/dede/usbstick")>=0:
print("<h3>USB-Stick ist verfügbar!</h3>")
else:
print("<h2>USB-Stick ist <u>nicht</u> verfügbar!</h2>")
process=subprocess.Popen(["ps", "aux"], stdin =subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
rc=process.communicate()[0]
if rc.decode().find("/usr/sbin/gpsd")>=0:
print("<h3>GPS-Dienst läuft!</h3>")
else:
print("<h2>GPS-Dienst läuft <u>nicht</u>!</h2>")
print("<h3>Anzahl Satelliten: ??</h3>")
print("<h3>Alter GPS-Signal [Sek.]: %d</h3>"%(5, ))
print("<h3>Aufzeichnung seit [Min.]: %d</h3>"%(25, ))
print("<h3>Anzahl Track-Punkte: %d</h3>"%(205, ))
print('</body></html>')
Das mag jetzt für einen WebServer, der vom Internet aus erreichbar wäre, etwas unsicher sein...aber hier sehe ich da keine große Gefahr.
www-data ALL=(ALL) NOPASSWD: /sbin/init
usb 1-1.2: USB disconnect, device number 4
usb 1-1.2: new full-speed USB device number 5 using dwc_otg
usb 1-1.2: New USB device found, idVendor=1546, idProduct=01a6
usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1.2: Product: u-blox 6 - GPS Receiver
usb 1-1.2: Manufacturer: u-blox AG - www.u-blox.com
cdc_acm 1-1.2:1.0: ttyACM0: USB ACM device
usb 1-1.2: USB disconnect, device number 5
usb 1-1.2: new full-speed USB device number 6 using dwc_otg
usb 1-1.2: New USB device found, idVendor=1546, idProduct=01a6
usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1.2: Product: u-blox 6 - GPS Receiver
usb 1-1.2: Manufacturer: u-blox AG - www.u-blox.com
oder auch:
usb 1-1.2.4: USB disconnect, device number 7
rtw_cmd_thread: DriverStopped(0) SurpriseRemoved(1) break at line 482
usb 1-1.2.4: new high-speed USB device number 8 using dwc_otg
usb 1-1.2.4: New USB device found, idVendor=7392, idProduct=7811
usb 1-1.2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.2.4: Product: 802.11n WLAN Adapter
usb 1-1.2.4: Manufacturer: Realtek
usb 1-1.2.4: SerialNumber: 00e04c000001
sudo apt-get
install python-dateutil python3-dateutil |
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import subprocess
import gps
import datetime
from dateutil import tz
# ######################################################################
# Liefert für einen Timestamp im Format "2016-06-25T10:40:31.000Z"
# ein entsprechendes datetime-Objekt in Ortszeit.
def utcToLocal(timestamp):
utc=datetime.datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ')
utc=utc.replace(tzinfo=tz.tzutc())
return(utc.astimezone(tz.tzlocal()))
# ######################################################################
# Schreibt "strg" ins syslog.
def writeLog(strg):
subprocess.call(["logger", "GPS_set_time: %s"%(strg,)])
# ######################################################################
#
if __name__ == '__main__':
time.sleep(3)
writeLog("warte auf GPS")
mygps=gps.gps(mode=gps.WATCH_ENABLE)
writeLog("Init erfolgt")
time_set=False
wcnt=0
while not time_set:
try:
mygps.next()
if mygps.utc is not None and len(mygps.utc)==24:
dtl=utcToLocal(mygps.utc)
subprocess.call(["sudo", "date", "-s", dtl.strftime("%Y-%m-%d %H:%M:%S")])
time_set=True
writeLog("Zeit gesetzt")
else:
wcnt+=1
if wcnt%10==0:
writeLog("%d mal gewartet"%(wcnt,))
except Exception, e:
writeLog("Ausnahme aufgetreten %s"%(str(e),))
pass
/usr/bin/python /home/dede/bin/GPS_set_time.py &
Anbei das aktuelle Tracker-Script und das Script für die Erzeugung der WebSeite.
@reboot /usr/bin/python /home/dede/GPS_tracker.py