Wednesday, 21 August 2013

Send IP info on boot up.

Send a SMS with your internal and External IP for your Raspberry PI

First Grab a Text Local account from 

//  Pi - SMS - What is my IP bro?!
//  By Robert Wiggins
// Paypal Donate and let me get a Raspi-Cam!

// get the local hosts ip address
$ip = str_replace("\n","",shell_exec("ifconfig eth0 | grep 'inet addr' | awk -F':' {'print $2'} | awk -F' ' {'print $1'}"));

// External IP
$externalContent = file_get_contents('');

// Configuration variables
$info = "1";
$test = "0";

// Data for text message
$uname = '';
$pword = '';
$from = "Robbies PI";
$selectednums = "44";
$message = "You Pi Info LAN:".$ip." Ext: ".$externalContent." Raspberry Pi LCD";
$message = urlencode($message);

// Prepare data for POST request
$data = "uname=".$uname."&pword=".$pword."&message=".$message
."&from=". $from."&selectednums=".$selectednums."&info=".$info."&test=".$test;

// Send the POST request with cURL
$ch = curl_init(''); //note https for SSL
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); //This is the result from Textlocal

echo ('You Pi Info LAN: '.$ip.' Ext: '.$externalContent.' Raspberry Pi LCD');

Add A New Cron Job

To create a new job to Cron we will modify the “crontab”. This is a table that contains the list of jobs that Cron will monitor and run according to it’s details. To edit it we use the command :
sudo crontab -e
Each user of the system (ie “pi”) can have its own Crontab but in this case we want to add it as an admin so we prefix our “crontab -e” command with “sudo”. You should see something that looks like this :
Crontab Example - Python at Boot
Using your cursor keys scroll to the bottom and add the following line :
@reboot php /var/www/piboot.php &
This tells Cron that every boot (or reboot or start-up) we want to run PHP with the script piboot.php. The “&” at the end of the line means the command is run in the background and it won’t stop the system booting up as before.
Your screen should look something like this :
Crontab Example - Python at Boot
To save these changes click “CTRL-X”, then “Y” and finally “Return”. You should now be back at the command prompt.
To start testing you can now reboot using :
sudo reboot
The Cron Job part was taken from -


  1. Nice idea!

    I wrote a daemon to blink the OK LED on the Pi with the IP address -- works well, though it's a bit slow! It also writes the IP into a file in ~pi, so if you have another machine handy with a card reader you could have a peek and then reboot hoping that the IP stays the same. The code is here:

    We've also got some stuff about doing SMS notifications in various ways here -- -- comments welcome!

    My favourite solution is with PageKite, but I haven't written it up yet...


  2. Hi Hamish,

    All looks good there I'm going add a few bits myself i.e for twitter and for it to display the ip on my adafruits LCD.

    I found textlocal being great for support for sms

  3. cool -- what are the adafruit screens like? they look neat :-)

    I've written up the pagekite stuff now and linked this post -- and

    have a good one

  4. anyone tried with berryio? it sends the ipadd upon boot up. that means free and no need to subscribe for sms.

  5. the question is how do you know where the berryio webserver is running? i.e. which ip address it is on -- unless it is using a centralised proxying service like pagekite -- -- which is definitely a good solution :-)

    best, hamish

  6. this is free for ssh tunneling but cannot install at the moment
    for sending the ip add, from what I have experienced so far, it sends my local ip using msmtprc. so you just setup it using their script and you're ready to go...




Donate Towards More Raspberry PI's for Projects