Skip to content

Commit

Permalink
import from grid-host project
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartoallen committed Jan 24, 2020
1 parent 3f57049 commit 4318743
Show file tree
Hide file tree
Showing 28 changed files with 8,703 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
node_modules
etc/bedclear
etc/uuid
tmp
File renamed without changes.
2 changes: 1 addition & 1 deletion root-rc.local → bin/root-rc.local
@@ -1,6 +1,6 @@
#!/bin/bash

echo "My IP address is $(hostname -I)"
/home/pi/grid-bot/start-root.sh
/home/pi/grid-bot/bin/start-root.sh

exit 0
4 changes: 2 additions & 2 deletions setup-root.sh → bin/setup-root.sh
@@ -1,10 +1,10 @@
#!/bin/bash

# update config.txt with required fields
grep grid:bot /boot/config.txt || cat /home/pi/grid-bot/root-config.txt >> /boot/config.txt
grep grid:bot /boot/config.txt || cat /home/pi/grid-bot/etc/root-config.txt >> /boot/config.txt

# update rc.local to start grid:bot services
cp /home/pi/grid-bot/root-rc.local /etc/rc.local
cp /home/pi/grid-bot/bin/root-rc.local /etc/rc.local

# allow tcp on x server
grep ^xserver-allow-tcp=true /etc/lightdm/lightdm.conf || echo xserver-allow-tcp=true >> /etc/lightdm/lightdm.conf
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions start-gridbot.sh → bin/start-gridbot.sh
Expand Up @@ -6,10 +6,10 @@ export NODE=${ROOT}/node/bin/node
export BAUD=250000
export OPTS='--web --listen --baud=${BAUD} --filedir=${ROOT}/uploads'

cd ${HOME}/grid-host
cd ${ROOT}
while /bin/true; do
[ -f etc/serial.conf ] && source etc/serial.conf
echo "--- starting --- $(date)"
eval "${NODE} src/serial.js ${OPTS}"
eval "${NODE} src/js/serial.js ${OPTS}"
echo "--- exited ---"
done
File renamed without changes.
7 changes: 7 additions & 0 deletions bin/start-root.sh
@@ -0,0 +1,7 @@
#!/bin/bash

export ROOT=/home/pi/grid-bot

nohup nice -n -20 su -l -c ${ROOT}/bin/start-gridbot.sh pi > /tmp/gridbot.log 2>&1 &
nohup nice -n 19 su -l -c ${ROOT}/bin/start-gridhost.sh pi > /tmp/gridhost.log 2>&1 &
nohup nice -n 19 ${ROOT}/bin/start-camera.sh > /tmp/camera.log 2>&1 &
9 changes: 9 additions & 0 deletions bin/update-code.sh
@@ -0,0 +1,9 @@
#!/bin/bash

(
echo "updating code from github"
cd ../grid-bot && git pull && \
cd ../grid-host && git pull && \
cd ../grid-apps && git pull
echo "code update complete"
) | tee -a /tmp/update-code.log
10 changes: 10 additions & 0 deletions bin/update-name.sh
@@ -0,0 +1,10 @@
#!/bin/bash

[ -z "$1" ] && echo "missing host name" && exit

echo "HOST NAME=${1}"
echo "${1}" > /etc/hostname || echo "unable to update hostname"
echo "127.0.0.1 ${1}" >> /etc/hosts || echo "unable to undate hosts"
hostname "${1}"

echo "updated host name. reboot required"
27 changes: 27 additions & 0 deletions bin/update-wifi.sh
@@ -0,0 +1,27 @@
#!/bin/bash

[ -z "$1" ] && echo "missing ssid" && exit
[ -z "$2" ] && echo "missing psk" && exit

export TMPF=/tmp/wpa_supplicant.conf
export FILE=/etc/wpa_supplicant/wpa_supplicant.conf

echo "SSID=${1}"
echo "PSK=${2}"
echo "FILE=${FILE}"

