示例#1
0
# Get GPS readings and save to file
# Kevin Hinds http://www.kevinhinds.com / Dan Mandle http://dan.mandle.me
# License: GPL 2.0
import os, time, threading, pprint, json, math
import includes.postgres as postgres
from gps import *
import includes.data as data
import info.GPSInfo as GPSInfo
pp = pprint.PrettyPrinter(indent=4)

# setting the global variable
gpsd = None 

# start a new trip by inserting the new trip DB entry
postgres.startNewTrip()
data.removeJSONFile('location.data')

class GpsPoller(threading.Thread):
  '''create a threaded class for polling on the GPS sensor '''
  
  def __init__(self):
    threading.Thread.__init__(self)
    global gpsd
    
    # starting the stream of info
    gpsd = gps(mode=WATCH_ENABLE)
    self.current_value = None
    self.running = True

  def run(self):
    '''this will continue to loop and grab EACH set of gpsd info to clear the buffer'''
示例#2
0
# Kevin Hinds http://www.kevinhinds.com / Dan Mandle http://dan.mandle.me
# License: GPL 2.0
import os, time, threading, pprint, json, math, sys
import includes.postgres as postgres
from gps import *
import includes.data as data
import info.GPSInfo as GPSInfo

pp = pprint.PrettyPrinter(indent=4)

# setting the global variable
gpsd = None

# start a new trip by inserting the new trip DB entry
postgres.startNewTrip()
data.removeJSONFile('location.data')


class GpsPoller(threading.Thread):
    '''create a threaded class for polling on the GPS sensor '''
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd

        # starting the stream of info
        gpsd = gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True

    def run(self):
        '''this will continue to loop and grab EACH set of gpsd info to clear the buffer'''
示例#3
0
#!/usr/bin/python
# Get current forecast from forecast.io using lat/long
# Kevin Hinds http://www.kevinhinds.com
# License: GPL 2.0
import time, json, string, cgi, subprocess
import includes.data as data
import includes.settings as settings
import info.WeatherDetails as WeatherDetails
import includes.settings as settings

# remove old file and start logging weather
data.removeJSONFile('weather.data')
while True:
    try:

        # get current forecast from location
        weatherInfo = json.loads(
            subprocess.check_output([
                'curl', 'https://api.forecast.io/forecast/' +
                settings.weatherAPIKey + '/' + str(settings.latitude) + ',' +
                str(settings.longitude) + '?lang=en'
            ]))
        hourlyConditions = weatherInfo['minutely']
        currentConditions = weatherInfo['currently']

        # gather info in serializable object to store as JSON file
        weatherDetails = WeatherDetails.WeatherDetails()
        weatherDetails.time = int(currentConditions['time'])
        weatherDetails.summary = str(currentConditions['summary'])
        weatherDetails.nextHour = str(hourlyConditions['summary'])
        weatherDetails.icon = str(currentConditions['icon'])
示例#4
0
#!/usr/bin/python
# Get current forecast from forecast.io using lat/long
# Kevin Hinds http://www.kevinhinds.com
# License: GPL 2.0
import time, json, string, cgi, subprocess
import includes.data as data
import includes.settings as settings
import info.WeatherDetails as WeatherDetails

# remove old file and start logging weather
data.removeJSONFile('weather.data')
while True:

    try:
        # get current location from GPS
        currentLocationInfo = data.getLastKnownLatLong()
        
        # get current forecast from location
        weatherInfo = json.loads(subprocess.check_output(['curl', 'https://api.forecast.io/forecast/' + settings.weatherAPIKey + '/' + str(currentLocationInfo['latitude']) + ',' + str(currentLocationInfo['longitude']) + '?lang=en']))
        hourlyConditions = weatherInfo['minutely']
        currentConditions = weatherInfo['currently']
        
        # gather info in serializable object to store as JSON file
        weatherDetails = WeatherDetails.WeatherDetails()
        weatherDetails.time = int(currentConditions['time'])
        weatherDetails.summary = str(currentConditions['summary'])
        weatherDetails.nextHour = str(hourlyConditions['summary'])
        weatherDetails.icon = str(currentConditions['icon'])
        weatherDetails.apparentTemperature = float(currentConditions['apparentTemperature'])
        weatherDetails.humidity = float(currentConditions['humidity'])
        weatherDetails.precipIntensity = float(currentConditions['precipIntensity'])
示例#5
0
# Run GPS Breakout board w/MTK3339 chipset
# Kevin Hinds http://www.kevinhinds.com / Dan Mandle http://dan.mandle.me
# License: GPL 2.0
import os, time, threading, pprint, json, math, sys
import includes.postgres as postgres
from gps import *
import includes.data as data
import info.GPSInfo as GPSInfo
pp = pprint.PrettyPrinter(indent=4)

