Пример #1
0
    def startCollectTemp(self):
        loc = '95132,us'
        w = openweather.OpenWeather(loc)
        local_temp = w.getCurrentTemp()
        logging.info("{} get temperature {}".format(loc, local_temp))
        # r = Temperature(loc, datetime.datetime.now(), local_temp)
        r = temperature.Temperature('95132,us', datetime.datetime.now(),
                                    local_temp)
        r.save()

        credentials = {
            'project_id':
            '88fd3306-59ed-44f4-9134-06d1dd43878c',
            'client_id':
            '740269163638-jpthukkg54pab72dadun2q912f18d2d8.apps.googleusercontent.com',
            'client_secret':
            '2_I685cVfbMVhJX25fcWNGJE',
            'refresh_token':
            '1//0eQkelEO8pRZsCgYIARAAGA4SNwF-L9IrzNE76R-t3pn3eLy14UBY-85spny7h8GVEqf3E1idE7lF6sOMmWiTKNlYIt6F3sWK9zc'
        }
        n = nest.NestAgent(**credentials)
        if n.get_new_access_token():
            # use the new access token to get the devie list
            list = n.get_device_list()
            if list is not None:
                ambient = n.parse_Temp_from_dlist(list)
                r = temperature.Temperature('nest', datetime.datetime.now(),
                                            ambient)
                r.save()
Пример #2
0
def set_up_readings(temperature_data):
	temperature_range.append(temperature.Temperature
		(0,temperature_data["cold_max"], 0,0,255))

	temperature_range.append(temperature.Temperature
		(temperature_data["comfortable_min"],
		temperature_data["comfortable_max"], 0,255,0))

	temperature_range.append(temperature.Temperature
		(temperature_data["hot_min"],100, 255,0,0))

	measure_temperature(temperature_range)
Пример #3
0
def cli():
    #close GUI window to minimize user distraction
    main.destroy()

    #create new Temperature object & loop for more conversions
    cliTemp=temperature.Temperature()
    
    x=''
    while x.lower()!='gui':
        #use Class accessors to display converted results
        print('\tWhen °F = ',format(cliTemp.gettemperature(),'.2f'),'...'
              ' °C = ',format(cliTemp.tocelcius(),'.2f'),' and °K = ',
              format(cliTemp.tokelvin(),'.2f'),sep='')

        #prompt user
        if x=='': print('\n["exit" quits; "gui" restarts GUI]'
                        '\nEnter a temperature to convert:')
        x=input('\n°Fahrenheit==> ')
        
        #quit program
        if x.lower()=='exit': exit()
        
        #use mutator to set internal Class temp
        cliTemp.settemperature(x)
        
    #re-launch GUI
    del cliTemp
    assignment_13()
Пример #4
0
def assignment_13():
    #declare relevant globals
    global main,converter,entry,celcius,kelvin

    #create instance of Tepmerature object
    converter=temperature.Temperature()

    #create GUI
    main=t.Tk()
    main.title('Wurster')
    main.geometry('210x115')

    #build entry box
    mainentry=t.Frame(main)

    entrylbl=t.Label(mainentry,text='° Fahrenheit')
    entrylbl.pack(side='right')
    
    entry=t.Entry(mainentry,width=6)
    #use Class accessor to display "__ftemp"
    entry.insert(0,converter.gettemperature())
    entry.pack(side='right')

    #build celcius display area
    maincel=t.Frame(main)

    celcius=t.StringVar()
    celcius.set('= '+format(converter.tocelcius(),'.2f'))
    cel=t.Label(maincel,textvariable=celcius)
    cel.pack(side='left')
    
    clbl=t.Label(maincel,text='° Celcius')
    clbl.pack(side='left')

    #build kelvin display area
    mainkvn=t.Frame(main)

    kelvin=t.StringVar()
    kelvin.set('= '+format(converter.tokelvin(),'.2f'))
    kvn=t.Label(mainkvn,textvariable=kelvin)
    kvn.pack(side='left')
    
    klbl=t.Label(mainkvn,text='° Kelvin.')
    klbl.pack(side='left')

    #set triggers
    action=t.Button(main,text='Convert',command=convert)
    console=t.Button(main,text='switch to CLI',command=cli)
    quitter=t.Button(main,text='Quit',command=exit)
    main.bind('<Return>',enterkey)

    #pack & play
    mainentry.pack()
    maincel.pack()
    mainkvn.pack()
    action.pack()
    console.pack(side='right')
    quitter.pack(side='right')
    t.mainloop()
