Skip to content

Commit e72c164

Browse files
authored
Python3 and Debian Buster compatible
This allows the plugin to run on both the old and the newer BeamOS images.
2 parents 971ea9c + 355f2eb commit e72c164

File tree

9 files changed

+669
-438
lines changed

9 files changed

+669
-438
lines changed

octoprint_netconnectd/__init__.py

Lines changed: 352 additions & 281 deletions
Large diffs are not rendered by default.

octoprint_netconnectd/analytics.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
21
class Analytics:
3-
ANALYTICS_DATA = 'MrbAnalyticsData'
4-
EVENT_WIFI_CONFIG = 'wifi_config'
5-
EVENT_WIFI_REFRESH = 'wifi_refresh'
2+
ANALYTICS_DATA = "MrbAnalyticsData"
3+
EVENT_WIFI_CONFIG = "wifi_config"
4+
EVENT_WIFI_REFRESH = "wifi_refresh"
65

76
def __init__(self, plugin):
87
self._plugin = plugin
@@ -17,12 +16,10 @@ def write_wifi_config_command(self, command, success, err=None):
1716
)
1817
self._send_op_event(eventname=self.EVENT_WIFI_CONFIG, data=data)
1918
except:
20-
self._logger.exception("Exception while writing wifi config command to analytics.")
19+
self._logger.exception(
20+
"Exception while writing wifi config command to analytics."
21+
)
2122

2223
def _send_op_event(self, eventname, data):
23-
payload = dict(
24-
plugin='netconnectd',
25-
eventname=eventname,
26-
data=data
27-
)
24+
payload = dict(plugin="netconnectd", eventname=eventname, data=data)
2825
self._plugin._event_bus.fire(self.ANALYTICS_DATA, payload)

octoprint_netconnectd/static/css/netconnectd.css

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,49 @@ table th.settings_plugin_netconnectd_wifis_action a.disabled, table td.settings_
2828
width: 198px;
2929
float: right;
3030
margin: 0 8px 6px 0;
31-
}
31+
}
32+
33+
/*Signal Bars*/
34+
* {
35+
box-sizing: border-box;
36+
}
37+
.sizing-box {
38+
height: 20px;
39+
width: 30px;
40+
float: right;
41+
}
42+
.signal-bars {
43+
/*display: inline-block;*/
44+
}
45+
.signal-bars .bar {
46+
width: 14%;
47+
margin-left: 1%;
48+
min-height: 20%;
49+
display: inline-block;
50+
border: rgba(0, 0, 0, 0.4);
51+
background-color: rgba(0, 0, 0, 0.4);
52+
}
53+
.signal-bars .bar.first-bar {
54+
height: 20%;
55+
}
56+
.signal-bars .bar.second-bar {
57+
height: 40%;
58+
}
59+
.signal-bars .bar.third-bar {
60+
height: 60%;
61+
}
62+
.signal-bars .bar.fourth-bar {
63+
height: 80%;
64+
}
65+
.signal-bars .bar.fifth-bar {
66+
height: 99%;
67+
}
68+
.four-bars .bar.fifth-bar,
69+
.three-bars .bar.fifth-bar,
70+
.three-bars .bar.fourth-bar,
71+
.one-bar .bar:not(.first-bar),
72+
.two-bars .bar:not(.first-bar):not(.second-bar) {
73+
background-color: #fafafa;
74+
border: thin solid #f3f3f3;
75+
}
76+
/*Signal Bars*/

