Skip to content

Commit

Permalink
Release version 1.0.0
Browse files Browse the repository at this point in the history
Extended README & removed static-ip system.
  • Loading branch information
ArdaSeremet committed Jul 20, 2020
2 parents 0d66052 + 9b73944 commit 445338b
Show file tree
Hide file tree
Showing 32 changed files with 78 additions and 215 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .jshintrc
100644 → 100755
Empty file.
Empty file modified .travis.yml
100644 → 100755
Empty file.
Empty file modified COPYING
100644 → 100755
Empty file.
20 changes: 15 additions & 5 deletions README.markdown
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ For a long time, I was researching about a good automation platform for Linux bo
The whole system is based on NodeJS & SocketIO technologies. The back-end & front-end codes are completely separate through the SocketIO API. When a board address is entered through the web interface, the client-side Javascript code sends a SocketIO connection request to that hostname and gathers information about that board.

## Installation
Download the latest online bash installation script through the [releases page]([https://github.com/ArdaSeremet/SBC-RealTimeIO/releases](https://github.com/ArdaSeremet/SBC-RealTimeIO/releases)).
Download the latest online bash installation script through the [releases page](https://github.com/ArdaSeremet/SBC-RealTimeIO/releases).

$ sudo bash GPIOController.sh
When the installation process finishes, enter the created directory and open the app.js file with your favourite text editor. Change the nmInterfaceName & interfaceName entries with your network interface name. If you don't, the system may throw an error when you try to change the static ip address of the board.
$ sudo bash auto_install.sh
This script is going to install NodeJS & other dependencies the system needs automatically. You can run it on a bare board installation.

After that, you can run the app.js file to start the system. You can also create a systemd entry to run it at system boot-up as you wish.
When the installation process finishes, the system will be up and running as a Systemd service named "realtimeio". Systemd service will be automatically started up when the server boots up.

#### Systemd Commands
##### Use sudo privileges while running these commands.
| Command | Description |
| -- | -- |
| systemctl start realtimeio | Starts the system instance. |
| systemctl stop realtimeio | Stops the system instance. |
| systemctl status realtimeio | Shows the current status of the system. |
| systemctl enable realtimeio | Starts the system on server bootup. |
| systemctl disable realtimeio | Doesn't start the system on server bootup. |

## HTTP API Reference
#### HTTP API route list
Expand All @@ -34,6 +44,6 @@ After that, you can run the app.js file to start the system. You can also create

*The more detailed explanation will be added later.*

### Licensing
## Licensing
This software is licensed as per GNU-GPL regulations. This forbids anybody to share their own closed-sourced versions.

65 changes: 0 additions & 65 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ const serverPort = 80;
const io = require('socket.io')(server);
const fs = require('fs');
const { exec, execSync } = require('child_process');
const validationToken = fs.readFileSync('./security.txt').toString().replace('\n', '');
const httpAuthentication = {
"username": "admin",
"password": "password"
};
const interfaceName = 'wlan0'; // Change these values for your connection!
const nmInterfaceName = 'Arda';
const systemFolder = path.join(__dirname, 'sys');
const systemLogsFile = path.join(__dirname, 'static/logs.txt');
const nodeName = execSync('uname -n').toString().replace('\n', '');

const availableTaskTypes = ['turnOn', 'turnOff', 'unlink', 'linkToInput', 'setMonostable', 'setBistable'];
Expand Down Expand Up @@ -90,52 +86,6 @@ app.get('/reboot', (req, res) => {
}
});

app.get('/static-ip', (req, res) => {
res.sendFile(path.join(__dirname, 'static/static-ip.html'));
});

app.get('/static-ip/get', (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/json' });

let ip = os.networkInterfaces().wlan0[0].address;
let gateway = execSync(`ip r | grep ${interfaceName} | grep default | cut -d ' ' -f 3 | head -n1`).toString().replace('\n', '');
let dhcp = execSync(`nmcli c s ${nmInterfaceName} | grep "ipv4.method" | tail -c 5`).toString().replace('\n', '') == 'auto' ? 'true' : 'false';

res.write(`{
"ip-address": "${ip}",
"gateway-ip-address": "${gateway}",
"dhcp": "${dhcp}"
}`);
res.end();
});

app.get('/static-ip/set', (req, res) => {
if(!req.headers.authorization || req.headers.authorization.indexOf('Basic ') === -1) {
res.statusCode = 401;
res.setHeader('WWW-Authenticate', 'Basic realm="Secure Area"');
res.end('Authorization is required!');
}
const base64Credentials = req.headers.authorization.split(' ')[1];
const credentials = Buffer.from(base64Credentials, 'base64').toString('ascii');
const [username, password] = credentials.split(':');
if(username != httpAuthentication.username || password != httpAuthentication.password) {
res.statusCode = 401;
res.write('Invalid Authentication Credentials!');
}
try {
let method = (req.query.dhcp == 'true') ? 'auto' : 'manual';
let gateway = req.query['gateway-ip-address'];
let ip = req.query['ip-address'];

execSync(`nmcli connection modify '${nmInterfaceName}' connection.autoconnect yes ipv4.method ${method} ipv4.addresses ${ip}/24 ipv4.gateway ${gateway} ipv4.dns 8.8.8.8,8.8.4.4`);
res.write('IP address has been succesfully set. Please reboot the board to apply the changes.');
res.end();
} catch(e) {
res.write('An error occured while processing your request. Try again later.');
res.end();
}
});

/**
* This function is to bring the backwards compatibility to all ProgettiHWSW.com automation boards.
*/
Expand Down Expand Up @@ -839,26 +789,11 @@ const setBistable = (pin, callback) => {
return false;
};

const windowsblueStatusUpdater = () => {
var queryString = ioData.boardName.replace(/s+/g, '') + '_';
ioData.pinOrder.forEach((item, i) => {
if(item.toString() in ioData.controllable_pins) {
let name = ioData.pinNames[item.toString()];
let nameSpaceless = name.replace(/\s+/g, '');
let valueStr = (ioData.pinStates[item] == '1') ? 'ON' : 'OFF';
queryString += nameSpaceless + 'is' + valueStr + '_';
}
});
queryString = queryString.slice(0, -1);
http.get(`http://windowsblue.it/boards.php?in=${encodeURIComponent(queryString)}`);
};

initData();

setInterval(checkInputPins, 300);
setInterval(checkOutputPins, 4000);
setInterval(saveData, 5000);
//setInterval(windowsblueStatusUpdater, 60000);

/* Socket */

Expand Down
Empty file modified package-lock.json
100644 → 100755
Empty file.
Empty file modified package.json
100644 → 100755
Empty file.
58 changes: 58 additions & 0 deletions scripts/auto_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

echo 'Updating package repos ==> '
sudo apt-get update
echo '----'

echo 'Installing Curl, AutoSSH and Git ==> '
sudo apt-get install curl git -y
echo '----'

echo 'Going to home directory ==> '
cd ~
echo '----'

echo 'Installing NodeJS Version 10'
curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
sudo chmod +x ./nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo rm nodesource_setup.sh
sudo apt-get install nodejs -y
echo '----'

echo 'Getting project files from GitHub'
cd ~
git clone https://github.com/ArdaSeremet/SBC-RealTimeIO.git
cd SBC-RealTimeIO
npm install
echo '----'

echo 'Setting systemd daemon for system bootup'
projectPath=$(pwd)
username=$(whoami)
sudo rm /etc/systemd/system/realtimeio.service
cat >> /etc/systemd/system/realtimeio.service <<EOF
[Unit]
Description=Realtime GPIO Controller for Linux SBCs
[Service]
User=${username}
Restart=always
KillSignal=SIGQUIT
WorkingDirectory=${projectPath}
ExecStart=${projectPath}/app.js
[Install]
WantedBy=multi-user.target
EOF
echo '----'

sudo systemctl daemon-reload
sudo systemctl enable gpioctrl
echo '----'

echo 'Running the server'
sudo systemctl start gpioctrl
echo '----'

echo 'Done installing the system! Have a nice day!'
98 changes: 0 additions & 98 deletions scripts/install_from_scratch.sh

This file was deleted.

Empty file modified static/css/index.css
100644 → 100755
Empty file.
Empty file modified static/css/ioController.css
100644 → 100755
Empty file.
Empty file modified static/css/ipController.css
100644 → 100755
Empty file.
Empty file modified static/css/main.css
100644 → 100755
Empty file.
Empty file modified static/css/main.css.map
100644 → 100755
Empty file.
Empty file modified static/css/modeManager.css
100644 → 100755
Empty file.
Empty file modified static/css/reset.min.css
100644 → 100755
Empty file.
Empty file modified static/css/taskManager.css
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion static/index.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<a href="#" onclick="handleAutomaticAddition();" class="addNewBoard">Configure Automatic Addition</a>
</main>
<footer role="main">
<span>This website is a property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. All rights reserved. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
<span>This website is originally an open-sourced property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
</footer>

<script src="/socket.io/socket.io.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion static/ioController.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<a href="#" onclick="handleAutomaticAddition();" class="addNewBoard">Configure Automatic Addition</a>
</main>
<footer role="main">
<span>This website is a property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. All rights reserved. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
<span>This website is originally an open-sourced property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
</footer>

<script src="/socket.io/socket.io.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion static/ipController.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<a href="#" onclick="handleAutomaticAddition();" class="addNewBoard">Configure Automatic Addition</a>
</main>
<footer role="main">
<span>This website is a property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. All rights reserved. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
<span>This website is originally an open-sourced property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
</footer>
<script src="/socket.io/socket.io.js"></script>
<script src="js/ipController.js"></script>
Expand Down
Empty file modified static/js/index.js
100644 → 100755
Empty file.
Empty file modified static/js/ioController.js
100644 → 100755
Empty file.
Empty file modified static/js/ipController.js
100644 → 100755
Empty file.
Empty file modified static/js/jquery.min.js
100644 → 100755
Empty file.
Empty file modified static/js/main.js
100644 → 100755
Empty file.
Empty file modified static/js/modeManager.js
100644 → 100755
Empty file.
Empty file modified static/js/taskManager.js
100644 → 100755
Empty file.
2 changes: 0 additions & 2 deletions static/logs.txt

This file was deleted.

40 changes: 0 additions & 40 deletions static/mainLayout.html

This file was deleted.

2 changes: 1 addition & 1 deletion static/modeManager.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<a href="#" onclick="handleAutomaticAddition();" class="addNewBoard">Configure Automatic Addition</a>
</main>
<footer role="main">
<span>This website is a property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. All rights reserved. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
<span>This website is originally an open-sourced property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
</footer>

<script src="/socket.io/socket.io.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion static/taskManager.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<a href="#" onclick="handleAutomaticAddition();" class="addNewBoard">Configure Automatic Addition</a>
</main>
<footer role="main">
<span>This website is a property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. All rights reserved. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
<span>This website is originally an open-sourced property of <a href="http://progettihwsw.com">ProgettiHwSw SaS</a>. Developed by <a href="https://www.ardaseremet.com.tr">Arda Seremet</a>.</span>
</footer>

<script src="/socket.io/socket.io.js"></script>
Expand Down

0 comments on commit 445338b

Please sign in to comment.