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