Exemplo n.º 1
0
def toggleWifiIcon():
    ''' toggle wifi icon based on if we have a valid ping from google or not and log that to file for other processes '''
    global isInternetConnected
    wifi = Wifi.Wifi()
    try:
        urllib2.urlopen('https://www.google.com', timeout=1)
        subprocess.call([leftDisplayCommand, "Wifi", "105", "10"])
        wifi.isConnected = 'yes'
        data.saveJSONObjToFile('wifi.data', wifi)
        isInternetConnected = True
    except urllib2.URLError as err:
        subprocess.call([leftDisplayCommand, "NoWifi", "105", "10"])
        wifi.isConnected = 'no'
        data.saveJSONObjToFile('wifi.data', wifi)
        isInternetConnected = False
Exemplo n.º 2
0
                # save JSON object of GPS info to file system
                gpsInfo = GPSInfo.GPSInfo()
                gpsInfo.latitude = float(gpsd.fix.latitude)
                gpsInfo.longitude = float(gpsd.fix.longitude)
                gpsInfo.track = float(gpsd.fix.track)

                # convert to imperial units
                gpsInfo.altitude = float(gpsd.fix.altitude * 3.2808)
                gpsInfo.climb = float(gpsd.fix.climb * 3.2808)

                # correct for bad speed value on the device
                #   also save to last location because it must be good with a valid speed present
                gpsInfo.speed = float(gpsd.fix.speed)
                if (gpsInfo.speed > 5):
                    gpsInfo.speed = gpsInfo.speed * 2.25
                    data.saveJSONObjToFile('last-location.data', gpsInfo)

                # create or rewrite data to GPS location data file as JSON
                data.saveJSONObjToFile('location.data', gpsInfo)

                # set clock from GPS
                if gpsd.utc != None and gpsd.utc != '':
                    gpsutc = gpsd.utc[0:4] + gpsd.utc[5:7] + gpsd.utc[
                        8:10] + ' ' + gpsd.utc[11:19]
                    os.system('sudo date -u --set="%s"' % gpsutc)
                time.sleep(1)

            except (Exception):
                pass
    except (KeyboardInterrupt, SystemExit):
        print "\nKilling Thread..."
Exemplo n.º 3
0
        while True:
            try:
                # save JSON object of GPS info to file system
                gpsInfo = GPSInfo.GPSInfo()
                gpsInfo.latitude = float(gpsd.fix.latitude)
                gpsInfo.longitude = float(gpsd.fix.longitude)
                gpsInfo.track = float(gpsd.fix.track)

                # convert to imperial units
                gpsInfo.altitude = float(gpsd.fix.altitude * 3.2808)
                gpsInfo.climb = float(gpsd.fix.climb * 3.2808)
                
                # correct for bad speed value on the device
                #   also save to last location because it must be good with a valid speed present
                gpsInfo.speed = float(gpsd.fix.speed)
                if (gpsInfo.speed > 5):
                    gpsInfo.speed = gpsInfo.speed * 2.25
                    data.saveJSONObjToFile('last-location.data', gpsInfo)
                
                # create or rewrite data to GPS location data file as JSON
                data.saveJSONObjToFile('location.data', gpsInfo)
                time.sleep(1)
            
            except (Exception):
                pass
    except (KeyboardInterrupt, SystemExit):
        print "\nKilling Thread..."
        gpsp.running = False
        gpsp.join()
        print "Done.\nExiting."
Exemplo n.º 4
0
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'])
        weatherDetails.precipProbability = float(currentConditions['precipProbability'])
        weatherDetails.windSpeed = float(currentConditions['windSpeed'])

        # create or rewrite data to weather data file as JSON, then wait 5 minutes
        data.saveJSONObjToFile('weather.data', weatherDetails)
        time.sleep(300)
        
    except (Exception):
        # GPS is not fixed or network issue, wait 30 seconds
        time.sleep(30)
Exemplo n.º 5
0
        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'])
        weatherDetails.apparentTemperature = float(
            currentConditions['apparentTemperature'])
        weatherDetails.humidity = float(currentConditions['humidity'])
        weatherDetails.precipIntensity = float(
            currentConditions['precipIntensity'])
        weatherDetails.precipProbability = float(
            currentConditions['precipProbability'])
        weatherDetails.windSpeed = float(currentConditions['windSpeed'])

        # create or rewrite data to weather data file as JSON, then wait 5 minutes
        data.saveJSONObjToFile('weather.data', weatherDetails)
        time.sleep(300)

    except (Exception):
        time.sleep(30)
