Tag: Raspberry Pi
I posted previously about using Twlio to get an RPi to send text message notifications to me using a Twilio trial account. These trial accounts used to keep going unless you stopped using them for a period of time, but now they time out like most trial accounts do.
I scouted around looking for another notification method. I didn’t want to use email. I’d previously used sSMTP with some success, but I wanted to try something different.
Pushbullet is working well for me. You can get a free account, and apps for Android and Apple. Once you’ve got your free API authentication key you can make web requests to the Pushbullet service and they’re delivered to your mobile.
I use the cUrl app to make the requests. If you need to install it, you can do so by entering this command in a terminal. (For other unrelated purposes, I also incorporate cUrl into some applications I develop, so I always install the libcurl3 development libraries as well. If you don’t need them you can leave them off the command. For completeness, this is the command I use to install all things cUrl on my boxes.)
sudo apt-get -y install curl libcurl3 libcurl3-dev
Then I create shell scripts similar to the following which can be called by other scripts or applications, or triggered by
title= parameter, it is often convenient to use the name of the process you’re reporting on, or the name of the RPi or PC it is running on.
API="enter your API key here"
MSG="This is where you would put your message text"
curl -u $API: https://api.pushbullet.com/v2/pushes -d type=note -d title="Message Title" -d body="$MSG"
Nice and simple, and free.
[Edit] It seems that Twilio trial accounts timeout after all. They used to keep going so long as you didn’t go 30 days or more without using it. So this was a short lived success. I’ll look for alternate solutions.
I wanted a simple and free way to send texts to myself from one of my Raspberry Pi’s. The Pi is running the Jessie release of Debian. Debian, as the universe and its dog knows, is the OS that Ubuntu is built on, so these instructions apply to Ubuntu as well. I have tested on Ubuntu 15.10 and 16.04.
I got my Pi to send texts to my mobile using a free account from Twilio. Twilio is a Platform as a Service (PaaS) company based in California. Their platform and API’s allow developers to build applications that can make telephone calls, send text messages and much, much more.
Of course, for all of this goodness there is a charge. This is a paid for service. But luckily for me, you can get a free trial account. And although it is a trial it seems to run forever, unless you stop using it for a thirty day period. There are restrictions, naturally. You can only send out to one mobile phone number, for one thing. I only wanted to send to one number (my own mobile phone) so that was perfect for me.
To get your Ubuntu box or Raspberry Pi to send texts you need to register with Twilio and sign up for a free account. You will have to nominate the mobile number you’re going to text out to. Twilio verify this number by sending a code to it that you need to enter back into the website during the registration process. Once you have completed the registration you will get three things. One is a virtual phone number that the texts will be sent from. The other two are an account Id and an API authentication token. You’ll need all three of these to make the API call that will send the text.
You also need to have Pyhton, pip and Twilio installed on your system. Most systems will have Python and some will have pip (my Pi did, my Ubuntu did not). You will need to install Twilio as well. If any of these are missing from your system, you can install them with:
sudo apt-get install python
sudo apt-get install python-pip
sudo pip install twilio
The minimum Python script that you need to send a text is shown below (with my details obscured). Of course, you need to replace the account=, token= and from= and to= values with your own account ID, authentication token, virtual telephone number and the number that you want to have the text sent to. This last one must be the mobile number you verified during the Twilio registration process.
from twilio.rest import TwilioRestClient
client = TwilioRestClient(account=’AC79******************************’, token=’d2b*****************************’)
client.messages.create(to=’+4478********’, from_=’+4412********’, body=”Hello, World!”)
In a worthwhile script you’d probably want to include logic in it that queried the system parameters that were of interest to you. It would then compose the content of the text body into something valuable. But even a simple script like this with a single, unchanging message could be used as a sort of system heartbeat check if it was inserted into a scheduled Cron job.
So, to recap. Register with Twilio. Get your account details. Install Twilio. Enter your details into the above script, and save it as (say) send_text.py.
invoke it as follows
And you should receive a text on your mobile.
One Pi is running the standard Raspbian Wheezy Debian image with a large externally powered USB drive connected to it. This forms the NAS storage device. It has some Samba SMB shares set up on it. This means the shares are acessible from other computers on the same network. I can therefore back up to the USB drive on the NAS Pi and transfer media files to it.
There are any number of tutorials on the web on how to do all of this, so I’m not going to rehash what has already been done elsewhere. But, because the XBMC Pi is connected to a wireless dongle (both systems are running headless, and I ssh onto them) I had to track down a few CLI networking commands to help me sort all of this out. I had a feeling that they might prove useful to others.
Of course, everyone knows about ifconfig. This enumerates the network interfaces and prints out a set of useful information about each one.
Another similar command is iwconfig. This concentrates on the wireless network interfaces and provides a different set of information.
To find your IP address quickly use ip addr.
Another useful command to have up your sleeve is findsmb. This enumerates Samba shares on your network. The screenshot below was taken from my laptop in a public library, so there is not much information displayed in it. More details of this command can be found at the Samba.org website. It also shows example output.