Пример #5
0
    def _initialize(self):
        # Create state directory.
        if not os.path.exists(K.STATE_DIR):
            os.mkdir(K.STATE_DIR)
        # Create upload thread (started in run() below).
        self._uploader = uploader.Uploader(self._main_cq,
                                           self._uploader_termination_event)
        # Create data sources.
        GPIO.setmode(GPIO.BCM)  # required before Wind()
        self._uploader.add_data_source(temperature.Temperature(), True)
        self._uploader.add_data_source(metadata.Metadata(), False)

        # Import modules only when enabled, since some again import optional libraries (e.g. DHT).
        # In demo mode, enable all and import demo instances.
        if True:  # TODO: Make wind optional.
            if C.DEMO_MODE_ENABLED():
                import demo.demo_wind as wind  # @UnusedImport
            else:
                import wind  # @Reimport
            self._uploader.add_data_source(wind.Wind(), True)
        if C.DHT_ENABLED() or C.DEMO_MODE_ENABLED():
            if C.DEMO_MODE_ENABLED():
                import demo.demo_dht as dht  # @UnusedImport
            else:
                import dht  # @Reimport
            self._uploader.add_data_source(dht.Dht(), True)
        if C.ADC_ENABLED() or C.DEMO_MODE_ENABLED():
            if C.DEMO_MODE_ENABLED():
                import demo.demo_spi_adc as spi_adc  # @UnusedImport
            else:
                import spi_adc  # @Reimport
            self._uploader.add_data_source(spi_adc.SpiAdc(), True)
        if C.HUAWEI_ENABLED() or C.DEMO_MODE_ENABLED():
            if C.DEMO_MODE_ENABLED():
                import demo.demo_huawei_status as huawei_status  # @UnusedImport
            else:
                import huawei_status  # @Reimport
            self._uploader.add_data_source(huawei_status.HuaweiStatus(), True)
        if C.DOOR_ENABLED() or C.DEMO_MODE_ENABLED():
            if C.DEMO_MODE_ENABLED():
                import demo.demo_door as door  # @UnusedImport
            else:
                import door  # @Reimport
            self._uploader.add_data_source(door.Door(), True)
        if C.PILOTS_ENABLED() or C.DEMO_MODE_ENABLED():
            if C.DEMO_MODE_ENABLED():
                import demo.demo_pilot_count as pilot_count  # @UnusedImport
            else:
                import pilot_count  # @Reimport
            self._uploader.add_data_source(pilot_count.PilotCount(), True)
Пример #6
0
def main():
    machine.freq(160000000)
    count = _SCREEN_REFRESH
    # try:
    conf_class = config.Config()
    conf_data = conf_class.load_config()
    # counter_class = counter.Counter(9, 10, conf_data)
    screen_class = screen.Screen(conf_data)
    temperature_class = temperature.Temperature(4, 5, conf_data, screen_class)
    screen_class.write_display()
    screen_class.write_data()
    while True:
        temperature_class.temperature()
        conf_data['p']['l'] = temperature_class.temp_level()
        time.sleep_ms(1000)
        count -= 1
        if count <= 0:
            screen_class.write_data()
            count = _SCREEN_REFRESH
Пример #7
0
def main():

    # set up logging
    logging.config.fileConfig('logging.conf')
    log = logging.getLogger("Main")
    log.info("###### NEW INSTANCE #####")
    log.log(51, "Current level is: {0}".format(logging.getLevelName(log.getEffectiveLevel())))

    # start the main class
    t = temperature.Temperature()
    t.start()

    # attach observers
    # t.attach(console.Console())
    t.attach(sql_writer.SQLWriter())
    t.attach(display.SegPlugin())
    # t.attach(notify.TempNotify())

    # start object catching SIGTERM
    killer = GracefulKiller(t)
    while killer.getRun():
        time.sleep(1)
    log.info("left main method")
