mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-05-28 21:12:37 +02:00
Added wifi disconnect
This commit is contained in:
parent
a06ddd7f23
commit
86d265d585
@ -30,6 +30,7 @@ UPTIME=$(uptime -s)
|
||||
LOADAVG=$(cat /proc/loadavg)
|
||||
ARCHITECTURE=$(uname -m)
|
||||
TEMP=$(cat /sys/class/thermal/thermal_zone*/temp)
|
||||
ACTIVE_WIFI=$(nmcli -t c show --active | grep wireless | cut -d":" -f1)
|
||||
|
||||
# Memory
|
||||
memTotal=$(egrep '^MemTotal:' /proc/meminfo | awk '{print $2}')
|
||||
@ -59,6 +60,7 @@ JSON="{
|
||||
\"loadAverage\": \"$LOADAVG\",
|
||||
\"architecture\": \"$ARCHITECTURE\",
|
||||
\"temperature\": \"$TEMP\",
|
||||
\"activeWifi\": \"$ACTIVE_WIFI\",
|
||||
\"memory\":
|
||||
{
|
||||
\"total\": $memTotal,
|
||||
|
@ -8,6 +8,7 @@ cat << EOF
|
||||
"loadAverage": "0.00 0.00 0.00 1/120 2859",
|
||||
"architecture": "armv7l",
|
||||
"temperature": "40656",
|
||||
"activeWifi": "befree",
|
||||
"memory":
|
||||
{
|
||||
"total": 245760,
|
||||
|
@ -10,4 +10,8 @@ app.use('/api/graphql', graphqlApp)
|
||||
|
||||
if (process.env.NODE_ENV === 'production') app.use(express.static(buildPath));
|
||||
|
||||
app.get('*', function (req, res) {
|
||||
res.sendFile(buildPath + '/index.html');
|
||||
});
|
||||
|
||||
module.exports = app
|
||||
|
17
src/graphql/graphqlModules/Mcu/McuWifiDisconnect.js
Normal file
17
src/graphql/graphqlModules/Mcu/McuWifiDisconnect.js
Normal file
@ -0,0 +1,17 @@
|
||||
module.exports.typeDefs = `
|
||||
type McuActions {
|
||||
wifiDisconnect: McuWifiDisconnectOutput!
|
||||
}
|
||||
|
||||
type McuWifiDisconnectOutput {
|
||||
error: Error
|
||||
}
|
||||
`
|
||||
|
||||
module.exports.resolvers = {
|
||||
McuActions: {
|
||||
wifiDisconnect (root, args, { dispatch }) {
|
||||
return dispatch('api/mcu/wifiDisconnect')
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ function wifiConnect(ssid, passphrase, errors) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let command = 'sudo nmcli dev wifi connect ' + ssid;
|
||||
if (passphrase) command += ' password ' + passphrase;
|
||||
if (process.env.NODE_ENV !== 'production') command = 'echo true';
|
||||
if (process.env.NODE_ENV !== 'production') command = 'sleep 2 && nmcli dev wifi connect ' + ssid;
|
||||
|
||||
exec(command, {}, (err, stdout) => {
|
||||
if (err) {
|
||||
|
31
src/store/api/mcu/mcuWifiDisconnect.js
Normal file
31
src/store/api/mcu/mcuWifiDisconnect.js
Normal file
@ -0,0 +1,31 @@
|
||||
const { exec } = require('child_process')
|
||||
|
||||
module.exports = ({ define }) => {
|
||||
define('wifiDisconnect', async (payload, { knex, errors, utils }) => {
|
||||
await wifiDisconnect(errors);
|
||||
return;
|
||||
}), {
|
||||
auth: true
|
||||
}
|
||||
}
|
||||
|
||||
function wifiDisconnect(ssid, passphrase, errors) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let command = 'for i in $(nmcli -t c show |grep wireless | cut -d":" -f2); do nmcli c delete $i; done';
|
||||
if (process.env.NODE_ENV !== 'production') command = 'sleep 2 && echo true';
|
||||
|
||||
exec(command, {}, (err, stdout) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
if (stdout.includes('Error')) {
|
||||
errMsg = stdout.trim().replace(/^.+\(\d+\)\ /g, "").replace(/\.$/g, "");
|
||||
reject(new errors.ValidationError(errMsg));
|
||||
}
|
||||
else {
|
||||
resolve()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user