Make output more verbose
parent
f9affe4641
commit
5918222383
17
src/gmail.rb
17
src/gmail.rb
|
@ -14,11 +14,14 @@ end
|
|||
|
||||
#Checking internet connection to google.com (pinging it)
|
||||
begin
|
||||
puts "Checking internet connection ..."
|
||||
TCPSocket.new 'google.com', 443
|
||||
rescue SocketError
|
||||
puts "ERROR: ".colorize(:red) + "The program was unable to find an active internet connection. " \
|
||||
"Please check your internet connection and try again"
|
||||
exit
|
||||
else
|
||||
puts "SUCCESS: ".colorize(:green) + "Active internet connection found"
|
||||
end
|
||||
|
||||
#Create string to hold the Arduino's serial connection
|
||||
|
@ -30,26 +33,29 @@ File.open("#{File.dirname(__FILE__)}/serial").each_line do |line|
|
|||
@serial_connection = line.slice(0..(line.index(' '))) if line.include?("Arduino")
|
||||
end
|
||||
|
||||
#FileUtils.rm("#{File.dirname(__FILE__)}/src/serial")
|
||||
|
||||
#Gmail username and password
|
||||
gmail = Gmail.connect($gmail_username, $gmail_password)
|
||||
|
||||
#count the number of unread messages
|
||||
begin
|
||||
puts "Checking connection to Gmail ..."
|
||||
prev_unread = gmail.inbox.count(:unread)
|
||||
rescue Net::IMAP::BadResponseError
|
||||
puts "ERROR: ".colorize(:red) + "Connecting to your Gmail account has failed (NET::IMAP::BadResponseError)\n" \
|
||||
"Please ensure that you have entered your correct username and password (refer to README for further details)"
|
||||
exit
|
||||
else
|
||||
puts "SUCCESS: ".colorize(:green) + "Sucessfully connected to Gmail with provided login details"
|
||||
end
|
||||
|
||||
#Serial port of the Arduino
|
||||
puts "Detecting Arduino..."
|
||||
unless @serial_connection.size > 0
|
||||
puts "ERROR: ".colorize(:red) + "No Arduino has been found connected to your computer\n" \
|
||||
"Please check if your Arduino is working and has been properly connected"
|
||||
exit
|
||||
else
|
||||
puts "SUCCESS: ".colorize(:green) + "Arduino has been found"
|
||||
puts "Arduino is connected to: #{@serial_connection}"
|
||||
port_file = @serial_connection.gsub(' ', '')
|
||||
end
|
||||
|
@ -67,18 +73,17 @@ port = SerialPort.new(port_file, baud_rate, data_bits, stop_bits, parity)
|
|||
|
||||
wait_time = 4
|
||||
|
||||
puts "Checking emails ..."
|
||||
|
||||
#for an infinite amount of time
|
||||
loop do
|
||||
#get the number of unread messages in the inbox
|
||||
unread = gmail.inbox.count(:unread)
|
||||
|
||||
#lets us know that we've checked the unread messages
|
||||
puts "Checked unread."
|
||||
|
||||
#check if the number of unread messages has increased
|
||||
if unread > prev_unread
|
||||
#Write the subject of the last unread email to the serial port
|
||||
port.write gmail.inbox.find(:unread).last.subject
|
||||
port.write gmail.inbox.find(:unread).last.subject.upcase
|
||||
|
||||
#For debugging purposes
|
||||
puts "Received email: \n" + gmail.inbox.find(:unread).last.subject
|
||||
|
|
|
@ -23,7 +23,6 @@ void notifingBeep() {
|
|||
}
|
||||
|
||||
void got_email(String subject) {
|
||||
|
||||
//Initial two beeps to alert user to incoming email
|
||||
notifingBeep();
|
||||
delay(200);
|
||||
|
@ -31,6 +30,8 @@ void got_email(String subject) {
|
|||
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("You've got mail!");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Subject:");
|
||||
delay(5000);
|
||||
|
||||
int str_len = subject.length() + 1;
|
||||
|
|
Loading…
Reference in New Issue