octoprint_netconnectd/static/js/netconnectd.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ $(function() {
1919

2020
self.hostname = ko.observable(undefined);
2121
self.forwardUrl = ko.observable(undefined);
22+
self.countries = ko.observableArray([]);
23+
self.country = ko.observable(undefined);
2224

2325
self.status = {
2426
link: ko.observable(),
@@ -138,6 +140,13 @@ $(function() {
138140
"wifis",
139141
{
140142
"ssid": function (a, b) {
143+
// hidden SSIDs always go at the end, sorted by MAC
144+
if (!a["ssid"] && b["ssid"]) return 1;
145+
if (!b["ssid"] && a["ssid"]) return -1;
146+
if (!a["ssid"] && !b["ssid"]) {
147+
if (a["address"] < b["address"]) return -1;
148+
if (a["address"] > b["address"]) return 1;
149+
}
141150
// sorts ascending
142151
if (a["ssid"].toLocaleLowerCase() < b["ssid"].toLocaleLowerCase()) return -1;
143152
if (a["ssid"].toLocaleLowerCase() > b["ssid"].toLocaleLowerCase()) return 1;
@@ -230,6 +239,9 @@ $(function() {
230239
self.requestData();
231240
}, 30000)
232241
}
242+
243+
self.countries(response.countries)
244+
self.country(response.country)
233245
};
234246

235247
self.configureWifi = function(data) {
@@ -287,6 +299,11 @@ $(function() {
287299

288300
self.sendStartAp = function() {
289301
if (!self.canRun()) return;
302+
new PNotify({
303+
title: gettext("Access point"),
304+
text: _.sprintf(gettext("Mr Beam is now starting the access point. The connection may be interrupted before the access point is available.")),
305+
type: "info"
306+
});
290307
self._postCommand("start_ap", {});
291308
};
292309

@@ -337,6 +354,15 @@ $(function() {
337354
}, 80000);
338355
};
339356

357+
self.selectedValueChanged = function(context) {
358+
if (!self.canRun()) return;
359+
360+
country = context.country();
361+
if (country) {
362+
self._postCommand("set_country", {country: country});
363+
}
364+
};
365+
340366
self.sendReset = function() {
341367
if (!self.canRun()) return;
342368

@@ -408,13 +434,10 @@ $(function() {
408434
self.pollingTimeoutId = undefined;
409435
}
410436

411-
$.ajax({
412-
url: API_BASEURL + "plugin/netconnectd",
413-
// url: self.isWizardActive ? "/plugin/mrbeam/wifi" : API_BASEURL + "plugin/netconnectd",
414-
type: "GET",
415-
dataType: "json",
416-
success: self.fromResponse
417-
});
437+
OctoPrint.simpleApiGet("netconnectd")
438+
.done(function(response) {
439+
self.fromResponse(response);
440+
});
418441
};
419442

420443
self.onUserLoggedIn = function(user) {
@@ -458,8 +481,20 @@ $(function() {
458481
return res;
459482
}
460483

484+
self.signalQuality = function (quality){
485+
if(quality >= 60){
486+
return 'four-bars';
487+
}else if(quality >= 40){
488+
return 'three-bars'
489+
}else if(quality >= 20){
490+
return 'two-bars'
491+
}else{
492+
return 'one-bar'
493+
}
494+
}
495+
461496
}
462497

463498
// view model class, parameters for constructor, container to bind to
464499
ADDITIONAL_VIEWMODELS.push([NetconnectdViewModel, ["loginStateViewModel", "settingsViewModel"], "#settings_plugin_netconnectd"]);
465-
});
500+
});
Lines changed: 86 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<div id="settings_plugin_netconnectd_dialog" data-bind="allowBindings: true" class="scrollable" style="padding-bottom:2em; overflow-y: auto; height: calc(100vh - 100px);">
1+
<div id="settings_plugin_netconnectd_dialog" data-bind="allowBindings: true" class="scrollable"
2+
style="padding-bottom:2em; overflow-y: auto; height: calc(100vh - 100px);">
23
<h3>{{ _('Network Connection') }}</h3>
34

45
<p>
@@ -9,25 +10,46 @@
910
</p>
1011
<div class="pull-right" data-bind="visible: enableQualitySorting">
1112
<small>
12-
{{ _('Sort by') }}: <a href="#" data-bind="click: function() { listHelper.changeSorting('ssid'); }">{{ _('SSID') }} ({{ _('ascending') }})</a> | <a href="#" data-bind="click: function() { listHelper.changeSorting('quality'); }">{{ _('Quality') }} ({{ _('descending') }})</a>
13+
{{ _('Sort by') }}: <a href="#"
14+
data-bind="click: function() { listHelper.changeSorting('ssid'); }">{{ _('SSID') }}
15+
({{ _('ascending') }})</a> | <a href="#"
16+
data-bind="click: function() { listHelper.changeSorting('quality'); }">{{ _('Quality') }}
17+
({{ _('descending') }})</a>
1318
</small>
1419
</div>
1520
<table class="table table-striped table-hover table-condensed table-hover" id="settings_plugin_netconnectd_wifis">
1621
<thead>
1722
<tr>
1823
<th class="settings_plugin_netconnectd_wifis_ssid">{{ _('SSID') }}</th>
19-
<th class="settings_plugin_netconnectd_wifis_quality" data-bind="visible: enableQualitySorting">{{ _('Quality') }}</th>
24+
<th class="settings_plugin_netconnectd_wifis_quality"
25+
data-bind="visible: enableQualitySorting">{{ _('Quality') }}</th>
2026
<th class="settings_plugin_netconnectd_wifis_action">{{ _('Action') }}</th>
2127
</tr>
2228
</thead>
2329
<tbody data-bind="foreach: listHelper.paginatedItems">
24-
<tr data-bind="attr: {title: name}">
25-
<td class="settings_plugin_netconnectd_wifis_ssid"><span class="icon-lock" data-bind="invisible: !encrypted"></span> <span data-bind="text: ssid"></span> <small class="muted">({{ _('Address') }}: <span data-bind="text: address"></span>)</small></td>
26-
<td class="settings_plugin_netconnectd_wifis_quality" data-bind="visible: $root.enableQualitySorting, text: qualityText"></td>
27-
<td class="settings_plugin_netconnectd_wifis_action">
28-
<button class="btn btn-small" data-bind="click: function() { $parent.configureWifi($data); }, css: {disabled: !$root.loginState.isUser() || $root.working() || $root.error() || $root.getEntryId($data) == $root.statusCurrentWifi()}"><i class="icon-spinner icon-spin" data-bind="visible: $root.working"></i><i class="icon-signin" data-bind="visible: !$root.working()"></i> {{ _('Connect') }}</button>
29-
</td>
30-
</tr>
30+
<tr data-bind="attr: {title: name}">
31+
<td class="settings_plugin_netconnectd_wifis_ssid"><span class="icon-lock"
32+
data-bind="invisible: !encrypted"></span> <span
33+
data-bind="text: ssid"></span> <small class="muted">({{ _('Address') }}: <span
34+
data-bind="text: address"></span>)</small></td>
35+
<td class="settings_plugin_netconnectd_wifis_quality"
36+
data-bind="visible: $root.enableQualitySorting">
37+
<div data-bind="css: $root.signalQuality(quality)" class="signal-bars mt1 sizing-box">
38+
<div class="first-bar bar"></div>
39+
<div class="second-bar bar"></div>
40+
<div class="third-bar bar"></div>
41+
<div class="fourth-bar bar"></div>
42+
<div class="fifth-bar bar"></div>
43+
</div>
44+
</td>
45+
<td class="settings_plugin_netconnectd_wifis_action">
46+
<button class="btn btn-small"
47+
data-bind="click: function() { $parent.configureWifi($data); }, css: {disabled: !$root.loginState.isUser() || $root.working() || $root.error() || $root.getEntryId($data) == $root.statusCurrentWifi()}">
48+
<i class="icon-spinner icon-spin" data-bind="visible: $root.working"></i><i class="icon-signin"
49+
data-bind="visible: !$root.working()"></i> {{ _('Connect') }}
50+
</button>
51+
</td>
52+
</tr>
3153
</tbody>
3254
</table>
3355
<div class="pagination pagination-mini pagination-centered">
@@ -38,7 +60,8 @@
3860
</ul>
3961
<ul data-bind="foreach: listHelper.pages">
4062
<li data-bind="css: { active: $data.number === $root.listHelper.currentPage(), disabled: $data.number === -1 }">
41-
<a href="#" data-bind="text: $data.text, click: function() { $root.listHelper.changePage($data.number); }"></a>
63+
<a href="#"
64+
data-bind="text: $data.text, click: function() { $root.listHelper.changePage($data.number); }"></a>
4265
</li>
4366
</ul>
4467
<ul>
@@ -48,17 +71,42 @@
4871
</ul>
4972
</div>
5073

51-
<button class="btn btn-primary btn-block" data-bind="click: function() { $root.refresh() }, enable: $root.daemonOnline() && $root.status.wifi.present()">{{ _('Refresh') }}</button>
74+
<button class="btn btn-primary btn-block"
75+
data-bind="click: function() { $root.refresh() }, enable: $root.daemonOnline() && $root.status.wifi.present()">{{ _('Refresh') }}</button>
5276

5377
<div>
54-
<small class="muted">{{ _('netconnectd socket') }}: <span data-bind="text: settings.plugins.netconnectd.socket"></span></small>
78+
<small class="muted">{{ _('netconnectd socket') }}: <span
79+
data-bind="text: settings.plugins.netconnectd.socket"></span></small>
5580
</div>
5681

5782
<div>
58-
<div><small><a href="#" class="muted" onclick="$(this).children().toggleClass('icon-caret-right icon-caret-down').parent().parent().parent().next().slideToggle('fast')"><i class="icon-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
59-
<div class="hide row-fluid">
60-
<button class="btn span6" data-bind="click: function() { if ($root.apRunning()) { $root.sendStopAp(); } else { $root.sendStartAp(); } }, enable: $root.daemonOnline()"><span data-bind="visible: !$root.apRunning() && $root.daemonOnline()">{{ _('Start AP') }}</span><span data-bind="visible: $root.apRunning() && $root.daemonOnline()">{{ _('Stop AP') }}</span><span data-bind="visible: !$root.daemonOnline()">{{ _('Daemon offline') }}</span></button>
61-
<button class="btn span6" data-bind="click: function() { $root.sendReset() }, enable: $root.daemonOnline()">{{ _('Reset daemon') }}</button>
83+
<div><small><a href="#" class="muted"
84+
onclick="$(this).children().toggleClass('icon-caret-right icon-caret-down').parent().parent().parent().next().slideToggle('fast')"><i
85+
class="icon-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
86+
<div class="hide">
87+
<div class="row-fluid" data-bind="visible: $root.countries().length != 0">
88+
<div class="control-group">
89+
<label class="control-labelt"><strong>Country</strong></label>
90+
<div class="controls">
91+
<select data-bind="options: countries,
92+
optionsText: 'country',
93+
optionsValue: 'code',
94+
optionsCaption: 'Select Country...',
95+
value: country,
96+
event: {change: selectedValueChanged}">
97+
</select>
98+
</div>
99+
</div>
100+
</div>
101+
<div class="row-fluid">
102+
<button class="btn span6"
103+
data-bind="click: function() { if ($root.apRunning()) { $root.sendStopAp(); } else { $root.sendStartAp(); } }, enable: $root.daemonOnline()">
104+
<span data-bind="visible: !$root.apRunning() && $root.daemonOnline()">{{ _('Start AP') }}</span><span
105+
data-bind="visible: $root.apRunning() && $root.daemonOnline()">{{ _('Stop AP') }}</span><span
106+
data-bind="visible: !$root.daemonOnline()">{{ _('Daemon offline') }}</span></button>
107+
<button class="btn span6"
108+
data-bind="click: function() { $root.sendReset() }, enable: $root.daemonOnline()">{{ _('Reset daemon') }}</button>
109+
</div>
62110
</div>
63111
</div>
64112

@@ -69,24 +117,36 @@
69117
</div>
70118
<div class="modal-body">
71119
<form class="form-horizontal">
72-
<div class="control-group" data-bind="css: {success: $root.editorWifiPassphrase2() && !$root.editorWifiPassphraseMismatch()}">
73-
<label class="control-label" for="settings_plugin_netconnectd_wificonfig_passphrase1">{{ _('Password') }}</label>
120+
<div class="control-group"
121+
data-bind="css: {success: $root.editorWifiPassphrase2() && !$root.editorWifiPassphraseMismatch()}">
122+
<label class="control-label"
123+
for="settings_plugin_netconnectd_wificonfig_passphrase1">{{ _('Password') }}</label>
74124
<div class="controls">
75-
<input type="password" class="input-block-level" id="settings_plugin_netconnectd_wificonfig_passphrase1" data-bind="value: $root.editorWifiPassphrase1, valueUpdate: 'input'" required>
125+
<input type="password" class="input-block-level"
126+
id="settings_plugin_netconnectd_wificonfig_passphrase1"
127+
data-bind="value: $root.editorWifiPassphrase1, valueUpdate: 'input'" required>
76128
</div>
77129
</div>
78-
<div class="control-group" data-bind="css: {success: $root.editorWifiPassphrase2() && !$root.editorWifiPassphraseMismatch(), error: $root.editorWifiPassphrase2() && $root.editorWifiPassphraseMismatch()}">
79-
<label class="control-label" for="settings_plugin_netconnectd_wificonfig_passphrase2">{{ _('Repeat Password') }}</label>
130+
<div class="control-group"
131+
data-bind="css: {success: $root.editorWifiPassphrase2() && !$root.editorWifiPassphraseMismatch(), error: $root.editorWifiPassphrase2() && $root.editorWifiPassphraseMismatch()}">
132+
<label class="control-label"
133+
for="settings_plugin_netconnectd_wificonfig_passphrase2">{{ _('Repeat Password') }}</label>
80134
<div class="controls">
81-
<input type="password" class="input-block-level" id="settings_plugin_netconnectd_wificonfig_passphrase2" data-bind="value: $root.editorWifiPassphrase2, valueUpdate: 'input'" required>
82-
<span class="help-inline" data-bind="visible: $root.editorWifiPassphrase2() && $root.editorWifiPassphraseMismatch()">{{ _('Passwords do not match') }}</span>
135+
<input type="password" class="input-block-level"
136+
id="settings_plugin_netconnectd_wificonfig_passphrase2"
137+
data-bind="value: $root.editorWifiPassphrase2, valueUpdate: 'input'" required>
138+
<span class="help-inline"
139+
data-bind="visible: $root.editorWifiPassphrase2() && $root.editorWifiPassphraseMismatch()">{{ _('Passwords do not match') }}</span>
83140
</div>
84141
</div>
85142
</form>
86143
</div>
87144
<div class="modal-footer">
88-
<button class="btn" data-dismiss="modal" data-bind="enable: !$root.working() && !$root.error()" aria-hidden="true">{{ _('Abort') }}</button>
89-
<button class="btn btn-primary" data-bind="click: function() { $root.confirmWifiConfiguration(); }, enable: !$root.editorWifiPassphraseMismatch() && !$root.working() && !$root.error()"><i class="icon-spinner icon-spin" data-bind="visible: working"></i> {{ _('Confirm') }}</button>
145+
<button class="btn" data-dismiss="modal" data-bind="enable: !$root.working() && !$root.error()"
146+
aria-hidden="true">{{ _('Abort') }}</button>
147+
<button class="btn btn-primary"
148+
data-bind="click: function() { $root.confirmWifiConfiguration(); }, enable: !$root.editorWifiPassphraseMismatch() && !$root.working() && !$root.error()">
149+
<i class="icon-spinner icon-spin" data-bind="visible: working"></i> {{ _('Confirm') }}</button>
90150
</div>
91151
</div>
92152
</div>
290 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)