Jade Perreault
Published © CC BY-NC-SA

Home Monitoring And Alerts For The Blind

This project is for the assistance of blind and hard of seeing enabling them to find their way with alerts and voice directions.

AdvancedWork in progressOver 4 days9,142

Things used in this project

Story

Read more

Code

Python Code

Python
Copy Paste this into a python script explanation on previous screen
#****************gpio_control.py****************

from flask import Flask
from flask_ask import Ask, statement, convert_errors
import RPi.GPIO as GPIO
import logging

GPIO.setmode(GPIO.BCM)
app = Flask(__name__)
ask = Ask(app, '/')
logging.getLogger("flask_ask").setLevel(logging.DEBUG)

@ask.intent('GPIOControlIntent', mapping={'status': 'status','pin':'pin'})
def gpio_control(status,pin):
    try:
         pinNum = int(pin)
    except Exception as e:
         return statment ('Pin Number Not Valid.')
    GPIO.setup(pinNum, GPIO.OUT)
    if status in ['on','high' ]:   GPIO.output(pinNum, GPIO.HIGH)
    if status in ['on',  'low']:   GPIO.output(pinNum, GPIO.LOW)
    return statement ('turning pin {}  {}'.format(pin, status))
    GPIOControlIntentstate=GPIO.input(14)
    if  (state == True):
      GPIO.setup(14, GPIO.OUT)
      GPIO.output(14,GPIO.HIGH)
      return statement('InPut One Already On')
##+++++++++++++++++++++++++++++++++++++++++++++++++++
      GPIO.setup(15, GPIO.IN)
      state=GPIO.input(15)
      if  (state == True):
         GPIO.setup(15, GPIO.OUT)
         GPIO.output(15,GPIO.HIGH)
         return statement('InPut Two Already On')
      else:
        GPIO.setup(15, GPIO.OUT)
        GPIO.output(15, GPIO.HIGH)
        return statement('InPut Two {}'.format(status))

    if status in['off', 'low']:
      GPIO.setup(15, GPIO.IN)
      state=GPIO.input(15)
      print('status of input',state)
      if (state == False):
        GPIO.setup(15, GPIO.OUT)
        GPIO.output(15,GPIO.LOW)
        return statement('InPut Two Already Off')
      else:
        GPIO.setup(15, GPIO.OUT)
        GPIO.output(15, GPIO.LOW)
        return statement('InPut Two {}'.format(status))
##++++++++++++++++++++++++++++++++++++++++++++++
      GPIO.setup(18, GPIO.IN)
      state=GPIO.input(18)
      if  (state == True):
         GPIO.setup(18, GPIO.OUT)
         GPIO.output(18,GPIO.HIGH)
         return statement('InPut Three Already On')
      else:
        GPIO.setup(18, GPIO.OUT)
        GPIO.output(18, GPIO.HIGH)
        return statement('InPut Three {}'.format(status))

    if status in['off', 'low']:
      GPIO.setup(18, GPIO.IN)
      state=GPIO.input(18)
      print('status of input',state)
      if (state == False):
        GPIO.setup(18, GPIO.OUT)
        GPIO.output(18,GPIO.LOW)
        return statement('InPut Three Already Off')
      else:
        GPIO.setup(18, GPIO.OUT)
        GPIO.output(18, GPIO.LOW)
        return statement('InPut Three {}'.format(status))
##++++++++++++++++++++++++++++++++++++++++++++++++

      GPIO.setup(23, GPIO.IN)
      state=GPIO.input(23)
      if  (state == True):
         GPIO.setup(23, GPIO.OUT)
         GPIO.output(23,GPIO.HIGH)
         return statement('InPut Four Already On')
      else:
        GPIO.setup(23, GPIO.OUT)
        GPIO.output(23, GPIO.HIGH)
        return statement('InPut Four {}'.format(status))

    if status in['off', 'low']:
      GPIO.setup(23, GPIO.IN)
      state=GPIO.input(23)
      print('status of input',state)
      if (state == False):
        GPIO.setup(23, GPIO.OUT)
        GPIO.output(23,GPIO.LOW)
        return statement('InPut Four Already Off')
      else:
        GPIO.setup(23, GPIO.OUT)
        GPIO.output(23, GPIO.LOW)
        return statement('InPut Four {}'.format(status))

##+++++++++++++++++++++++++++++++++++++++++++++++++

      GPIO.setup(24, GPIO.IN)
      state=GPIO.input(24)
      if  (state == True):
         GPIO.setup(24, GPIO.OUT)
         GPIO.output(24,GPIO.HIGH)
         return statement('InPut Five Already On')
      else:
        GPIO.setup(24, GPIO.OUT)
        GPIO.output(24, GPIO.HIGH)
        return statement('InPut Five {}'.format(status))

    if status in['off', 'low']:
      GPIO.setup(24, GPIO.IN)
      state=GPIO.input(24)
      print('status of input',state)
      if (state == False):
        GPIO.setup(24, GPIO.OUT)
        GPIO.output(24,GPIO.LOW)
        return statement('InPut Five Already Off')
      else:
        GPIO.setup(24, GPIO.OUT)
        GPIO.output(24, GPIO.LOW)
        return statement('InPut Five {}'.format(status))

##++++++++++++++++++++++++++++++++++++++++++++++++++++

      GPIO.setup(25, GPIO.IN)
      state=GPIO.input(25)
      if  (state == True):
         GPIO.setup(25, GPIO.OUT)
         GPIO.output(25,GPIO.HIGH)
         return statement('InPut Six Already On')
      else:
        GPIO.setup(25, GPIO.OUT)
        GPIO.output(25, GPIO.HIGH)
        return statement('InPut Six {}'.format(status))

    if status in['off', 'low']:
      GPIO.setup(25, GPIO.IN)
      state=GPIO.input(25)
      print('status of input',state)
      if (state == False):
        GPIO.setup(25, GPIO.OUT)
        GPIO.output(25,GPIO.LOW)
        return statement('InPut Six Already Off')
      else:
        GPIO.setup(25, GPIO.OUT)
        GPIO.output(25, GPIO.LOW)
        return statement('InPut Six {}'.format(status))


if __name__=='__main__':
 port = 5000
 app.run(host='0.0.0.0',port=port)



##+++++++++++++++++++++++++++++++++++++++++++++++++++++++

@ask.intent('LocationControlIntent', mapping={'status':'status', 'location':'location'})
def location_control(status,location):

   locationDict  = {
        'Bed_Light': 12,
        'kitchen_Light': 16,
        'Coffee_Maker': 18,
        'Front_Window': 22'
        'Side_Window': 32,
        'Bed_Window': 33,
   }
   targetPin =  locationDict[location]

   GPIO.setup(targetPin, GPIO.OUT)


   if status in ['on', 'high']:   GPIO.output(targetPin, GPIO.HIGH)
   if status in ['off', 'low']:   GPIO.output(targetPin, GPIO.LOW)

   return statment ('turning {} {}!'.format(location, status))

Credits

Jade Perreault

Jade Perreault

32 projects • 59 followers
27 Years as a Journeyman Electrician , 4 Years as a PCB design engineer for Penteon Corporation Out of New York ..

Comments