Пример #8
0
#/usr/bin/python2.7

import dot3k.joystick as j
import time
import sys
import os
import signal
import screen, backlight, ledbar, temperature, joystick

MESSAGE = screen.Screen()
TEMP = temperature.Temperature()
LED = ledbar.LedBar()
SCROLLER = joystick.Scroller()
LIGHT = backlight.Backlight()


def main():
    if SCROLLER.scrollnum >= len(TEMP.temperatures):
        SCROLLER.reset()
    if SCROLLER.scrollnum < 0:
        SCROLLER.scrollnum = len(TEMP.temperatures) - 1
    MESSAGE.writeTemp(TEMP.temperatures[SCROLLER.scrollnum])
    LIGHT.color(float(TEMP.temperatures[SCROLLER.scrollnum]))
    LED.set_size(float(TEMP.temperatures[SCROLLER.scrollnum]))
    return


@j.on(j.UP)
def handle_up(pin):
    MESSAGE.clearScreen()
    TEMP.readTemp()
Пример #9
0
pin16 = pins.Pins(5)
pin19 = pins.Pins(22)
pin20 = pins.Pins(21)

import display
Image = display.Image
display = display.Display()

import button
button_a = button.Button(35)
button_b = button.Button(27)

import temperature
__adc = machine.ADC(machine.Pin(34, machine.Pin.IN))
__adc.atten(machine.ADC.ATTN_11DB)
temperature = temperature.Temperature(__adc).temperature

try:
    from mpu9250 import MPU9250
    from mpu6500 import MPU6500
    __i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=200000)
    __dev = __i2c.scan()
    # print("dev ", __dev)
    if 104 in __dev:
        print("1.4 version")
        __sensor = MPU9250(__i2c, MPU6500(__i2c, 0x68))
    if 105 in __dev:
        print("1.2 version No compass")
        __sensor = MPU9250(__i2c, MPU6500(__i2c, 0x69))
    import accelerometer
    accelerometer = accelerometer.Direction(__sensor)
Пример #10
0
## Main class for Temperature program
## Author: Robert Lowman
## Date: 12/5/16
import temperature

create = temperature.Temperature(0, 'C')
print "Enter Information about starting Temperature"
start = create.createTemperature()
print "Enter Information about ending Temperature"
end = create.createTemperature()
print "Enter Information about Incrementing Temperature"
inc = create.createTemperature()

inc = inc.getFahrenheit()

if start is None or end is None or inc is None:
    print "Invalid value given"
else :
    while start.lessThan(end):
        start = start.getFahrenheit()
        start.printTemperature()
        print "\t",
        start.getCelsius().printTemperature()
        print "\t",
        start.getKelvin().printTemperature()
        print "\n"
        start = start.raiseTemperature(inc.degrees)
#!/usr/bin/python
import temperature

temperature = temperature.Temperature()

listOfTemperatures = temperature.getListOfTemperatures(20, 5)
temperature.printToCsvFile(listOfTemperatures, 'output_for_local_file.csv')
Пример #12
0
          mosi=Pin(23),
          miso=Pin(19))
spi.init()
cs = Pin(5, Pin.OUT)
dc = Pin(15, Pin.OUT)
rst = Pin(4, Pin.OUT)
bl = Pin(32, Pin.OUT, value=0)
lcd = pcd8544.PCD8544(spi, cs, dc, rst)
lcd.reset()
lcd.init()
lcd.clear()

# Font setup

font = font5x8.Font5x8(lcd, space=1)
tempFont = temperature.Temperature(lcd)
pictoBig = picto_big.picto_big(lcd)
pictoSmall = picto_small.picto_small(lcd)

# Weather id categories

