Last active
October 19, 2015 19:51
-
-
Save sjg/60dd3f0135654840521e to your computer and use it in GitHub Desktop.
TripSensr Codebase
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
# TripSensor Install Info | |
# Getting BU353-S4 GPS Device Working on Raspberry Pi | |
# ************************************************************ | |
sudo apt-get -y install gpsd gpsd-clients python-gps | |
# Change file with settings | |
nano /etc/default/gpsd | |
# Default settings for gpsd. | |
# change the options. | |
START_DAEMON="true" | |
GPSD_OPTIONS="/dev/ttyACM0" | |
DEVICES="" | |
USBAUTO="true" | |
GPSD_SOCKET="/var/run/gpsd.sock" | |
sudo /etc/init.d/gpsd restart | |
# Run GPS Test or run file above | |
cgps -s | |
pythin pollgps.py | |
# Install GPIO | |
https://pypi.python.org/pypi/RPi.GPIO | |
http://abyz.co.uk/rpi/pigpio/download.html | |
# ********************************************************* | |
# DHT22 Install -- Maybe if the other script doesn't work?? | |
# Adafruit Library prone to errors apperently | |
# ********************************************************* | |
sudo apt-get -y install build-essential python-dev | |
sudo git clone https://github.com/adafruit/Adafruit_Python_DHT.git | |
cd Adafruit_Python_DHT | |
sudo python setup.py install | |
# CO2 Sensor - Get notSMB and install | |
mkdir /home/pi/notsmb && cd /home/pi/notsmb | |
wget http://www.byvac.com/downloads/sws/notsmb_1_0.zip && unzip notsmb_1_0.zip | |
sudo python setup.py install | |
sudo apt-get install i2c-tools | |
#Add i2c-bcm2708 to /etc/modules | |
i2cdetect -y 1 # Nothing should show up at the moment | |
# SPI Dev | |
git clone https://github.com/doceme/py-spidev.git | |
sudo python setup.py install | |
sudo easy_install rpi.gpio | |
# MQTT | |
pip install paho-mqtt | |
pip3 install paho-mqtt |
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
#! /usr/bin/python | |
import os | |
from gps import * | |
from time import * | |
import time | |
import threading | |
import urllib2 | |
import subprocess | |
from subprocess import call | |
print 'Setting System Time' | |
subprocess.call("sudo /home/pi/tripSensr/setTimeFromGPS.sh", shell=True) | |
gpsd = None | |
pingNet = None | |
os.system('clear') | |
def internetUp(): | |
try: | |
response=urllib2.urlopen('http://google.com', timeout=1) | |
#return True | |
return "Up" | |
except urllib2.URLError as err: pass | |
#return False | |
return "Down" | |
class pollGPSDevice(threading.Thread): | |
def __init__(self): | |
threading.Thread.__init__(self) | |
global gpsd | |
gpsd = gps(mode=WATCH_ENABLE) | |
self.current_value = None | |
self.running = True | |
def run(self): | |
global gpsd | |
while poll.running: | |
gpsd.next() | |
if __name__ == '__main__': | |
poll = pollGPSDevice() | |
try: | |
poll.start() | |
while True: | |
os.system('clear') | |
print 'TripSensr Reading' | |
print '----------------------------------------' | |
print 'Latitude ' , gpsd.fix.latitude | |
print 'Longitude ' , gpsd.fix.longitude | |
print 'Time UTC ' , gpsd.utc | |
print 'Altitude (m)' , gpsd.fix.altitude | |
#print 'eps ' , gpsd.fix.eps | |
#print 'epx ' , gpsd.fix.epx | |
#print 'epv ' , gpsd.fix.epv | |
#print 'ept ' , gpsd.fix.ept | |
print 'Speed (m/s) ' , gpsd.fix.speed | |
print 'Climb ' , gpsd.fix.climb | |
print 'Track ' , gpsd.fix.track | |
#print 'Mode ' , gpsd.fix.mode | |
print '*****************************' | |
print 'Humidity ' , 0 | |
print 'Temperature ' , 0 | |
print 'N02 ' , 0 | |
print 'C02 ' , 0 | |
print '*****************************' | |
print 'Last Photo: \t' | |
print 'Internet Status: \t', internetUp() | |
print 'Logging State: \t', "Not Logging" | |
#print 'sats ' , gpsd.satellites | |
time.sleep(5) | |
except (KeyboardInterrupt, SystemExit): | |
print "\nKilling Thread..." | |
poll.running = False | |
poll.join() | |
print "Done.\nExiting." |
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
date -s '01/01/2014 00:01' | |
sleep 1 | |
pkill ntpd | |
pkill gpsd | |
gpsd -b -n -D 2 /dev/ttyUSB0 | |
sleep 2 | |
GPSDATE=`gpspipe -w | head -10 | grep TPV | sed -r 's/.*"time":"([^"]*)".*/\1/' | head -1` | |
echo $GPSDATE | |
date -s "$GPSDATE" | |
/usr/sbin/ntpd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment