Exemplo n.º 1
0
    def main(self):
        lcd.lcd_init()
        lcd.lcd_string("###SETTING UP###", LINE_1)
        lcd.lcd_string("###SETTING UP###", LINE_2)

        lcd.lcd_string(text, LINE_1)

        while(True):

            time.sleep(.05); # this is to give the pi a cool down

            temp_time = epoch - time.time()

            """ Calculating the number of days until the specified time """
            days = int(math.floor((epoch - time.time()) / 86400))
            temp_time -= days * 86400 # updating the temp time

            """ Calculating the number of hours until the specified time """
            hours = int(math.floor(temp_time / 3600))
            temp_time -= hours * 3600 # updating temp_time

            """ Calculating the number of minutes until the specified time """
            minutes = int(math.floor(temp_time / 60))
            seconds = int(temp_time - minutes * 60)

            lcd.lcd_string("  %02d:%02d:%02d:%02d" % (days,hours,minutes,seconds), LINE_2)
Exemplo n.º 2
0
def main():
    d = identify.Identify()
    lcd.lcd_init()

    if d == -1:
        lcd.lcd_print("No Face Found")
        time.sleep(1)
        return 1

    if d == -2:
        lcd.lcd_print("No Internet Connection")
        return 1

    name = d['name']
    gender = d['gender']
    age = findAge(d['age'])
    smile = isSmiling(d['smile'])
    glasses = d['glasses']
    confidence = d['confidence']
    emotion = findMaxEmotion(d['emotion'])

    lcd.lcd_string("Uploading Data...")
    
    with open("index.xml", 'r+') as f:
        line = f.readline()
        index = int(line)

    fb = firebase.FirebaseApplication(URL)
    imageName = str(index)+".jpg"

    result = fb.put('/',index,{'name':name, 'gender':gender ,'age':age, 'smile':smile, 'glasses':glasses, 'confidence':confidence, 'emotion':emotion})

    status = 1

    try:
        status = subprocess.check_call(["./storage.sh",imageName])
    except:
        pass
    
    while status!=0:
        try:
            status = subprocess.check_call(["./storage.sh",imageName])
        except:
            pass

    index += 1
    with open("index.xml", 'w+') as f:
        f.write(str(index))

    lcd.lcd_string(name)
    if smile == "Yes":
        smile = "Smiling"
    else:
        smile = "Not Smiling"
    printString = "Age Range:" + str(age) + " " + str(gender) + " " + str(smile) + " " + str(glasses) + " Emotion:" + str(emotion)
    lcd.lcd_print(printString,2)
    lcd.lcd_clear()
    return 0
Exemplo n.º 3
0
def init():
    print("Initialization")
    global baseValue
    #initialize lcd
    lcd.lcd_init()
    lcd.string("      Welcome", LINE_1)
    lcd.string(" Remove any object", LINE_2)
    lcd.string(" from the platform.", LINE_3)
    time.sleep(2)
    lcd.clear()
    lcd.string("    Calibrating", LINE_1)
    lcd.string("   Please wait...", LINE_2)
    baseValue = lc.base_value()
Exemplo n.º 4
0
 def __init__(self, periphery):
     self.lcd_lock = threading.Lock()
     self.display_number = 0
     self.line1 = "Chili-Bot"
     self.line2 = ""
     self.line3 = ""
     self.line4 = "by Tim Kraemer"
     self.periphery = periphery
     self.dhtObserver = DisplayController.DHTObserver(self)
     self.externalObserver = DisplayController.ExternalObserver(self)
     self.periphery.dht_changed.addObserver(self.dhtObserver)
     self.periphery.external_changed.addObserver(self.externalObserver)
     lcd.lcd_init()
Exemplo n.º 5
0
def subscribe_topic():
    # Initialise display
    lcd.lcd_init()
    lcd.lcd_string("IP " + IPAddr, lcd.LCD_LINE_1)
    lcd.lcd_string("Alarm UNKNOWN", lcd.LCD_LINE_2)
    lcd.lcd_string("Garage Door UNKNOWN", lcd.LCD_LINE_3)
    lcd.lcd_string("Unsure where you are", lcd.LCD_LINE_4)
    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = on_message
    client.username_pw_set(username=priv.username, password=priv.password)
    client.connect(priv.MQTT_HOST, 1883)
    client.loop_forever()
Exemplo n.º 6
0
def on_message(client, userdata, msg):
    if msg.payload.decode() == "Hello world!":
        print("H W")
    else:
        #print("Yes!")
        a = msg.payload.decode()
        print(a)
        lcd.lcd_init()
        lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
        lcd.lcd_string("SMART AGRICULTURE", 2)
        lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
        lcd.lcd_string(a, 2)
        if (a == "END"):
            client.disconnect()
Exemplo n.º 7
0
def delete_fav():
    global num_unauth
    # Example: curl -u pikachu:electric -X DELETE 'http://localhost:5000/favs/delete?Name=What&Poketype=Whatsapp3'
    print("delete called")
    name_del = request.args.get('Name', None)
    type_del = request.args.get('Poketype', None)
    if name_del == None:
        error_light()
        num_unauth = 0
        lcd.lcd_init()
        lcd.lcd_string("Bad Name passed",2)
        return jsonify({'Error': 'Name not passed for deletion'})
    elif type_del == None:
        error_light()
        num_unauth = 0
        lcd.lcd_init()
        lcd.lcd_string("Bad Type passed",2)
        return jsonify({'Error': 'Type not passed for deletion'})
    elif db.session.query(Favs_table).filter_by(Name = name_del, Poketype = type_del).first():
        processing_light()
        db.session.query(Favs_table).filter_by(Name = name_del, Poketype = type_del).delete()
        db.session.commit()
        success_light()
        lcd.lcd_init()
        lcd.lcd_string("Success!",2)
        num_unauth = 0
        return jsonify({'Entry': 'Deleted'})
    else:
        error_light()
        num_unauth = 0
        lcd.lcd_init()
        lcd.lcd_string("Can't find entry",2)
        return jsonify({'Entry': 'Not Found'})
Exemplo n.º 8
0
def unauthorized():
    global num_unauth
    print("global num_unauth eh =" + str(num_unauth))
    if num_unauth >= 2:
        error_light()
        lcd.lcd_init()
        lcd.lcd_string("Can't Access!",2)
        print("unauthorized light")
        num_unauth = 0
    else:
        num_unauth += 1
        lcd.lcd_init()
        lcd.lcd_string("Can't Access!",2)
    return make_response(jsonify({'Error': 'Unauthorized Access'}), 401)
Exemplo n.º 9
0
 def lcd_thread_job(data_pointer):
     # reads elements in data_pointer and proximity_pointer[0] and show them on the LCD
     try:
         lcd_init()
         while True:
             if data_pointer[0] is None:
                 continue
             proxi = data_pointer[0].get("proximity", None)
             coords = data_pointer[0].get('est_pos', None)
             line1 = "Proxi: {} cm".format(
                 proxi) if proxi is not None else "Proxi:OutOfRange"
             line2 = "x:{:.2f} y:{:.2f} m".format(coords['x'], coords['y'])
             lcd_disp(line1, line2)
             time.sleep(0.1)
     except BaseException as e:
         raise (e)
Exemplo n.º 10
0
def yaz(satır1, satır2, a=2):
    lcd.lcd_init()
    lcd.GPIO.output(lcd.LED_ON, True)
    time.sleep(1)
    lcd.GPIO.output(lcd.LED_ON, False)
    time.sleep(1)
    lcd.GPIO.output(lcd.LED_ON, True)
    time.sleep(1)
    # set cursor to line 1
    lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
    # display text centered on line 1
    lcd.lcd_string(satır1, a)
    # set cursor to line 2
    lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
    # display additional text on line 2
    lcd.lcd_string(satır2, a)
Exemplo n.º 11
0
def action5():
    if GPIO.input(act5):
        GPIO.output(act5, False)
        gsm.Sendmsg(number, "Toilet")
        os.system('mpg321 Toilet.mp3 &')
        lcd.lcd_init()
        lcd.stringlcd(0xC0, "Toilet")
        print("act5 false")
        ser1.flushInput()

    elif act5 != 1:
        GPIO.output(act5, True)
        gsm.Sendmsg(number, "Toilet")
        os.system('mpg321 Toilet.mp3 &')
        lcd.lcd_init()
        lcd.stringlcd(0xC0, "Toilet")
        print("act5 true")
        ser1.flushInput()
Exemplo n.º 12
0
def action6():
    if GPIO.input(act6):
        GPIO.output(act6, False)
        gsm.Sendmsg(number, "Medicine")
        print("act6 Medicine false")
        os.system('mpg321 Medicine.mp3 &')
        lcd.lcd_init()
        lcd.stringlcd(0xC0, "Medicine")
        ser1.flushInput()

    elif act6 != 1:
        GPIO.output(act6, True)
        gsm.Sendmsg(number, "Medicine")
        os.system('mpg321 Medicine.mp3 &')
        lcd.lcd_init()
        lcd.stringlcd(0xC0, "Medicine")
        print("act6 Medicine true")
        ser1.flushInput()
Exemplo n.º 13
0
def action2():
    if GPIO.input(act2):
        GPIO.output(act2, False)
        gsm.Sendmsg(number, "act2 Light OFF")
        os.system('mpg321 LightOFF.mp3 &')
        print("act2 Light false")
        lcd.lcd_init()
        lcd.stringlcd(0xC0, "LIGHT OFF")
        ser1.flushInput()

    elif act2 != 1:
        GPIO.output(act2, True)
        gsm.Sendmsg(number, "act2 Light ON")
        os.system('mpg321 LightON.mp3 &')
        lcd.lcd_init()
        lcd.stringlcd(0xC0, "LIGHT ON")
        print("act2 Light true")
        ser1.flushInput()
Exemplo n.º 14
0
def setupComponents():
    #initialize buzzer
    buzzer.setup()

    #intialize lcd
    lcd.lcd_init()
    time.sleep(1)
    lcd.message("WELCOME ", "SMART PARKING")

    #set person gate pin as output pin
    GPIO.setup(PERSON_GATE, GPIO.OUT)
    GPIO.output(PERSON_GATE, False)

    # Hook the SIGINT
    signal.signal(signal.SIGINT, end_read)

    # Welcome message
    print("Welcome to the MFRC522 data read example")
    print("Press Ctrl-C to stop.")
Exemplo n.º 15
0
def main():
    # Initialise GPIO pins
    print("Initialising GPIO")
    gpio_init()

    # Initialise display
    print("Initialising LCD")
    lcd_init()

    print("Getting covid data")
    #covid_data = covid_api.CovidData.from_worldometer_country()
    covid_data = covid_api.CovidData.from_api()
    last_update = time.time()

    while True:
        print("Printing data on LCD display")
        lcd_print(
            "US Cases:{:7}".format(covid_data.cases),
            "US Today:{:7}".format(covid_data.today),
        )

        time.sleep(4)

        lcd_print(
            "US Death:{:7}".format(covid_data.deaths),
            "US Recov:{:7}".format(covid_data.recovered),
        )

        new_time = time.time()
        if new_time - last_update > API_UPDATE_INTERVAL:
            print("Getting covid data")
            try:
                #covid_data = covid_api.CovidData.from_worldometer_country()
                covid_data = covid_api.CovidData.from_api()
            except Exception as e:
                print(
                    "Parsing worldometer failed, Caught exception: {}".format(
                        e))
                covid_data = covid_api.CovidData.na()

            last_update = new_time
        else:
            time.sleep(4)
Exemplo n.º 16
0
def action1():
    if GPIO.input(act1):
        GPIO.output(act1, False)
        gsm.Sendmsg(number, "act1  Fan OFF")
        os.system('mpg321 FanOFF.mp3 &')
        lcd.lcd_init()
        lcd.stringlcd(0xC0, "FAN OFF")
        print("act1 false")
        ser1.flushInput()
        DA()

    elif act1 != 1:
        GPIO.output(act1, True)
        gsm.Sendmsg(number, "act1 Fan ON")
        os.system('mpg321 FanON.mp3 &')
        lcd.lcd_init()
        lcd.stringlcd(0xC0, "FAN ON")
        print("act1 true")
        ser1.flushInput()
        DA()
Exemplo n.º 17
0
def get_table():
    # Example: curl -i 'http://localhost:5000/favs?Poketype=shadow'
    fav_arg = request.args.get('Poketype', None)
    favsArr = []
    if fav_arg == None:
        error_light()
        print("GET /favs error light 1")
        lcd.lcd_init()
        lcd.lcd_string("Invalid Type",2)
        return jsonify({'Error': 'Invalid Type Passed in favs GET'})
    elif fav_arg not in ['normal', 'fighting', 'poison', 'flying', 'ground', 'bug', 'ghost', 'steel', 'fire', 'rock', 'water', 'grass', 'electric', 'psychic', 'ice', 'dragon', 'dark', 'fairy', 'unknown', 'shadow']:
        error_light()
        print("GET /favs error light 2")
        lcd.lcd_init()
        lcd.lcd_string("Invalid Type",2)
        return jsonify({'Error': 'Invalid Type Passed in favs GET'})
    else:
        processing_light()
        favs = db.session.query(Favs_table).filter_by(Poketype = fav_arg)
        for fav in favs:
            favsArr.append(fav.toDict())
        success_light()
        lcd.lcd_init()
        lcd.lcd_string("Success!",2)
        print(jsonify(favsArr))
        return jsonify(favsArr)
Exemplo n.º 18
0
def get_poketype():
    # Example: curl -i 'http://localhost:5000/poketype?Poketype=shadow'
    poketype_arg = request.args.get('Poketype', None)
    pokeapi_entry = ""
    if poketype_arg == None:
        error_light()
        print("GET error light 1")
        lcd.lcd_init()
        lcd.lcd_string("Invalid Find",2)
        pokeapi_entry = jsonify({'Pokeapi_Type': 'Not Found'})
    elif poketype_arg not in ['normal', 'fighting', 'poison', 'flying', 'ground', 'bug', 'ghost', 'steel', 'fire', 'rock', 'water', 'grass', 'electric', 'psychic', 'ice', 'dragon', 'dark', 'fairy', 'unknown', 'shadow']:
        error_light()
        print("GET error light 2")
        lcd.lcd_init()
        lcd.lcd_string("Invalid Find",128)
        
        pokeapi_entry = jsonify({'Pokeapi_Type': 'Not Found'})
    else:
        processing_light()
        pokeapi_url = "https://pokeapi.co/api/v2/type/" + poketype_arg + "/"
        print(pokeapi_url)
        pokeapi_entry = jsonify(requests.get(pokeapi_url).json())
        lcd.lcd_init()
        lcd.lcd_string("Success!",2)
        success_light()
    return pokeapi_entry
Exemplo n.º 19
0
def add_fav():
    # Example: curl -u pikachu:electric -i -H "Content-Type: application/json" -X POST -d '{"Name":"What", "Poketype":"Whatsapp5"}' http://localhost:5000/favs
    global num_unauth
    if not request.json or not 'Name' in request.json or not 'Poketype' in request.json:
        error_light()
        print("POST error light 1")
        print("either Name or Poketype not in request light")
        lcd.lcd_init()
        lcd.lcd_string("Input Invalid",2)
        num_unauth = 0
        abort(400)
    entry = ""
    if db.session.query(Favs_table).filter_by(Name = request.json['Name'], Poketype = request.json['Poketype']).first():
        error_light()
        print("POST error light 2")
        print("entry already exists light")
        new_fav_json = {'Error': 'Entry Already Exists'}
        lcd.lcd_init()
        lcd.lcd_string("Entry Exists",2)
        entry = jsonify(new_fav_json)
        num_unauth = 0
    else:
        processing_light()
        new_fav_json = {
            'Name': request.json['Name'],
            'Poketype': request.json['Poketype']
        }
        new_fav = Favs_table(0, request.json['Name'], request.json['Poketype'])
        print(new_fav)
        db.session.add(new_fav)
        db.session.commit()
        entry = jsonify({'New Entry': new_fav_json})
        print("global num_unauth suc =" + str(num_unauth))
        success_light()
        lcd.lcd_init()
        lcd.lcd_string("Success!",2)
        num_unauth = 0
    return entry, 201
Exemplo n.º 20
0
def main():
    global stopper

    lcd.lcd_init()
    kb.keyboard_init()
    try:
        while True:

            num = ''
            lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
            lcd.lcd_string('Enter Stock Num:', 2)
            while True:
                print("get:")
                key = kb.get_key()
                time.sleep(0.3)
                if key == 'A':
                    print('A')
                elif key == 'B':
                    num = num[:len(num) - 1]
                    print('Back, Cur num : ' + num)
                    lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
                    lcd.lcd_string(num, 2)
                elif key == 'C':
                    num = ''
                    print('Clear, Cur num : ' + num)
                    lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
                    lcd.lcd_string(num, 2)
                elif key == 'D':
                    print('D')
                elif key == 'E' or key == 'F':
                    print('Searching : ' + num)
                    lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
                    lcd.lcd_string(num, 2)
                    lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
                    lcd.lcd_string('Searching...', 2)
                    break
                else:
                    num += key
                    print('Cur num : ' + num)
                    lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
                    lcd.lcd_string(num, 2)

            stock = twstock.realtime.get(num)

            if not stock['success']:
                lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
                lcd.lcd_string('Stock Not Found', 2)
                continue

            stock_his = twstock.Stock(num)
            print(stock)
            yes = stock_his.price[-2:][0]

            op = stock['realtime']['open']
            now = stock['realtime']["latest_trade_price"]
            high = stock['realtime']['high']
            low = stock['realtime']['low']

            a_s = float(now) - float(yes)

            output = now + '  '
            if a_s > 0:
                output += '+'

            output += "%.2f" % a_s

            lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
            lcd.lcd_string(num, 2)
            lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
            lcd.lcd_string(output, 2)

            while True:
                print("get:")
                key = kb.get_key()
                time.sleep(0.3)
                if key == 'E' or key == 'F':
                    stopper = 0
                    lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
                    lcd.lcd_string('', 2)
                    break
                elif key == 'A':
                    stopper = 0
                    lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
                    lcd.lcd_string(output, 2)
                elif key == 'B':
                    if stopper == 1:
                        stopper = 0
                        t.join()
                    stopper = 1
                    s = ' open: ' + op + ' high: ' + high + ' low: ' + low
                    t = threading.Thread(target=mov_print, args=[s])
                    t.start()
                elif key == 'C':
                    if stopper == 1:
                        stopper = 0
                        t.join()
                    stopper = 1
                    s = ' '.join(str(x)
                                 for x in stock_his.price[-5:]) + '     '
                    t = threading.Thread(target=mov_print, args=[s])
                    t.start()

    except KeyboardInterrupt:
        GPIO.cleanup()
Exemplo n.º 21
0
        Lprint.lcd_byte(0x01, LCD_CMD)
        Lprint.lcd_string("sorry....",
                          LCD_LINE_1)  #syntax for printing on lcd screen
        Lprint.lcd_string("try again",
                          LCD_LINE_2)  #syntax for printing on lcd screen
        time.sleep(2)

    f.stop_led()


def main():
    while (1):
        k = mode_select()  #selecting mode for :1)new user 2)payment
        if (k == '1'):  #for enrollment of new user finger print
            scan_finger()  #function used to store the finger print of the user
        if (k == '2'):  #mode selection for payment
            y = verify()  #store the id of the user in the variable
        if (k == '#'):
            '''
            send req. to server to update the database
            press #
            '''
            Lprint.lcd_byte(0x01, LCD_CMD)
            Lprint.lcd_string("database updated..",
                              LCD_LINE_1)  #syntax for printing on lcd screen
            time.sleep(2)


Lprint.lcd_init()
main()
Exemplo n.º 22
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import lcd as LCD
import time
LCD.main()
LCD.lcd_init()
time.sleep(1)
LCD.lcd_string("line 1",LCD.LCD_LINE_1)
LCD.lcd_string("line 2",LCD.LCD_LINE_2)
time.sleep(2)
LCD.lcd_string("Animation test",LCD.LCD_LINE_2)
LCD.lcd_string("               T",LCD.LCD_LINE_1)

LCD.lcd_string("              T ",LCD.LCD_LINE_1)

LCD.lcd_string("             T  ",LCD.LCD_LINE_1)

LCD.lcd_string("            T   ",LCD.LCD_LINE_1)

LCD.lcd_string("           T    ",LCD.LCD_LINE_1)

LCD.lcd_string("          T     ",LCD.LCD_LINE_1)

LCD.lcd_string("         T      ",LCD.LCD_LINE_1)

LCD.lcd_string("        T       ",LCD.LCD_LINE_1)

LCD.lcd_string("       T        ",LCD.LCD_LINE_1)

LCD.lcd_string("      T         ",LCD.LCD_LINE_1)
Exemplo n.º 23
0
def main():
    logger = get_logger()
    lcd_init()
    logger.info("LCD Initialized")

    try:
        status = stats.Stats(logger)
    except Exception as e:
        logger.exception("Leaving... could not create stats object")

    while True:
        try:
            # LINE 1
            if line_state[1]['current_state'] == 0:
                lcd_string("Mining Stats v1", LCD_LINE_1, 2)
            elif line_state[1]['current_state'] == 1:
                lcd_string(
                    "Started {}/{} {}:{} ".format(
                        init_start.day, init_start.month,
                        str(init_start.hour).zfill(2),
                        str(init_start.minute).zfill(2)), LCD_LINE_1, 2)
            elif line_state[1]['current_state'] == 2:
                time_diff = datetime.datetime.now() - init_start
                last_checked_hours = time_diff.seconds // 3600
                last_checked_minutes = (time_diff).seconds // 60 % 60
                lcd_string(
                    "Up {}d {}h{}m{}s".format(
                        time_diff.days,
                        str(last_checked_hours).zfill(2),
                        str(last_checked_minutes).zfill(2),
                        str(time_diff.seconds % 60).zfill(2)), LCD_LINE_1, 2)

            # LINE 2
            if 'chip_temp' in status.stats:
                if line_state[2]['current_state'] == 0:
                    lcd_string(
                        "Chip " + chr(223) + "{} {} {} {} ".format(
                            *status.stats['chip_temp'].values()), LCD_LINE_2,
                        2)
                elif line_state[2]['current_state'] == 1:
                    lcd_string(
                        "PCB " + chr(223) + "{} {} {} {} ".format(
                            *status.stats['pcb_temp'].values()), LCD_LINE_2, 2)
                elif line_state[2]['current_state'] == 2:
                    lcd_string(
                        "G5s {}|Gav {}".format(
                            round(float(status.stats['miner_speed']['GHS 5s']),
                                  1),
                            round(float(status.stats['miner_speed']['GHS av']),
                                  1)), LCD_LINE_2, 2)
            else:
                lcd_string("!! NO TEMPS AVAIL !!", LCD_LINE_2, 2)

            # LINE 3
            if line_state[3]['current_state'] == 0:
                ip_addr = status.stats['miner_ip']
                if ip_addr is None:
                    lcd_string("!! MINER NOT FOUND !!", LCD_LINE_3, 2)
                else:
                    time_diff = datetime.datetime.now(
                    ) - status.stats['miner_ip_last_checked']
                    last_checked_minutes = (time_diff).seconds // 60 % 60
                    lcd_string(
                        str(ip_addr) + " ({}:{})".format(
                            last_checked_minutes,
                            str(time_diff.seconds % 60).zfill(2)), LCD_LINE_3,
                        2)
            elif line_state[3]['current_state'] == 1:
                if status.stats['ambient_temp']:
                    time_diff = datetime.datetime.now(
                    ) - status.stats['ambient_last_checked']
                    lcd_string(
                        "{}".format(status.stats['ambient_temp']) + chr(223) +
                        "C | " +
                        "{}%".format(status.stats['ambient_humidity']) +
                        " ({}s)".format(time_diff.seconds), LCD_LINE_3, 2)
                else:
                    lcd_string("Ambient Temp Not avail", LCD_LINE_3, 2)

            # LINE 4
            btc_eur_rate = status.stats['btc_eur_rate']
            ltc_eur_rate = status.stats['ltc_eur_rate']
            engine = status.stats['engine']
            if engine in ["nicehash", "mininpoolhub"]:
                eur_rate = btc_eur_rate
                displayed_cryptocurrency = "BTC"
            elif engine == "litecoinpool":
                eur_rate = ltc_eur_rate
                displayed_cryptocurrency = "LTC"

            if line_state[4]['current_state'] == 0:
                if engine == "auto":
                    lcd_string("Balance N/A", LCD_LINE_4, 2)
                else:
                    balance_num = status.stats['balance']
                    if balance_num:
                        balance_num = round(balance_num, 7)
                    eur_balance = eur_rate * balance_num if (
                        eur_rate and balance_num) else 0
                    lcd_string(
                        "{}{} [{}E]".format(balance_num,
                                            displayed_cryptocurrency,
                                            round(eur_balance, 1)), LCD_LINE_4,
                        2)
            elif line_state[4]['current_state'] == 1:
                if engine == "auto":
                    lcd_string("Detecting pool...", LCD_LINE_4, 2)
                else:
                    lcd_string("{}".format(status.stats['engine']), LCD_LINE_4,
                               2)
            elif line_state[4]['current_state'] == 2:
                if engine == "auto":
                    lcd_string("Rate N/A", LCD_LINE_4, 2)
                else:
                    btc_day = status.stats['btc_day']
                    eur_day = btc_day * eur_rate if (btc_day
                                                     and eur_rate) else 0
                    lcd_string(
                        "{} {}/d[{}E]".format(btc_day,
                                              displayed_cryptocurrency,
                                              round(eur_day, 2)), LCD_LINE_4,
                        2)
            elif line_state[4]['current_state'] == 3:
                lcd_string("1BTC = {}eur".format(int(btc_eur_rate)),
                           LCD_LINE_4, 2)
            elif line_state[4]['current_state'] == 4:
                lcd_string("1LTC = {}eur".format(int(ltc_eur_rate)),
                           LCD_LINE_4, 2)

            update_line_states()
        except Exception as e:
            logger.exception("Leaving... Error while refreshing LCD")
            break
Exemplo n.º 24
0
import sys
sys.path.append('`/.python/lcd')
import lcd
lcd.lcd_init()
lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
lcd.lcd_string("Raspberry Pi", 2)
lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
lcd.lcd_string("Model B+", 2)
lcd.GPIO.cleanup()
Exemplo n.º 25
0
 def __init__(self):
     self.lcd_lock = threading.Lock()
     self.display_number = 0
     self.head_line = "Gefuehlsboard"
     self.bottom_line = "2.0"
     lcd.lcd_init()
Exemplo n.º 26
0
#!/usr/bin/env python
# -*- coding: utf8 -*-

import RPi.GPIO as GPIO
import MFRC522
import signal
import time
import software
import lcd

continue_reading = True
# GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)  #SETTING UP GPIO BOARD
GPIO.setup(29,GPIO.OUT)   #SETTING PIN 29 AS OUTPUT PIN TO RELAY 
GPIO.output(29,True)    #SETTING INITIAL VALUE AS TRUE AS RELAY IS TRIGGERED ON GROUND
lcd.lcd_init() #Intialising the LCD 
lock_delay=3
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
    global continue_reading
    continue_reading = False
    GPIO.cleanup()

# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)

# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()

# Welcome message
 
Exemplo n.º 27
0
    def handle_event(self, event, data):
        if event != EVENT_FLASH_LED and event != EVENT_DISPLAY_LINE:
            print(event, data)

        if event == EVENT_IDLE:
            self.validate_state()
            return

        if event == EVENT_DISPLAY_LINE:
            self.showing_line += 1
            if self.showing_line == 4:
                self.showing_line = 1

            Timer({
                1: TIMESECS_LINE_1,
                2: TIMESECS_LINE_2,
                3: TIMESECS_LINE_3
            }[self.showing_line], self.post_event,
                  (EVENT_DISPLAY_LINE, )).start()

        if event == EVENT_RESET_DISPLAY:
            lcd_init()
            self.current_text = None
            Timer(TIMESECS_RESET_DISPLAY, self.post_event,
                  (EVENT_RESET_DISPLAY, )).start()

        if event == EVENT_FLASH_LED:
            self.validate_state()
            self.flash_led_on = not self.flash_led_on
            Timer(TIMESECS_LED_FLASH, self.post_event,
                  (EVENT_FLASH_LED, )).start()

        if event == EVENT_BUTTON_DOWN:
            previous_press_counter = self.button_press_counter
            self.button_press_counter = (self.button_press_counter + 1) % len(
                self.button_presses)

            elapsed_secs_since_click = time.time() - data

            if self.button_presses[
                    previous_press_counter]:  # not yet decided previous press - this must be a double click
                self.button_presses[previous_press_counter] = None
                self.post_event(EVENT_DOUBLE_CLICK, self.button_press_counter)
            else:
                self.button_presses[self.button_press_counter] = [True]
                Timer(TIMESECS_DOUBLE_CLICK - elapsed_secs_since_click,
                      self.post_event, (EVENT_SINGLE_CLICK_TIMEOUT,
                                        self.button_press_counter)).start()
                Timer(TIMESECS_LONG_PRESS - elapsed_secs_since_click,
                      self.post_event, (EVENT_LONG_PRESS_TIMEOUT,
                                        self.button_press_counter)).start()
            return

        if event == EVENT_BUTTON_UP:
            elapsed_secs_since_click = time.time() - data

            # If the click operation is not yet decided and the click timeout has fired
            if self.button_presses[
                    self.button_press_counter] and not self.button_presses[
                        self.button_press_counter][0]:
                self.button_presses[self.button_press_counter] = None
                self.post_event(EVENT_CLICK)

        if event == EVENT_SINGLE_CLICK_TIMEOUT:
            if self.button_presses[data]:
                if not GPIO.input(GPIO_BUTTON):
                    self.button_presses[data] = None
                    self.post_event(EVENT_CLICK)
                else:
                    self.button_presses[data] = [
                        False
                    ]  # record the fact that the timeout has passed
            return

        if event == EVENT_LONG_PRESS_TIMEOUT:
            if self.button_presses[data]:
                self.button_presses[data] = None
                self.post_event(EVENT_LONG_PRESS)
            return

        if event == EVENT_SMALL_TANK_FLOAT_ON:
            self.small_tank_float = True
            self.transfer_pump = True
            return

        if event == EVENT_SMALL_TANK_FLOAT_OFF:
            self.small_tank_float = False
            Timer(TIMESECS_TRANSFER_PUMP, self.post_event,
                  (EVENT_TRANSFER_PUMP_OFF, )).start()
            return

        if event == EVENT_TRANSFER_PUMP_OFF and not self.small_tank_float:
            self.transfer_pump = False
            return

        if event == EVENT_LARGE_TANK_BOTTOM_FLOAT_ON:
            self.large_tank_bottom_float = True
            if self.want_to_mist:
                self.misting_pump = True
            return

        if event == EVENT_LARGE_TANK_BOTTOM_FLOAT_OFF:
            self.large_tank_bottom_float = False
            Timer(TIMESECS_MISTING_PUMP, self.post_event,
                  (EVENT_MISTING_PUMP_OFF, )).start()
            return

        if event == EVENT_LARGE_TANK_TOP_FLOAT_ON:
            self.large_tank_top_float = True
            self.venting = True
            self.misting_pump = True
            return

        if event == EVENT_LARGE_TANK_TOP_FLOAT_OFF:
            self.large_tank_top_float = False
            Timer(TIMESECS_VENTING_PUMP, self.post_event,
                  (EVENT_MISTING_PUMP_OFF, )).start()
            return

        if event == EVENT_MISTING_PUMP_OFF:
            self.venting = False
            if not self.large_tank_bottom_float:
                self.misting_pump = False
            else:
                self.misting_pump = self.want_to_mist
            return

        if event == EVENT_WANT_TO_MIST:
            if self.large_tank_bottom_float:
                self.misting_pump = True
            return

        if event == EVENT_DONT_WANT_TO_MIST:
            self.misting_pump = False
            return

        if event == EVENT_LONG_PRESS:
            if self.mode == MODE_ALWAYS_OFF:
                self.mode = MODE_VENTING
                self.popup_text('Mode: Venting')
            else:
                self.mode = MODE_ALWAYS_OFF
                self.popup_text('Mode: Disabled')

        if event == EVENT_CLICK:
            if self.mode == MODE_VENTING:
                self.mode = MODE_ALWAYS_ON
                self.popup_text('Mode: Cooling')
                Timer(TIMESECS_COOLING_TIME, self.post_event,
                      (EVENT_COOLING_STOP, self.cooling_count)).start()
            elif self.mode == MODE_ALWAYS_ON:
                self.post_event(EVENT_COOLING_STOP, self.cooling_count)
            return

        if event == EVENT_COOLING_STOP and self.mode == MODE_ALWAYS_ON and self.cooling_count == data:
            self.post_event(EVENT_MISTING_PUMP_OFF)
            self.mode = MODE_VENTING
            self.cooling_count += 1
            self.popup_text('Mode: Venting')
            return

        if event == EVENT_REVERT_TEXT and self.show_text == data:
            self.show_text = None
            self.showing_line = 1
            return
