Skip to content

Commit f770923

Browse files
committed
wip #92
1 parent bcd9fbd commit f770923

File tree

5 files changed

+84
-47
lines changed

5 files changed

+84
-47
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Vite App</title>
7+
<title>CoderBot</title>
88
</head>
99
<body>
1010
<div id="app"></div>

src/common/coderbot.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class CoderBot {
187187

188188
async saveSettings(settings) {
189189
/* eslint-enable */
190-
const legacySettings = new URLSearchParams({
190+
const legacySettings = {
191191
ctrl_hud_image: settings.ctrl_hud_image,
192192
cv_image_factor: settings.cv_image_factor,
193193
camera_color_object_size_max: settings.camera_color_object_size_max,
@@ -224,10 +224,9 @@ class CoderBot {
224224
audio_volume_level: settings.audioLevel,
225225
admin_password: settings.adminPassword,
226226
hardware_version: settings.hardwareVersion,
227-
228-
});
227+
};
229228
this.$store.commit('setSettings', settings);
230-
return this.$axios.post(`${this.CB}/system/config`, legacySettings);
229+
return this.$axios.put(`${this.CB}/settings`, legacySettings);
231230
}
232231

233232
reboot() {
@@ -274,15 +273,6 @@ class CoderBot {
274273
});
275274
}
276275

277-
saveWifiParams(wifiMode, wifiSSID, wifiPsw) {
278-
const valuesAsString = new URLSearchParams({
279-
wifi_mode: wifiMode,
280-
wifi_ssid: wifiSSID,
281-
wifi_psk: wifiPsw,
282-
});
283-
return this.$axios.post(`${this.CB}/system/settings/wifi`, valuesAsString);
284-
}
285-
286276
updatePackages(formdata) {
287277
return this.$axios.post(`${this.CB}/updatePackages`, formdata);
288278
}

src/common/wifi_connect.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class WifiConnect {
2+
constructor(CB, axios) {
3+
this.CB = CB + '/wifi';
4+
this.$axios = axios;
5+
}
6+
7+
networks() {
8+
return this.$axios.get(`${this.CB}/networks`);
9+
}
10+
11+
connect(ssid, identity, passphrase) {
12+
return this.$axios.post(`${this.CB}/connect`, {
13+
ssid: ssid,
14+
identity: identity,
15+
passphrase: passphrase,
16+
});
17+
}
18+
19+
disconnect(ssid) {
20+
return this.$axios.post(`${this.CB}/disconnect`, {
21+
ssid: ssid,
22+
});
23+
}
24+
}
25+
26+
export default WifiConnect;

src/components/Settings.vue

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,26 @@
406406
<v-radio v-bind:label="$t('message.settings_network_mode_client')" value="client"></v-radio>
407407
<v-radio v-bind:label="$t('message.settings_network_mode_ap')" value="ap">
408408
</v-radio>
409-
<v-text-field v-model="settings.wifiSSID" v-bind:label="$t('message.settings_network_ssid')"></v-text-field>
410-
<v-text-field v-model="settings.wifiPsw" v-bind:label="$t('message.settings_network_password')"></v-text-field>
411409
</v-radio-group>
410+
<div v-if="settings.wifiMode=='client'">
411+
<v-select
412+
:disabled="settings.wifiMode!='client'"
413+
v-model="settings.wifiSSID"
414+
:items="networks"
415+
item-title="ssid"
416+
item-value="ssid"
417+
v-bind:label="$t('message.settings_network_ssid')"
418+
single-line
419+
>
420+
</v-select>
421+
<v-text-field
422+
:disabled="settings.wifiMode!='client'"
423+
v-model="settings.wifiPsw"
424+
:append-icon="wifi_pwd_show ? 'mdi-eye' : 'mdi-eye-off'"
425+
:type="wifi_pwd_show ? 'text' : 'password'"
426+
@click:append="wifi_pwd_show = !wifi_pwd_show"
427+
v-bind:label="$t('message.settings_network_password')"></v-text-field>
428+
</div>
412429
<!--v-card-actions>
413430
<v-btn color="primary" @click.stop="dialog = true" block>Salva</v-btn>
414431
<v-dialog v-model="dialog" max-width="290">
@@ -733,6 +750,18 @@ export default {
733750
setup() {
734751
return {
735752
v$: useVuelidate(),
753+
cameraExposureModes: [
754+
{ text: 'Auto', key: 'auto' },
755+
{ text: 'Sports', key: 'sports' },
756+
{ text: 'Night', key: 'night' },
757+
{ text: 'Fixed FPS', key: 'fixedfps' },
758+
{ text: 'Anti shake', key: 'antishake' },
759+
{ text: 'Very long', key: 'verylong' }
760+
],
761+
hardware_version_items: [
762+
{ key: '4', text: '4.0 (legacy)' },
763+
{ key: '5', text: '5.0 (latest)' }
764+
],
736765
};
737766
},
738767
mounted() {
@@ -747,6 +776,9 @@ export default {
747776
this.cb.info = this.$store.getters.info;
748777
this.cb.status = this.$store.getters.status;
749778
this.adminPassword_dialog = this.settings.adminPassword != null && this.settings.adminPassword != '';
779+
this.$wifi_connect.networks().then((result) => {
780+
this.networks = result.data;
781+
});
750782
},
751783
beforeRouteLeave(to, from, next) {
752784
if (this.v$.$anyDirty) {
@@ -781,7 +813,6 @@ export default {
781813
this.uploadCompleted = true;
782814
this.uploadInProgress = false;
783815
this.updateStatusText = this.$i18n.t('message.settings_music_packages_text_1');
784-
console.dir(result.data);
785816
if (this.updateStatus == 2) {
786817
this.updateStatusText = this.$i18n.t('message.settings_music_packages_text_2');
787818
}
@@ -803,7 +834,6 @@ export default {
803834
this.$$coderbot.updateFromPackage(this.formdata, config).then((result) => {
804835
this.uploadCompleted = true;
805836
this.uploadInProgress = false;
806-
console.dir(result.data);
807837
this.updateStatusText = this.$i18n.t('message.settings_packages_text_1');
808838
});
809839
},
@@ -910,7 +940,6 @@ export default {
910940
if (this.v$.$invalid) {
911941
this.snackText = this.$i18n.t('message.settings_errors');
912942
this.snackbar = true;
913-
console.log(this.v$);
914943
} else {
915944
/* eslint-disable func-names, object-shorthand, prefer-arrow-callback */
916945
const needRestart = this.needRestart();
@@ -930,25 +959,24 @@ export default {
930959
console.log('set dirty false');
931960
});
932961
if (this.v$.settings.wifiMode.$dirty || this.v$.settings.wifiSSID.$dirty || this.v$.settings.wifiPsw.$dirty) {
933-
this.$coderbot.saveWifiParams(this.settings.wifiMode, this.settings.wifiSSID, this.settings.wifiPsw)
934-
.then(() => {
935-
console.log('Sent');
936-
this.snackText = this.$i18n.t('message.settings_network_updated');
937-
this.snackbar = true;
938-
});
962+
if(this.settings.wifiMode=="client") {
963+
this.$wifi_connect.connect(this.settings.wifiSSID, "", this.settings.wifiPsw)
964+
.then(() => {
965+
console.log('connect Sent');
966+
this.snackText = this.$i18n.t('message.settings_network_updated');
967+
this.snackbar = true;
968+
});
969+
} else {
970+
this.$wifi_connect.disconnect(this.settings.wifiSSID)
971+
.then(() => {
972+
console.log('disconnect Sent');
973+
this.snackText = this.$i18n.t('message.settings_network_updated');
974+
this.snackbar = true;
975+
});
976+
}
939977
}
940978
}
941979
},
942-
saveWifi() {
943-
// Send post with URL encoded parameters
944-
this.$coderbot.saveWifiParams(this.settings.wifiMode, this.settings.wifiSSID, this.settings.wifiPsw)
945-
.then(() => {
946-
console.log('Sent');
947-
this.snackText = this.$i18n.t('message.settings_network_updated');
948-
this.snackbar = true;
949-
});
950-
console.log(`save wifi config - ssid: ${this.settings.wifiSSID} pwd: ${this.settings.wifiPsw}`);
951-
},
952980
toggleSidebar() {
953981
const currentStatus = this.$store.getters.drawerStatus;
954982
this.$store.commit('toggleDrawer', !currentStatus);
@@ -1075,18 +1103,8 @@ export default {
10751103
this.$i18n.t('message.settings_tabs_audio'),
10761104
this.$i18n.t('message.settings_tabs_music_packages')
10771105
],
1078-
cameraExposureModes: [
1079-
{ text: 'Auto', key: 'auto' },
1080-
{ text: 'Sports', key: 'sports' },
1081-
{ text: 'Night', key: 'night' },
1082-
{ text: 'Fixed FPS', key: 'fixedfps' },
1083-
{ text: 'Anti shake', key: 'antishake' },
1084-
{ text: 'Very long', key: 'verylong' }
1085-
],
1086-
hardware_version_items: [
1087-
{ key: '4', text: '4.0 (legacy)' },
1088-
{ key: '5', text: '5.0 (latest)' }
1089-
]
1106+
networks: [],
1107+
wifi_pwd_show: false,
10901108
};
10911109
},
10921110
validations() {

src/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ import App from './App.vue';
3737
import router from './routes';
3838

3939
import CoderBot from './common/coderbot';
40+
import WifiConnect from './common/wifi_connect';
4041

4142
// Utilities
4243
// This is to serialize parameters to send them as URLencoded
4344
// https://github.com/axios/axios/issues/350#issuecomment-227270046
4445

4546
const $axios = axios.create();
4647
const $coderbot = new CoderBot(import.meta.env.VITE_CB_ENDPOINT, $axios, store);
48+
const $wifi_connect = new WifiConnect(import.meta.env.VITE_CB_ENDPOINT, $axios);
4749

4850
// this will block until CoderBot returns several configuration data.
4951
$coderbot.load().then(() => {
@@ -58,6 +60,7 @@ $coderbot.load().then(() => {
5860

5961
app.config.globalProperties.$axios = $axios;
6062
app.config.globalProperties.$coderbot = $coderbot;
63+
app.config.globalProperties.$wifi_connect = $wifi_connect;
6164
app.mount('#app');
6265
app.defaultTheme = 'dark';
6366
}).catch((errors) => {

0 commit comments

Comments
 (0)