# setting the global variable
gpsd = None

# start a new trip by inserting the new trip DB entry
postgres.startNewTrip()
data.removeJSONFile('gps.data')


class GpsPoller(threading.Thread):
    '''create a threaded class for polling on the GPS sensor '''
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd

        # starting the stream of info
        gpsd = gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True

    def run(self):
        '''this will continue to loop and grab EACH set of gpsd info to clear the buffer'''
示例#6
0
#!/usr/bin/python
# Get local temp from DHT11 humidistat 
# Kevin Hinds http://www.kevinhinds.com
# License: GPL 2.0
import Adafruit_DHT
import os, time, json
import includes.data as data
import info.CurrentReadings as CurrentReadings

# set to use DHT11 sensor
sensor = Adafruit_DHT.DHT11
pin = 16

# start logging temp
data.removeJSONFile('temp.data')
while True:
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    if humidity is not None and temperature is not None:
        # convert to imperial units, save to JSON file and wait one second
        temperature = 9.0/5.0 * temperature + 32
        currentReadings = CurrentReadings.CurrentReadings()
        currentReadings.temp = int(temperature)
        currentReadings.hmidty = int(humidity)
        data.saveJSONObjToFile('temp.data', currentReadings)
    time.sleep(1)
示例#7
0
#!/usr/bin/python
# Summarize driving statistics to file once per minute
# Kevin Hinds http://www.kevinhinds.com
# License: GPL 2.0
import os, time, json
import includes.data as data
import includes.postgres as postgres
import info.Statistics as Statistics

# get the beginning of the trip
thisTripStartID = postgres.getNewTripStartID()

# remove stats data and start calculating
data.removeJSONFile('stats.data')

while True:
    try:
        drivingStatistics = Statistics.Statistics()
        drivingTimes = postgres.getDrivingTimes(thisTripStartID)
        avgSpeeds = postgres.getAverageSpeeds(thisTripStartID)
        drivingStatistics.drivingTimes = map(data.convertHumanReadable,
                                             drivingTimes)
        drivingStatistics.inTrafficTimes = map(
            data.convertHumanReadable,
            postgres.getInTrafficTimes(thisTripStartID))
        drivingStatistics.averageSpeeds = map(
            data.convertToString, map(data.convertToInt, avgSpeeds))
        drivingStatistics.averageAltitude = map(
            data.convertToString,
            map(data.convertToInt, postgres.getAverageAlt(thisTripStartID)))
        drivingStatistics.milesTravelled = [
示例#8
0
from math import cos, sin, pi, radians
import cgi, json, re, socket, string, struct, subprocess, sys, time, urllib2
import includes.data as data
import info.CurrentReadings as CurrentReadings
import info.WeatherDetails as WeatherDetails
import info.GPSInfo as GPSInfo
import info.Wifi as Wifi
import info.Notification as Notification
import info.Statistics as Statistics

# setup the commands to drive the left and right screens
leftDisplayCommand = "/home/pi/TripComputer/computer/left-display"
rightDisplayCommand = "/home/pi/TripComputer/computer/right-display"

# start logging wifi status
data.removeJSONFile('wifi.data')


def setupRightScreen():
    ''' setup initial right hand screen '''
    subprocess.call([rightDisplayCommand, "clear"])
    subprocess.call([rightDisplayCommand, "setColor", "255"])
    subprocess.call([rightDisplayCommand, "setFont", "18"])
    subprocess.call([rightDisplayCommand, "Temp", "10", "10"])
    subprocess.call([rightDisplayCommand, "Driving", "10", "40"])
    subprocess.call([rightDisplayCommand, "Calendar", "10", "100"])
    subprocess.call([rightDisplayCommand, "Speed", "10", "70"])
    subprocess.call([rightDisplayCommand, "Traffic", "100", "70"])


def setupLeftScreen():
示例#9
0
#!/usr/bin/python
# Get local temp from DHT11 humidistat 
# Kevin Hinds http://www.kevinhinds.com
# License: GPL 2.0
import Adafruit_DHT
import os, time, json
import includes.data as data
import info.CurrentReadings as CurrentReadings
import includes.settings as settings

# set to use DHT11 sensor
sensor = Adafruit_DHT.DHT11
pin = 25

# start logging temp
data.removeJSONFile('temp.data')
while True:
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    if humidity is not None and temperature is not None:
        # convert to imperial units, save to JSON file and wait one second
        # @todo compensating for the temp right next to the pi (extra heat [*0.90])
        temperature = (9.0/5.0 * temperature + 32) * 0.90
        currentReadings = CurrentReadings.CurrentReadings()
        currentReadings.temp = int(temperature)
        currentReadings.hmidty = int(humidity)
        data.saveJSONObjToFile('temp.data', currentReadings)
    time.sleep(1)