Exemplo n.º 28
0
import sys
sys.path.append('/home/pi/fire')
import lcd
lcd.lcd_init()
lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
lcd.lcd_string("Raspberry Pi", 2)
lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
lcd.lcd_string("Model B+", 2)
lcd.GPIO.cleanup()
Exemplo n.º 29
0
def main_program():
    global MOTOR1_POS
    global MOTOR1_NEG
    global MOTOR2_POS
    global MOTOR2_NEG
    global RELAY_MOTOR
    global RELAY_SPARY
    global IR_SENSOR
    delayCounter = 0
    internetData = 0
    roboState = 0
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(RELAY_MOTOR, GPIO.OUT)
    GPIO.setup(RELAY_SPARY, GPIO.OUT)
    GPIO.setup(MOTOR1_POS, GPIO.OUT)
    GPIO.setup(MOTOR1_NEG, GPIO.OUT)
    GPIO.setup(MOTOR2_POS, GPIO.OUT)
    GPIO.setup(MOTOR2_NEG, GPIO.OUT)
    GPIO.setup(IR_SENSOR, GPIO.IN)

    GPIO.output(RELAY_MOTOR, GPIO.LOW)
    GPIO.output(RELAY_SPARY, GPIO.LOW)
    GPIO.output(MOTOR1_POS, GPIO.LOW)
    GPIO.output(MOTOR1_NEG, GPIO.LOW)
    GPIO.output(MOTOR2_POS, GPIO.LOW)
    GPIO.output(MOTOR2_NEG, GPIO.LOW)

    lcd.lcd_init()
    # Send some test
    lcd.lcd_string("Agriculture ", LCD_LINE_1)
    lcd.lcd_string("Robo System", LCD_LINE_2)
    time.sleep(3)
    while True:
        temp = readTempSensor()
        print 'temp:' + str(temp) + '    '
        soilInfo = readSoilInfoSensor()
        print 'soil:' + str(soilInfo)
        lcdLine1 = 'TEMP:' + str(temp)
        lcdLine2 = 'SOIL:' + str(soilInfo)
        if GPIO.input(IR_SENSOR):
            if internetData == '1':
                Stop()
            lcdLine1 = lcdLine1 + ' AD'
        lcd.lcd_string(lcdLine1, LCD_LINE_1)
        lcd.lcd_string(lcdLine2, LCD_LINE_2)
        if roboState == 0:
            if int(soilInfo) > 500:
                GPIO.output(RELAY_MOTOR, GPIO.LOW)
            else:
                delayCounter = delayCounter + 1
            if delayCounter > 5:
                GPIO.output(RELAY_MOTOR, GPIO.HIGH)
                delayCounter = 0

        print 'IR:' + str(GPIO.input(IR_SENSOR))

        try:
            socketId = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            host = '54.255.248.231'
            port = 3011
            # connection to hostname on the port.
            socketId.connect((host, port))
            socketId.settimeout(2.0)
            if GPIO.input(IR_SENSOR):
                if internetData == '1':
                    Stop()
            internetData = socketId.recv(1)
            print data
            socketId.settimeout(None)
            socketId.close()
        except:
            print 'timeout'
        if internetData == '1':
            if GPIO.input(IR_SENSOR) == 0:
                Forword()
            else:
                Stop()
            roboState = 1
            GPIO.output(RELAY_MOTOR, GPIO.LOW)
        if internetData == '2':
            Reverse()
            roboState = 1
            GPIO.output(RELAY_MOTOR, GPIO.LOW)
        if internetData == '3':
            Left()
            roboState = 1
            GPIO.output(RELAY_MOTOR, GPIO.LOW)
        if internetData == '4':
            Right()
            roboState = 1
            GPIO.output(RELAY_MOTOR, GPIO.LOW)
        if internetData == '5':
            Stop()
            roboState = 0
        if internetData == '6':
            GPIO.output(RELAY_SPARY, GPIO.HIGH)
        if internetData == '7':
            GPIO.output(RELAY_SPARY, GPIO.LOW)
        if GPIO.input(IR_SENSOR):
            if internetData == '1':
                Stop()
        IoTSend.send_IoTData(temp, soilInfo)
        time.sleep(1)
    return
Exemplo n.º 30
0
def not_found(error):
    error_light()
    print("errorhandler light")
    lcd.lcd_init()
    lcd.lcd_string("Can't find entry",2)
    return make_response(jsonify({'Error': 'Not Found'}), 404)