Skip to content

Commit e22fcf0

Browse files
committed
added a local_client wifi mode2
1 parent a2a5e12 commit e22fcf0

File tree

5 files changed

+63
-10
lines changed

5 files changed

+63
-10
lines changed

coderbot.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"move_tr_speed": "75", "move_fw_elapse": "1.5", "arm_angle_raised": "120", "load_at_start": "", "move_tr_elapse": "90", "show_page_program": "true", "sound_stop": "$shutdown.mp3", "camera_exposure_mode": "auto", "prog_move_motion": "yes", "show_control_move_commands": "true", "prog_level": "adv", "prog_scrollbars": "true", "ctrl_counter": "yes", "sound_start": "$startup.mp3", "camera_rotation": "180", "ctrl_fw_speed": "100", "move_fw_speed": "100", "show_page_control": "true", "sound_shutter": "$shutter.mp3", "show_page_prefs": "true", "arm_angle_lowered": "60", "prog_maxblocks": "-1", "ctrl_hud_image": "", "button_func": "none", "move_motor_mode": "servo", "ctrl_fw_elapse": "-1", "ctrl_tr_elapse": "-1", "move_power_angle_2": "20", "move_power_angle_3": "20", "ctrl_tr_speed": "80", "move_power_angle_1": "15"}
1+
{"move_tr_speed": "75", "move_fw_elapse": "1.5", "arm_angle_raised": "120", "load_at_start": "", "move_tr_elapse": "90", "show_page_program": "true", "sound_stop": "$shutdown.mp3", "camera_exposure_mode": "fixedfps", "prog_move_motion": "yes", "show_control_move_commands": "true", "prog_level": "adv", "prog_scrollbars": "true", "ctrl_counter": "yes", "sound_start": "$startup.mp3", "camera_rotation": "180", "ctrl_fw_speed": "100", "move_fw_speed": "100", "show_page_control": "true", "sound_shutter": "$shutter.mp3", "show_page_prefs": "true", "arm_angle_lowered": "60", "prog_maxblocks": "-1", "ctrl_hud_image": "", "button_func": "none", "move_motor_mode": "servo", "ctrl_fw_elapse": "-1", "ctrl_tr_elapse": "-1", "move_power_angle_2": "20", "move_power_angle_3": "20", "ctrl_tr_speed": "80", "move_power_angle_1": "15"}

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def handle_wifi():
6262
logging.info(client_params)
6363
os.system("sudo python wifi.py updatecfg " + mode + client_params)
6464
if mode == "ap":
65-
return "http://coder.bot:8080/";
66-
else:
65+
return "http://coder.bot:8080/"
66+
elif mode == "client":
6767
return "http://coderbotsrv.appspot.com/"
6868

6969
@app.route("/bot", methods=["GET"])

static/js/control.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ $(document).on( "pagecreate", '#page-preferences', function( event ) {
114114
$('#popup-wifi').popup('close');
115115
if($("[name='wifi_mode']:checked").val()=="ap"){
116116
$('#popup-wifi-ap').popup('open');
117-
} else {
117+
} else if ($("[name='wifi_mode']:checked").val()=="client") {
118118
$('#popup-wifi-client').popup('open');
119+
} else if ($("[name=wifi_mode']:checked").val()=="local_client") {
120+
$('#popup-wifi-local-client').popup('open');
119121
}
120122
return false;
121123
});

templates/config.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ <h3>{% trans %}WiFi Client mode access data{% endtrans %}</h3>
171171
<label for="r_wifi_mode_a">{% trans %}Access Point{% endtrans %}</label>
172172
<input type="radio" name="wifi_mode" id="r_wifi_mode_b" value="client" {%if config.wifi_mode=='client'%}checked="checked"{%endif%}>
173173
<label for="r_wifi_mode_b">{% trans %}Client{% endtrans %}</label>
174+
<input type="radio" name ="wifi_mode" id="r_wifi_mode_c" value="local_client" {%if config.wifi_mode=='local_client'%}checked="checked"{%endif%}>
175+
<label for="r_wifi_mode_c">Local Client</label>
174176
</fieldset>
175177
<label for="i_wifi_ssid">{% trans %}WiFi name{% endtrans %}</label>
176178
<input type="text" id="i_wifi_ssid" name="wifi_ssid" value="{{config.wifi_ssid}}">
@@ -208,4 +210,15 @@ <h3>{% trans %}WiFi Client mode access{% endtrans %}</h3>
208210
</div>
209211
</div>
210212
</div>
213+
<div data-role="popup" id="popup-wifi-local-client" data-history="false" data-theme="a" class="ui-corner-all" data-dismissible="false" data-position-to "window">
214+
<div style="padding:10px 20px;">
215+
<h3> WiFi Local Client mode access</h3>
216+
<p>Client mode is being set:
217+
<ol>
218+
<li>Wait 30 seconds</li>
219+
<li>Connect your device to your own wifi</li>
220+
<li>Click on the following link: <a href="http://192.168.0.1:8080">Local Coderbot Hub</a></li>
221+
</ol>
222+
</div>
223+
</div>
211224

