Send a SMS with your internal and External IP for your Raspberry PI
First Grab a Text Local account from
- CODE: SELECT ALL
<?php
// Pi - SMS - What is my IP bro?!
// By Robert Wiggins
// txt3rob@gmail.com
// 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('http://www.icanhazip.com/');
// 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('https://www.txtlocal.com/sendsmspost.php'); //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
curl_close($ch);
//echo
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 :
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 :
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 -
http://www.raspberrypi-spy.co.uk/2013/07/running-a-python-script-at-boot-using-cron/