Scripts that I use on my Raspberry Pi #4

Sometimes you want that your Raspberry Pi connects many different wireless networks. To do this you just have to add file wpa_supplicant.conf to your memory card (You can do that example with notepad) and add this to it:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="petrilopia_home"
    psk="password"
    id_str="home"
    priority=1
}

network={
    ssid="petrilopianet_mobile"
    psk="password"
    id_str="mobile"
    priority=2
}

network={
    ssid="petrilopianet_guest"
    psk="password"
    id_str="guest"
    priority=3
}

Of course change “ssid” to be your network SSID and “psk” to be password of that networks and “priority” is where you can change which network your Raspberry Pi tries to connect first which second and so on…

If you want to SSH be enabled when you start up your Raspberry Pi you can do it easily at the same time when you add that wpa_supplicant.conf file to your Raspberry Pi memory card but this time just create empty file called “ssh” without any extension like .txt or anything like that.

Scripts that I use on my Raspberry Pi #3

I normally use sendemail on my Rasberry Pi because it’s easiest way to send email from your Raspberry Pi Linux machine using command line.

Let’s first install sendemail:

apt-get install sendemail

Using sendemail is easy:

sendemail -xu LOGIN -xp PASSWORD -f FROM -t TO -s SERVER:PORT -o tls=yes -u "SUBJECT" -m "MESSAGE" -a ATTACHEMENT FILE

You might not need -xu, -xp or tls=yes but I have used those just to be sure.

So my typical sendemail line is pretty much like this:

sendemail -xu LOGIN@gmail.com -xp PASSWORD -f my@email -t TO -s smtp.gmail.com:587 -o tls=yes -u "Test" -m "Just testing" -a /scripts/myscript.sh

When I’m not sure if my scripts/raspberry pi is working perfectly I use to add scripts as attachement so I easily have at least one
working copy of my script and different versions of it at the same time.

Now we can use this with earlier scripts example with IP scripts we can add this line to good place on that script:

sendemail -xu LOGIN@gmail.com -xp PASSWORD -f my@email -t TO -s smtp.gmail.com:587 -o tls=yes -u "RasPi IP" -m "Your Raspberry Pi new IP address is $ip2"

If your sendemail says:

Sep 13 06:33:08 raspberrypi sendemail[16329]: ERROR => No TLS support!  SendEmail can't load required libraries. (try installing Net::SSLeay and IO::Socket::SSL)

It should start to work if you install libio-socket-ssl-perl:

apt-get install libio-socket-ssl-perl

This has helped every time when I have had this problem.

How to search Coronavirus Tracing App Koronavilkku users

Since finnish version of Coronavirus Tracing App called Koronavilkku was released I have been wanting to find out if it is possible to see how many Koronavilkku users there is around me. So I have been playing with this app for about two weeks now and it seems to be working.

Because of an old project I happened to have Bluetooth LE scanner called RaMBLE – Bluetooth LE Mapper installed on my phone, so I started with that. I found out that if I scan bluetooth LE devices and use “Service UUID” filter “FD6F” I could find Koronavilkku users around me. Because Koronavilkku is using “Google’s & Apple’s Exposure Notification Framework” you should get this work on other countries too.

First add filters: RaMBLe filters for Covid Blinker

And then just turn on the scanner: RaMBLe Covid Blinker Results

Now there is even app for this called UUID 0xFD6F Scanner but I find it much more interesting to use tools that you can use for many purposes than these kind of apps.

Please let me know in the comments if this works with your phone and in your country. Feel free to correct me if I have wrote something that is not correct

Scripts that I use on my Raspberry Pi #2

This simple script just checks if your Raspberry Pi is connected to the Internet or not. So using this script is really easy, it will make Raspberry Pi reboot itself if it’s not connected to the Internet or do something else to get it connected again. This has saved me so many times when I have been using my headless Raspberry Pi setup and when my Raspberry Pi has been connected to Internet via 3G/4G USB modem and it has lost the connection once again.

#!/bin/bash
ping -c 3 8.8.8.8 > /dev/null 2>&1
let a=$?
if [ "$a" = "0" ]; then
  echo "We have connection."
else
  echo "We have lost connection."
fi

Scripts that I use on my Raspberry Pi #1

This script checks what your current external IP address and will let you know if it has changed since the last time you checked. You can easily modify this script to make your Raspberry Pi send you an email of it’s external IP address and send email when it’s email address has changed so this is pretty useful script for many kind of headless Raspberry Pi uses.

#!/bin/sh

ip1=""
ip2=""
ip="/scripts/ip.txt"

[ ! -f $ip ] && touch $ip

read ip1 < $ip
ip2=$(wget -U 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4' -qO- ifconfig.me/ip)

if [ "$ip1" = "$ip2" ]
then
 echo "IP is still the same $ip2"
  exit
else
  echo "$ip2" > $ip
        echo "IP has changed and it's now $ip2"
  exit
fi