Exemplo n.º 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)
Exemplo n.º 7
0
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 = [
            data.convertToInt(avgSpeeds[0] / 60 / 60 * drivingTimes[0]),
            data.convertToInt(avgSpeeds[1] / 60 / 60 * drivingTimes[1])
        ]

        # create or rewrite data to stats data file as JSON, then wait 1 minute
        data.saveJSONObjToFile('stats.data', drivingStatistics)
        time.sleep(60)

    except (Exception):

        # data issue, wait 5 seconds
        data.saveJSONObjToFile('stats.data', drivingStatistics)
        time.sleep(5)
Exemplo n.º 8
0
# Get complete current location details about known lat/long from Google Maps API
# Kevin Hinds http://www.kevinhinds.com
# License: GPL 2.0
import time, json, string, cgi, subprocess
import includes.data as data
import info.LocaleDetails as LocaleDetails

# get local locale info every 1 minutes to file to be further processed
while True:
    try: 
        currentLocationInfo = data.getLastKnownLatLong()
        localeURL = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + str(currentLocationInfo['latitude']) + ',' + str(currentLocationInfo['longitude'])
        localeInfo = json.loads(subprocess.check_output(['curl', localeURL]))

        # create serializeable class for use to save locale info to JSON file object
        localeDetails = LocaleDetails.LocaleDetails()
        localeDetails.address = str(localeInfo['results'][0]['formatted_address'])
        localeDetails.area = str(localeInfo['results'][1]['formatted_address'])
        localeDetails.city = str(localeInfo['results'][2]['formatted_address'])
        localeDetails.zipcode = str(localeInfo['results'][3]['formatted_address'])
        localeDetails.county = str(localeInfo['results'][4]['formatted_address'])
        localeDetails.country = str(localeInfo['results'][5]['formatted_address'])

        # create or rewrite data to locale data file as JSON
        data.saveJSONObjToFile('address.data', localeDetails)
        
    except (Exception):
        # GPS or network not available, wait 5 seconds
        time.sleep(5)
    time.sleep(60)
Exemplo n.º 9
0
#! /usr/bin/python
# Listen for button local presses
# Kevin Hinds http://www.kevinhinds.com / Dan Mandle http://dan.mandle.me
# License: GPL 2.0
import RPi.GPIO as GPIO
import time
import includes.data as data
import info.ButtonPressed as ButtonPressed

# setup button for BCM pin #25
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# listen for button press and save to file if it happened
while True:
    input_state_button1 = GPIO.input(24)
    if input_state_button1 == False:
        buttonPressed = ButtonPressed.ButtonPressed()
        buttonPressed.buttonName = 'button1'
        print buttonPressed
        data.saveJSONObjToFile('button.data', buttonPressed)
        time.sleep(0.2)
    input_state_button2 = GPIO.input(17)
    if input_state_button2 == False:
        buttonPressed = ButtonPressed.ButtonPressed()
        buttonPressed.buttonName = 'button2'        
        data.saveJSONObjToFile('button.data', buttonPressed)
        time.sleep(0.2)
Exemplo n.º 10
0
# Get complete current location details about known lat/long from Google Maps API
# Kevin Hinds http://www.kevinhinds.com
# License: GPL 2.0
import time, json, string, cgi, subprocess
import includes.data as data
import info.LocaleDetails as LocaleDetails

# get local locale info every 1 minutes to file to be further processed
while True:
    try: 
        currentLocationInfo = data.getLastKnownLatLong()
        localeURL = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + str(currentLocationInfo['latitude']) + ',' + str(currentLocationInfo['longitude'])
        localeInfo = json.loads(subprocess.check_output(['curl', localeURL]))

        # create serializeable class for use to save locale info to JSON file object
        localeDetails = LocaleDetails.LocaleDetails()
        localeDetails.address = str(localeInfo['results'][0]['formatted_address'])
        localeDetails.area = str(localeInfo['results'][1]['formatted_address'])
        localeDetails.city = str(localeInfo['results'][2]['formatted_address'])
        localeDetails.zipcode = str(localeInfo['results'][3]['formatted_address'])
        localeDetails.county = str(localeInfo['results'][4]['formatted_address'])
        localeDetails.country = str(localeInfo['results'][5]['formatted_address'])

        # create or rewrite data to locale data file as JSON
        data.saveJSONObjToFile('locale.data', localeDetails)
        
    except (Exception):
        # GPS or network not available, wait 5 seconds
        time.sleep(5)
    time.sleep(60)
Exemplo n.º 11
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)