categories_ids = [
    [800],  #very_sunny_ids
    [801],  #sunny_ids 
    [802],  #cloudy_ids 
    [803, 804],  #very_cloudy_ids 
    [300, 310, 500, 520],  #light_rain_ids 
    [301, 311, 501],  #rain_ids 
    [302, 312, 313, 314, 321],  #heavy_rain_ids 
    [200, 201, 202, 210, 211, 212, 221, 230, 231, 232],  #thunder_ids 
    [600, 601, 602, 611, 612, 615, 616, 620, 621, 622]  #snow_ids 
Пример #13
0
def lambda_handler(event, context):
    """Sample pure Lambda function

    Parameters
    ----------
    event: dict, required
        API Gateway Lambda Proxy Input Format

        Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format

    context: object, required
        Lambda Context runtime methods and attributes

        Context doc: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html

    Returns
    ------
    API Gateway Lambda Proxy Output Format: dict

        Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
    """

    # try:
    #     ip = requests.get("http://checkip.amazonaws.com/")
    # except requests.RequestException as e:
    #     # Send some context about this error to Lambda Logs
    #     print(e)

    #     raise e

    print("Debug: Inside: aws-sam-s3-trigger-process-a-HelloWorldFunction-1O4Z4AUA0OV0S")
    print("Debug: We are about to update the JSON object - below are the pre-view")
    print("Debug: Event (json): ", event)

    print("Chris Macgowan")



    print("We are testing the Temperature class implementation")
    print("Create the Temperature object")

    temp_obj = temperatureModule.Temperature(23)
    print("Debug: tempObj.temp: ", temp_obj.temp)
    print("Debug: get_temperature_by_state_id(41): ", temp_obj.get_temperature_by_state_id(41))
    print("Debug: get_temperature_by_state_id(44): ", temp_obj.get_temperature_by_state_id(44))
    print("Debug: get_temperature_by_state_id(49): ", temp_obj.get_temperature_by_state_id(49))
    print("Debug: get_temperature_by_state_id(99): ", temp_obj.get_temperature_by_state_id(99))

    # get the temp based on the state ID
    print("Debug: Update the JSON object - setting temperature using temp_obj")
    print("Debug: Pre conditions")
    print("Debug: StateId: ", event['WeatherBase']['StateId'])
    print("Debug: Temperature: ", event['WeatherBase']['Temperature'])
    print("Debug: Get the temperature based on StateId")
    temperature_for_state = temp_obj.get_temperature_by_state_id(int(event['WeatherBase']['StateId']))
    print("Debug: temperature_for_state: ", temperature_for_state)

    print("Debug: Set temperature back to the JSON object")
    event['WeatherBase']['Temperature'] = temperature_for_state
    print("Debug: Temperature: ", event['WeatherBase']['Temperature'])

    # Just a test
    event['WeatherBase']['VariableA'] = "Updated by: aws-sam-s3-trigger-process-a-HelloWorldFunction-1O4Z4AUA0OV0S"


    # This is the business

    # The event will contain the code.
    # we will pass the code the Temerature Class (The busiess)
    # This will make the business easter to test

    print("Debug: Inside: aws-sam-s3-trigger-process-a-HelloWorldFunction-1O4Z4AUA0OV0S")
    print("Debug: We are about the print the Event")
    print("Debug: Event (json): ", event)

    return {
        "statusCode": 200,
        "body": json.dumps({"message": "Hello from Lambda - s3-trigger-process-a"}),
        "data": json.dumps(event)
    }
Пример #14
0
"""importation des codes pour les differents capteurs""""
import sys
import os
sys.path.append(os.getcwd())
import temperature
import bus
import lumiere
"""declaration des pins pour la temperature"""
t = temperature.Temperature(pin_int="17",
                pin_ext="18",
                pin_rad="2")
b = bus.Bus()
"""declaration des pins pour la lumiere"""
l = lumiere.Lumiere(pin_mouv="7",
            pin_rel="3",
            niveau=1000)
t.start()
b.start()
l.start()

t.join()
b.join()
l.join()