Hello again! I had to delay this project for a little bit because I had final exams. Now that they're over, I've got some catching up to do. But it has been great to see the progress the other challengers are making!
In case you missed my previous posts, you can see them all here.
In my previous updates, I have discussed my progress in getting the Edison to recognize which key is being typed. As we have seen, there have been some issues. Remember how each type bar rests on a loop of copper wire to indicate that it is not being pressed? Well there is actually a lot of vibration that occurs when you type and this causes the type bars to momentarily lift off the copper wire, indicating a false positive. This is bad enough by itself, but also sometimes the type bar does not come back down to rest directly on the wire which makes the Edison think that the key is always being pressed. Basically, the Edison keeps reading multiple keys when I only want it to read one. I am going to continue investigating the best way to remedy these issues but it is possible that I will have to abandon this method altogether and try a different approach.
In the meantime however, I decided to work on some of the email-sending code for the Edison. I initially tried using python's smtplib to send an email through a gmail account I set up specifically for this project. While I was browsing stackoverflow to see if anyone else had accomplished this, I came across another method of sending an email that was much simpler. It involves using a service called mailgun. Mailgun is a good way of automatically sending emails using HTTP requests and it's free if you're sending under 10,000 emails a month. Below is the python code I used to send a sample email.
import requests import email def send_email(): fp = open('sample_email', 'r') msg = email.message_from_file(fp) fp.close() return requests.post("https://api.mailgun.net/v3/MY_DOMAIN_NAME/messages", auth=("api", "MY_API_KEY"), data={"from": "MYEMAIL@EMAIL.COM", "to": msg.get('to'), "subject": msg.get('subject'), "text": msg.get_payload()}) if __name__ == '__main__': print send_email()
Notice I'm using another library called requests. This gives me an easy way to send HTTP requests and I would definitely recommend it if you're ever using python to communicate via HTTP. The send_email() function returns a Response which is basically just a code that tells me if the request was successful. If I get a response code of 200 then it worked fine.
I should also mention that I am using python's email library to turn a file into an email message. This is a little easier than manually parsing the file myself. The sample_email file looks like this:
Subject: Sample email
This is a sample email to test the email
function of the hermes 3000 project.
End.
Lastly, I wrote some code that will wait for a button press, then call the send_email() function, then light an LED if I get a response code of 200 (so I know the request went through).
import mraa import time import send_email LED_IO = 13 BTN_IO = 12 led = mraa.Gpio(LED_IO) led.dir(mraa.DIR_OUT) button = mraa.Gpio(BTN_IO) button.dir(mraa.DIR_IN) led.write(0) while 1: if(button.read() == 1): time.sleep(0.5) r = send_email.send_email() if(r.status_code == 200): led.write(1) time.sleep(1) led.write(0) else: continue
When I run this code and then push the button, I see the LED light up for a second and then I get this in my email:
So the email sending function works! Here's how it will all go together: the user types an email which will have the same format as the sample email above. These characters will get written to a file as the user types. Then the user will press a button, the send_email() function will be called (but it will create the email from the file the user was modifying - not the sample_email file). The email will be sent off and the file will be erased so the next email can be typed.
Now that that's out of the way, I can get back to working on the key-detection mechanism. Once I have that fixed, I will try to incorporate some additional features if time permits. I hope you enjoyed this update, stay tuned for my next post! Let me know if you have any questions, comments, concerns, or criticisms.
Top Comments