Page 1 of 1

Set static IP or wifi by Web Interface??

Posted: Sat Jul 15, 2017 3:14 pm
by cscuilla
I often pre-program headless PI's and send them to friends and family as gifts. Examples being: baby monitors, thermostats, fish-feeders, sprinkler controls, etc.. They run Jessie Lite (no GUI)

I install a webserver to most of these PI's and provide a backend website (php, mysql, mariadb) for the end-user to login and to make changes to certain settings, etc.

The biggest issue I run into is with the static IP. I know how to set static IPs, but the end-users are non-technical, and so I am wondering if their would be any way to program the PI so that the end user could set the static IP via the backend website.

My thoughts on the user getting the original IP is as follows:
1. I could install a small LCD display and push-button to the device. When they push the button, the current IP (dhcpd) is shown.
or..
2. I could set a script w/ a pre-programmed email or cell phone number which would send out the IP to that number/email on first boot. EX: If for my uncle, I would set his email in their before sending it, then it would email him the IP from his network when he boots it up.

They could then login to that IP and change to static IP, and possibly configure their wifi settings as well.

Is any of this possible? I'm open to any and all suggestions. Thanks for your time.

Re: Set static IP or wifi by Web Interface??

Posted: Sat Jul 15, 2017 6:55 pm
by cscuilla
UPDATE:
I found some commands I could use in a python script to change the IP, but the pi seems to keep the old IP (from dhcp) as well.

Code: Select all

os.system("sudo ifconfig eth0 down")
os.system("sudo ifconfig eth0 [i](Get IP From DB)[/i]")
os.system("sudo ifconfig eth0 up")
Any ideas why?

Re: Set static IP or wifi by Web Interface??

Posted: Sat Jul 15, 2017 11:10 pm
by pcmanbob
cscuilla wrote: My thoughts on the user getting the original IP is as follows:
1. I could install a small LCD display and push-button to the device. When they push the button, the current IP (dhcpd) is shown.
or..
2. I could set a script w/ a pre-programmed email or cell phone number which would send out the IP to that number/email on first boot. EX: If for my uncle, I would set his email in their before sending it, then it would email him the IP from his network when he boots it up.
Hi.

Both of your options are possible I have used both myself.
using the switch and a 20x4 LCD ( bigger display used for other parts of project ) I used RPLCD to control the lcd and netfaces to get the IP and a python program to wait from switch press and then get IP and display it.
for the email option I used ssmtp and mailutils to send mails using a bash script which ran 60 seconds after boot to allow for network to be come available. I set up a google account just for the pi, the only problem I encounter was that some times but not always google would block the sending of mail from a new location , but if you logged in to the email account from your browse and confirmed the new location next time it works ok.

If you want help with either option let me know.
links
https://pypi.python.org/pypi/netifaces/
https://pypi.python.org/pypi/RPLCD/0.4.0
http://www.raspberry-projects.com/pi/so ... end-emails