Added project files

master
Marvin Johanning 2018-07-10 22:30:24 +02:00
parent 82f508dfcd
commit de3f1d2780
7 changed files with 151 additions and 3 deletions

8
serial Normal file
View File

@ -0,0 +1,8 @@
/dev/video0 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/input/event12 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/input/mouse2 - 1ea7_2.4G_Mouse
/dev/input/event15 - 1ea7_2.4G_Mouse
/dev/ttyACM4 - Arduino__www.arduino.cc__0043_75735323230351F09102
/dev/ttyACM2 - TOSHIBA_F5321gw_847A5C4419678500
/dev/ttyACM1 - TOSHIBA_F5321gw_847A5C4419678500
/dev/ttyACM0 - TOSHIBA_F5321gw_847A5C4419678500

11
src/detect_serial.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
echo "/dev/$devname - $ID_SERIAL"
)
done

11
src/detectserial.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
echo "/dev/$devname - $ID_SERIAL"
)
done

58
src/gmail.rb Normal file
View File

@ -0,0 +1,58 @@
require 'serialport'
require 'gmail'
require 'fileutils'
puts File.dirname(__FILE__)
#Start the bash file, read the file it creates and find out what port the Arduino is connected to
system("bash #{File.dirname(__FILE__)}/detect_serial.sh > serial")
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("username", "password")
#count the number of unread messages
prev_unread = gmail.inbox.count(:unread)
#Serial port of the Arduino
puts "Arduino is connected to: #{@serial_connection}"
port_file = @serial_connection.gsub(' ', '')
#this must be same as the baud rate set on the Arduino
#with Serial.begin
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
#create a SerialPort object using each of the bits of information
port = SerialPort.new(port_file, baud_rate, data_bits, stop_bits, parity)
wait_time = 4
#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
#For debugging purposes
puts "Received email: \n" + gmail.inbox.find(:unread).last.subject
end
#reset the number of unread emails
prev_unread = unread
#wait before we make another request to the Gmail servers
sleep wait_time
end

View File

@ -1,9 +1,58 @@
#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
String incomingString = "";
int buzzer = 2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(buzzer, OUTPUT);
}
void notifingBeep() {
unsigned char i;
for(i=0;i<50;i++) {
digitalWrite(buzzer, HIGH);
delay(10);
digitalWrite(buzzer, LOW);
delay(10);
}
}
void got_email(String subject) {
//Initial two beeps to alert user to incoming email
notifingBeep();
delay(200);
notifingBeep();
lcd.setCursor(0, 0);
lcd.print("You've got mail!");
delay(5000);
int str_len = subject.length() + 1;
char char_array[str_len];
subject.toCharArray(char_array, str_len);
unsigned int i;
lcd.clear();
lcd.setCursor(16, 1);
lcd.autoscroll();
for (i = 0; i < sizeof(char_array) - 1; i++){
lcd.print(char_array[i]);
delay(500);
}
//Last beep to inform user of end of email
notifingBeep();
}
void loop() {
// put your main code here, to run repeatedly:
}
if(Serial.available() > 0) {
incomingString = Serial.readString();
got_email(incomingString);
}
}

8
src/serial Normal file
View File

@ -0,0 +1,8 @@
/dev/video0 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/input/event12 - Chicony_Electronics_Co._Ltd._TOSHIBA_Web_Camera_-_HD_0x0001
/dev/input/mouse2 - 1ea7_2.4G_Mouse
/dev/input/event15 - 1ea7_2.4G_Mouse
/dev/ttyACM4 - Arduino__www.arduino.cc__0043_75735323230351F09102
/dev/ttyACM2 - TOSHIBA_F5321gw_847A5C4419678500
/dev/ttyACM1 - TOSHIBA_F5321gw_847A5C4419678500
/dev/ttyACM0 - TOSHIBA_F5321gw_847A5C4419678500

3
start Executable file
View File

@ -0,0 +1,3 @@
#!/bin/env ruby
load "#{File.dirname(__FILE__)}/src/gmail.rb"