Posted on July 31, 2015 in home automation, linux, raspberryPi
I builded a digital photo frame in 2012 with a old TFT-screen 17″ that I had lying around.
Here comes a post about how I did it, and sharing my scripts…
Here is a video and the photo frame have a uptime for three years now.
Guide from clean install of raspbian – using 2015-05-05 version.
pi@fotoram ~ $ sudo apt-get update
pi@fotoram ~ $ sudo apt-get upgrade
Now you have the latest version of your raspbian.
Now we have to install feh. Feh is the program that display the pictures and installing php, because we are using some php-scripts.
And at least, sendmail. Because after we email a picture, we get a respond from the photoframe that the picture is received.
pi@fotoram ~ $ sudo apt-get install feh php5-cli php5-imap sendmail
Download the scripts.
PhotoFrame.zip
Okey, how does this work? First we have to disable screensaver, otherwise the screen will shutdown.
Stop text terminals from blanking
change in /etc/kbd/config these two:
BLANK_TIME=0
POWERDOWN_TIME=0
Stop Xsession from blanking
Add these lines to /etc/xdg/lxsession/LXDE-pi/autostart or /home/pi/.config/lxsession/LXDE-pi/autostart
@xset s noblank
@xset s off
@xset -dpms
and comment out line @xscreensaver -no-splash to
#@xscreensaver -no-splash
In the photoframe.zip file we have a couple of files.
bilder = folder there feh will look for pictures.
display.txt = textfile with information that will display in the bottom corner.
fetch_mail.php = A php script that fetch new pictures from gmail.
get_online_pics.sh = A script that fetch webcam pictures from the internet and put it to the bilder folder.
picslide.sh = Script that start feh at boot.
put_display.sh = Update the information in display.txt file
run_fetch_mail.sh = Script that run fetch_mail.php, I made it because sometimes it take some time to fetch a new picture from gmail. And if the service is running the system hangs. So this script look if the fetch_mail.php is running, and if it does. It won’t start a new one.
Now everything is installed and the scrips are in pi homefolder.
Now add these lines to cron.
First I like pico as a editor insteed of vim.
So change the editor
pi@fotoram ~ $ which pico # Output /usr/bin/pico
pi@fotoram ~ $ export EDITOR=/usr/bin/pico
Now run
pi@fotoram ~ $ crontab -e
Add following lines:
*/1 * * * * /home/pi/get_online_pics.sh > /dev/null 2>&1 # Get a new pictures from webcam
*/1 * * * * /home/pi/put_display.sh > /dev/null 2>&1 # Update display.txt
*/5 * * * * /home/pi/run_fetch_mail.sh > /dev/null 2>&1 # Get new pictures from Gmail
00 22 * * * /opt/vc/bin/tvservice -o > /dev/null 2>&1 # Shutdown screen at 22:00
00 05 * * * sudo reboot > /dev/null 2>&1 # Reboot the Pi at 05:00 so the screen wakes up
Now we have that running, lets add so feh starts at bootup. Go back to /etc/xdg/lxsession/LXDE-pi/autostart or /home/pi/.config/lxsession/LXDE-pi/autostart and add @/home/pi/picslide.sh at the bottom save and then reboot.
As you can see in my script, that fetch_mail.php the script is only looking for new pictures in label Fotoram. So you have to make a filter in gmail. I using
Match: from:(myemailAndOneFilterforMypartnersEmail@essunga.org)
Do: Jump over Inbox, Use Label "Fotoram"
Do you have any questions or problems, please write a comment.
Posted on July 30, 2015 in linux, tips
Here is one simple way to unzip multiple zip files in linux thru console.
bash-4.2$ for i in *.zip; do unzip -d $i.folder $i; done
Posted on July 27, 2015 in alarm, home automation, mailbox, moteino
Here is how I build my alarm, quite simple to do and to get push messages from prowl or mail.
For Gateway I use a moteino connected to a raspberryPi model B+ as you can see from the pictures below.
Feel free to ask questions or guidance if you want to build one by you own.
Arduino IDE Code:
#include <RFM69.h> #include <SPI.h> #include <LowPower.h> #include <PinChangeInt.h> // Two lines to include pinChangeInt library //====================================================================== // NOTE! The logic of mailbox OPEN vs CLOSED has been reversed for D4 // D4 = HIGH is Mailbox OPENED (magnetic switch open) // D4 = LOW is Mailbox CLOSED (magnetic switch closed) //====================================================================== #define NODEID 2 // unique for each node on same network #define GATEWAYID 1 #define NETWORKID 100 // the same on all nodes that talk to each other #define FREQUENCY RF69_868MHZ #define ENCRYPTKEY "sampleEncryptKey" // exactly the same 16 characters/bytes on all nodes! #define ACK_TIME 30 // max # of ms to wait for an ack #define LED 9 // Moteinos have LEDs on D9 #define SERIAL_BAUD 115200 #define D4 4 #ifdef SERIAL_EN #define DEBUG(input) {Serial.print(input); delay(1);} #define DEBUGln(input) {Serial.println(input); delay(1);} #else #define DEBUG(input); #define DEBUGln(input); #endif RFM69 radio; bool promiscuousMode = false; // Set to 'true' to sniff all packets on the same network bool sentOpen = true; bool stateCheck=LOW; uint32_t switchTime=0; // variable to monitor when the switch last changed state (for debouncing) #define DEBOUNCE_TIME 50 // give it 50 mS to debounce a noisy switch // Add function to catch interrupt, doesn't need to do anything as the interrupt is all that's needed to wakeup void wakeUp(void) { } void setup() { //Setup the pins pinMode(LED, OUTPUT); pinMode(D4, INPUT_PULLUP); // TOMWS: Use internal pullup as it's easier than adding an external one... //Start the Serial Serial.begin(SERIAL_BAUD); delay(10); //Initialize the radio radio.initialize(FREQUENCY,NODEID,NETWORKID); #ifdef IS_RFM69HW //radio.setHighPower(); // Uncomment only for RFM69HW! #endif radio.encrypt(ENCRYPTKEY); // Turn encryption ON radio.promiscuous(promiscuousMode); // TOMWS: This is not necessary if not using this mode char buff[50]; sprintf(buff, "\nTransmiting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915); Serial.println(buff); } void loop() { if (digitalRead(D4) == HIGH) // If the mailbox is opened { switchTime = millis(); // record when we saw the switch change state stateCheck = LOW; if (sentOpen == false) // have we already sent this? { // no, send it now if (radio.sendWithRetry(GATEWAYID, "MAIL:OPN", 8)) { Serial.println(" nothing..."); // Blink(LED,3); } else { Serial.println("Sending Open mailboxstatus to gateway.."); } sentOpen = true; radio.sleep(); // we're done with the radio, make it sleep to save power immediately } } else { switchTime = millis(); // record when we saw the switch change state stateCheck = HIGH; if (sentOpen == true) // have we already sent this? { delay(10000); // no, send it now if (radio.sendWithRetry(GATEWAYID, "MAIL:CLS", 8)) { Serial.println(" nothing..."); } else { Serial.println("Sending closed, once... "); } sentOpen = false; radio.sleep(); // we're done with the radio, make it sleep to save power immediately } } while ((switchTime-millis()) < DEBOUNCE_TIME) // debounce the switch { if (digitalRead(D4) == stateCheck) switchTime = millis(); // if we sense a 'bounce' reset the timer } Serial.flush(); // need to do before sleeping. // Allow wake up pin to trigger interrupt on either edge. PCintPort::attachInterrupt(D4, wakeUp, CHANGE); // New code to trap interrupt on pin change LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); // Changed to SLEEP_FOREVER so that only interrupts wake up, no WDT used // WOKEN UP! Disable further interrupts until debounced PCintPort::detachInterrupt(D4); // disable interrupts until debounced } void Blink(byte PIN, int DELAY_MS) // Local led blinking function { // pinMode(PIN, OUTPUT); // digitalWrite(PIN,HIGH); // delay(DELAY_MS); // digitalWrite(PIN,LOW); }
Shopping list:
Kjell o Co www.kjell.com
Artnr:
39780 Batterycase 4xR6 (AA) (fits perfect in the Box, had to remove some plastic)
89024 Box Höjd: 20 mm
42480 AA Litium 4-pack
Posted on July 17, 2015 in home automation, linux, moteino
Posted on July 17, 2015 in home automation, life
It was time for some new changes around here, and here it is. I have to do someting in my sparetime, besides programming my homeautomation and building a outside deck.
It is vacation as they say…