Alert project


#1

Hey.

Im working on a project where i want to use i sound sensor to alert me when its activated. I´ve tried using sound_sensor.py file and just modify it to send me a notification on twitter. this might be naive of me, but can i just add part of the code found in the wifi_twit.py?

something in the lines of:

while True:
try:
# Read the sound level
sensor_value = grovepi.analogRead(sound_sensor)

    # If loud, illuminate LED, otherwise dim
    if sensor_value > threshold_value:
        grovepi.digitalWrite(led,1)
    print (what ever i want the message to be)
    api.PostUpdate(what ever i want the message to be)

    else:
        grovepi.digitalWrite(led,0)

#2

Hey

You will need to instigate your Twitter connection first with this line:
api = twitter.Api(consumer_key=‘YourKey’,consumer_secret=‘YourKey’,access_token_key=‘YourKey’,access_token_secret=‘YourKey’)

and of course, you have to go to Twitter, and create your API connection there. You need all four keys that will be generated by Twitter. consumer_key, consumer_secret, access_token_key and access_token_secret


#3

thanks for the reply. i´ve generated the four keys from twitter and entered in the “yourkey” spaces. but when i try to run the program i get error whith the “import twitter”. Im guessing i´ll need some files to make that work, just like i needed to run the setup.py to get the import grovepi command to work?


#4

Yes, you do need the twitter library, sorry about that. I totally forgot that step
Launch a terminal window
type in
pip install python-twitter

Let me know if that works for you