February 24 2017 - Playing with Raspberry Pi

I bought Raspberry Pi a while ago so I played with it.

Raspberry Pi is a small computer and can be used with an OS in SD card. It has I/O pins which I can attach electric parts. In fact, I wanted to install a Wi-Fi and a camera into Arduino and grade up RC. But I can’t install other parts after installed two motors and Bluetooth so I will try Raspberry Pi which has Wi-Fi and camera I/F.

I bought Raspberry Pi and SD card, connect it to HDMI display, connected USB mouse and keyboard. I installed Raspbian (Default Linux) to SD card using PC, then ready. Launching Raspberry Pi and installed OS. After changing password, configured Wi-Fi, finally I was able to login to it with SSH from PC.

I have a problem here. When I use it, IP address will be changed because of DHCP and it is hard to use. I don’t want to connect display and execute ifconfig. Because of that, I created a first program that notify IP address to web site when launched. It was my first Python program so I don’t know details.

# coding: utf-8
import urllib2
import subprocess

url = 'http://xxxxx/cgi-bin/xxxxx.cgi?ip='
cmd = "hostname -I"
ip = subprocess.check_output(cmd,shell=True)
urllib2.urlopen(url + ip)

When Raspberry Pi launched, it seems that pi user automatically logins, so I added following code in .bashrc.

python /home/pi/xxx.py &

In Web side, I created CGI but I can’t copy & paste here because it is link to large original library. It saves given IP address and output latest IP address to standard output.

Now I don’t need display, mouse and keyboard. Super convenient.

Leave a Comment