cat > ${TMPF} << EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="${1}"
psk="${2}"
}
EOF

sudo mv ${TMPF} ${FILE}
sudo cat ${FILE}

echo "updated wifi settings. reboot required"
File renamed without changes.
28 changes: 28 additions & 0 deletions package.json
@@ -0,0 +1,28 @@
{
"name": "grid-bot",
"version": "0.0.1",
"description": "Runtime environment setup for GridBot controllers and devices",
"author": "Stewart Allen <sa@grid.space>",
"license": "MIT",
"private": false,
"repository": {
"type": "git",
"url": "https://github.com/stewartoallen/grid-bot.git"
},
"keywords": [
"grid.space",
"kiri:moto",
"server",
"3d",
"print",
"gcode"
],
"dependencies": {
"connect": "^3.6.6",
"minimist": "^1.2.0",
"moment": "^2.22.2",
"serialport": "^8.0.0",
"serve-static": "^1.13.2",
"ws": "^5.2.0"
}
}
12 changes: 0 additions & 12 deletions pi-gh-config

This file was deleted.

7 changes: 3 additions & 4 deletions setup.sh
Expand Up @@ -21,6 +21,7 @@ export ROOT="${HOME}/grid-bot"
# update grid-bot
cd "${ROOT}"
git pull
npm i

# uploads dir, remove legacy port link
cd ${ROOT}
Expand All @@ -30,7 +31,7 @@ mkdir -p uploads
# setup graphical interface boot
export LXDIR=${HOME}/.config/lxsession/LXDE-pi
mkdir -p "${LXDIR}"
cp "${ROOT}/pi-ui-autostart" "${LXDIR}/autostart"
cp "${ROOT}/bin/pi-ui-autostart" "${LXDIR}/autostart"
chmod 755 "${LXDIR}/autostart"

# download, expand, link node
Expand Down Expand Up @@ -63,8 +64,6 @@ export PATH=${PATH}:${ROOT}/node/bin
echo "installing grid-host"
cd ${HOME}
git clone https://github.com/GridSpace/grid-host.git grid-host
# setup config pointing to local instance
cp "grid-bot/pi-gh-config" "grid-host/etc/config.json"
}

# update grid-host modules
Expand All @@ -85,7 +84,7 @@ git pull
npm i

# do required root setups
[ ! -d "${HOME}/.grid" ] && sudo ${ROOT}/setup-root.sh && mkdir "${HOME}/.grid"
[ ! -d "${HOME}/.grid" ] && sudo ${ROOT}/bin/setup-root.sh && mkdir "${HOME}/.grid"

# ssh setup/trust if desired
[ ! -d "${HOME}/.ssh" ] && {
Expand Down
58 changes: 58 additions & 0 deletions src/js/linebuffer.js
@@ -0,0 +1,58 @@
class LineBuffer {

constructor(stream, online) {
if (!stream) {
throw "missing stream";
}
const lbuf = this;
this.enabled = true;
this.buffer = null;
this.stream = stream;
this.online = online;
if (online) {
stream.on("readable", () => {
let data;
while (data = stream.read()) {
lbuf.ondata(data);
}
});
} else {
stream.on("data", data => {
lbuf.ondata(data);
});
}
}

ondata(data) {
if (this.buffer) {
this.buffer = Buffer.concat([this.buffer, data]);
} else {
this.buffer = data;
}
this.nextLine();
}

nextLine() {
if (!this.enabled) {
return;
}
let left = 0;
const data = this.buffer;
const cr = data.indexOf("\r");
const lf = data.indexOf("\n");
if (lf && cr + 1 == lf) { left = 1 }
if (lf >= 0) {
let slice = data.slice(0, lf - left);
if (this.online) {
this.online(slice);
} else {
this.stream.emit("line", slice);
}
this.buffer = data.slice(lf + 1);
this.nextLine();
}
}

}

module.exports = LineBuffer;

0 comments on commit 4318743

Please sign in to comment.