wifi.py

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class WiFi():
1414

1515
CONFIG_FILE = "/etc/coderbot_wifi.conf"
16-
adapters = ["RT5370", "RTL8188CUS"]
16+
adapters = ["RT5370", "RTL8188CUS", "RT3572"]
1717
hostapds = {"RT5370": "hostapd.RT5370", "RTL8188CUS": "hostapd.RTL8188"}
1818
web_url = "http://coderbotsrv.appspot.com/register_ip"
1919
wifi_client_conf_file = "/etc/wpa_supplicant/wpa_supplicant.conf"
@@ -45,13 +45,13 @@ def get_adapter_type(cls):
4545

4646
@classmethod
4747
def start_hostapd(cls):
48-
adapter = cls.get_adapter_type()
49-
hostapd_type = cls.hostapds.get(adapter)
48+
#adapter = cls.get_adapter_type()
49+
#hostapd_type = cls.hostapds.get(adapter)
5050
try:
5151
print "starting hostapd..."
5252
#os.system("start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/" + hostapd_type + " -- /etc/hostapd/" + hostapd_type + " &")
53-
os.system("/usr/sbin/" + hostapd_type + " /etc/hostapd/" + hostapd_type + " -B")
54-
53+
#os.system("/usr/sbin/" + hostapd_type + " /etc/hostapd/" + hostapd_type + " -B")
54+
out = subprocess.check_output(["service", "hostapd", "start"])
5555
except subprocess.CalledProcessError as e:
5656
print e.output
5757

@@ -100,12 +100,14 @@ def set_client_params(cls, wssid, wpsk):
100100
f.write(" psk=\""+wpsk+"\"\n")
101101
f.write("}")
102102

103+
# set WIFI client mode
103104
@classmethod
104105
def set_start_as_client(cls):
105106
shutil.copy("/etc/network/interfaces_cli", "/etc/network/interfaces")
106107
cls._config["wifi_mode"] = "client"
107108
cls.save_config()
108109

110+
# start as client to coderbot server
109111
@classmethod
110112
def start_as_client(cls):
111113
cls.stop_hostapd()
@@ -118,6 +120,25 @@ def start_as_client(cls):
118120
print e.output
119121
raise
120122

123+
# set WIFI client mode and record as "local_client"
124+
@classmethod
125+
def set_start_as_local_client(cls):
126+
shutil.copy("/etc/network/interfaces_cli", "/etc/network/interfaces")
127+
cls._config["wifi_mode"] = "local_client"
128+
cls.save_config()
129+
130+
# start as client without registering to coderbot server
131+
@classmethod
132+
def start_as_local_client(cls):
133+
cls.stop_hostapd()
134+
try:
135+
out = subprocess.check_output(["ifdown", "wlan0"])
136+
out = subprocess.check_output(["ifup", "wlan0"])
137+
except:
138+
print e.output
139+
raise
140+
141+
121142
@classmethod
122143
def set_start_as_ap(cls):
123144
shutil.copy("/etc/network/interfaces_ap", "/etc/network/interfaces")
@@ -139,9 +160,16 @@ def start_service(cls):
139160
elif config["wifi_mode"] == "client":
140161
print "starting as client..."
141162
try:
142-
cls.start_as_client()
163+
cls.start_as_start_as_local_clientclient()
143164
except:
144165
print "Unable to register ip, revert to ap mode"
166+
cls.start_as_astart_as_local_clientp()
167+
elif config["wifi_mode"] == "local_client":
168+
print "starting as local client..."
169+
try:
170+
cls.start_as_local_client()
171+
except:
172+
print "Unable to connect to WLAN, rever to ap mode"
145173
cls.start_as_ap()
146174

147175
def main():
@@ -160,6 +188,16 @@ def main():
160188
except:
161189
print "Unable to register ip, revert to ap mode"
162190
w.start_as_ap()
191+
elif len(sys.argv) > 2 and sys.argv[2] == "local_client":
192+
if len(sys.argv) > 3:
193+
w.set_client_params(sys.argv[3], sys.argv[4])
194+
w.set_start_as_client()
195+
try:
196+
w.start_as_local_client()
197+
except:
198+
print "Unable to connect to WLAN, revert to ap mode"
199+
w.start_as_ap()
200+
163201
else:
164202
w.start_service()
165203

0 commit comments

Comments
 (0)