setup of wifi only rpi

User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

setup of wifi only rpi

Post by kw123 »

would it be of interest to have an SSD image that:

after initial start and no ethernet available, the RPI would start as a Wifi router with SID =piBeaconWIFI, passwd 12345 and would launch a very simple web server where you could enter ONLY your home wifi sid/pwd. --On your laptop connect to wifi piBeaconWiFi and http to 192.1.1.1
After entering, it would reboot with your home SID/pwd wifi as a regular wifi client.

That would bypass the need to attach a terminal go to the full rpi interface and setup wifi there.

Just an idea, anyone interested

Karl
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: setup of wifi only rpi

Post by kw123 »

here the little web server

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# by Karl Wachs
# jan 6 2019
# version 0.5 
#
# start webserver waiting for SID and passcode entry 
# write to WIFIsid when ssid and passCode are !=""
# will accept special char '";&8^ etc "
##
from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer

import sys
import urllib2
import time
import os
import json

class GetHandler(BaseHTTPRequestHandler):

	 def do_HEAD(self):
		self.send_response(200)
		self.send_header("Content-type", "text/html")
		self.end_headers()
 
	 def do_GET(self):
		values = self.path.split("?")
		if len(values) == 2:
			values = values[1].split("&")
			if len(values) ==2:
				wifi= {"ssid":"","passCode":""}
				for v in values:
					items = v.split("=")
					if len(items) ==2:
						if items[0]=="SSID": 	 wifi["ssid"]	  = urllib2.unquote(items[1])
						if items[0]=="passCode": wifi["passCode"] = urllib2.unquote(items[1])

				if wifi["ssid"] !="" and wifi["passCode"] !="":
					f=open("WIFIssid","w")
					f.write(json.dumps(wifi))
					f.close()
					print " got data", json.dumps(wifi)
					time.sleep(0.1)
					## now kill myself
					os.system("sudo kill -9 "+str(os.getpid()))

		self.send_response(200)
		self.send_header("Content-type", "text/html")
		self.end_headers()
		self.wfile.write("<html>")
		self.wfile.write(	"<head>")
		self.wfile.write(		"<title>ENTER SID and passcode for your wifi</title>")
		self.wfile.write(	"</head>")
		self.wfile.write(	"<body>")
		self.wfile.write(		'<form action = "/cgi-bin/hello_get.cgi" method = "get">'+
									'SSID:      <input type = "text" name = "SSID"      value = "" maxlength = "30" /> <br />'+
									'passCode:  <input type = "text" name = "passCode"  value = "" maxlength = "30" />'+
									'<input type = "submit" value = "Submit" />'+
								'</form>')
		self.wfile.write(	"</body>")
		self.wfile.write("</html>")
 

os.system("sudo rm WIFIsid")

server = HTTPServer(('', 8000), GetHandler)
try: server.serve_forever()
except: 
	server.server_close()
and here how the http page would look like
Screen Shot 2019-01-06 at 22.54.14.png
Screen Shot 2019-01-06 at 22.54.14.png (15.71 KiB) Viewed 1651 times
then master.py would grab that info and would compose the proper supplicant file and put into place and reboot. .. and then the RPI would connect to the home internet through wifi
Post Reply

Return to “piBeacon”