-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
RAKwireless
authored and
RAKwireless
committed
Jul 1, 2019
1 parent
05d65b2
commit 198571a
Showing
135 changed files
with
29,844 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,48 @@ | ||
# rak_common_for_gateway | ||
# rak_common_for_gateway | ||
|
||
## Introduction | ||
|
||
The aim of this project is to help users set up a LoRa network easily. The User Guide can be get from our Web. | ||
|
||
## Supported platforms | ||
|
||
This project currently provides support for the below platforms. | ||
* RAK831 | ||
* RAK833 | ||
* RAK2245 | ||
* RAK2247 | ||
* RAK7243 | ||
|
||
## Changelog | ||
|
||
2019-05-24 V2.9 | ||
|
||
* 1.Multiple models are integrated with one common version. | ||
* 2.Upgrade LoRa server to 3.0. | ||
|
||
## Installation procedure | ||
|
||
step1 : Download and install [Raspbian Stretch LITE](https://www.raspberrypi.org/downloads/raspbian/) | ||
|
||
step2 : Use "sudo raspi-config" command, enable spi and i2c interface. | ||
|
||
step3 : Clone the installer and start the installation. | ||
|
||
$ sudo apt update; sudo apt install git -y | ||
$ git clone https://github.com/RAKWireless/rak_common_for_gateway.git ~/rak_common_for_gateway | ||
$ cd ~/rak_common_for_gateway | ||
$ sudo ./install.sh | ||
|
||
step4 : Next you will see some messages as follow. Please select the corresponding hardware model. | ||
|
||
Please select your gateway model: | ||
* 1.RAK831 | ||
* 2.RAK833 | ||
* 3.RAK2245 | ||
* 4.RAK2247 | ||
* 5.RAK7243 | ||
Please enter 1-5 to select the model: | ||
|
||
step5 : Wait a moment and the installation is complete.If your gateway uses a wired connection, please reconfigure the LAN's IP address using "sudo gateway-config" after the installation is complete. | ||
|
||
step6 : For more other features, please use "sudo gateway-config". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
PREFIX=/usr/local/rak/ap | ||
MANDIR=$(PREFIX)/share/man | ||
BINDIR=$(PREFIX)/bin | ||
|
||
all: | ||
@echo "Run 'make install' for installation." | ||
@echo "Run 'make uninstall' for uninstallation." | ||
|
||
install: | ||
install -Dm755 create_ap $(DESTDIR)$(BINDIR)/create_ap | ||
install -Dm644 create_ap.conf $(DESTDIR)/etc/create_ap.conf | ||
[ ! -d /lib/systemd/system ] || install -Dm644 create_ap.service $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service | ||
install -Dm644 bash_completion $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap | ||
install -Dm644 README.md $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md | ||
|
||
uninstall: | ||
rm -f $(DESTDIR)$(BINDIR)/create_ap | ||
rm -f $(DESTDIR)/etc/create_ap.conf | ||
[ ! -f /lib/systemd/system/create_ap.service ] || rm -f $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service | ||
rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap | ||
rm -f $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
CHANNEL=default | ||
GATEWAY=192.168.12.1 | ||
WPA_VERSION=2 | ||
ETC_HOSTS=0 | ||
DHCP_DNS=gateway | ||
NO_DNS=0 | ||
NO_DNSMASQ=0 | ||
HIDDEN=0 | ||
MAC_FILTER=0 | ||
MAC_FILTER_ACCEPT=/etc/hostapd/hostapd.accept | ||
ISOLATE_CLIENTS=0 | ||
SHARE_METHOD=nat | ||
IEEE80211N=0 | ||
IEEE80211AC=0 | ||
HT_CAPAB=[HT40+] | ||
VHT_CAPAB= | ||
DRIVER=nl80211 | ||
NO_VIRT=0 | ||
COUNTRY= | ||
FREQ_BAND=2.4 | ||
NEW_MACADDR= | ||
DAEMONIZE=0 | ||
NO_HAVEGED=0 | ||
WIFI_IFACE=wlan0 | ||
INTERNET_IFACE=eth0 | ||
SSID=Rakwireless_XXXX | ||
PASSPHRASE=rakwireless | ||
USE_PSK=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Create AP Service | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/local/rak/ap/bin/create_ap --config /usr/local/rak/ap/create_ap.conf | ||
KillSignal=SIGINT | ||
Restart=on-failure | ||
RestartSec=5 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
# script needs to be run with super privilege | ||
if [ $(id -u) -ne 0 ]; then | ||
printf "Script must be run with superuser privilege. Try 'sudo ./install.sh'\n" | ||
exit 1 | ||
fi | ||
|
||
set -e | ||
|
||
SCRIPT_COMMON_FILE=$(pwd)/../rak/rak/shell_script/rak_common.sh | ||
source $SCRIPT_COMMON_FILE | ||
|
||
apt-get install util-linux procps hostapd iproute2 iw haveged dnsmasq | ||
|
||
if [ ! -d create_ap ]; then | ||
git clone https://github.com/oblique/create_ap | ||
fi | ||
cp Makefile_ap create_ap/Makefile | ||
pushd create_ap | ||
make install | ||
popd | ||
cp create_ap.service /lib/systemd/system/ | ||
cp create_ap.conf /usr/local/rak/ap | ||
|
||
./set_ssid | ||
#systemctl enable create_ap | ||
#mv /sbin/wpa_supplicant /sbin/wpa_supplicant_bak | ||
|
||
echo_success "Install ap success!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
GATEWAY_EUI_NIC="wlan0" | ||
|
||
GATEWAY_EUI=$(ip link show $GATEWAY_EUI_NIC | awk '/ether/ {print $2}' | awk -F\: '{print $5$6}') | ||
GATEWAY_EUI=${GATEWAY_EUI^^} | ||
|
||
sed -i "26c SSID=Rakwireless_$GATEWAY_EUI" /usr/local/rak/ap/create_ap.conf | ||
sed -i "s/^.*ap_ssid.*$/\\t\\t\"ap_ssid\":\"Rakwireless_$GATEWAY_EUI\",/" /usr/local/rak/gateway-config-info.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash | ||
|
||
# Stop on the first sign of trouble | ||
#set -e | ||
|
||
if [ $UID != 0 ]; then | ||
echo "ERROR: Operation not permitted. Forgot sudo?" | ||
exit 1 | ||
fi | ||
|
||
function echo_yellow() | ||
{ | ||
echo -e "\033[1;33m$1\033[0m" | ||
} | ||
|
||
do_check_variable_type(){ | ||
local a="$1" | ||
printf "%d" "$a" &>/dev/null && return 0 | ||
printf "%d" "$(echo $a|sed 's/^[+-]\?0\+//')" &>/dev/null && return 0 | ||
printf "%f" "$a" &>/dev/null && return 1 | ||
[ ${#a} -eq 1 ] && return 2 | ||
return 3 | ||
} | ||
|
||
do_check_variable_type_echo(){ | ||
local a="$1" | ||
printf "%d" "$a" &>/dev/null && echo "integer, return 0" && return 0 | ||
printf "%d" "$(echo $a|sed 's/^[+-]\?0\+//')" &>/dev/null && echo "integer,return 0" && return 0 | ||
printf "%f" "$a" &>/dev/null && echo "number,return 1" && return 1 | ||
[ ${#a} -eq 1 ] && echo "char, return 2" && return 2 | ||
echo "string, return 3" && return 3 | ||
} | ||
|
||
function echo_model_info() | ||
{ | ||
echo_yellow "Please select your gateway model:" | ||
echo_yellow "*\t1.RAK831" | ||
echo_yellow "*\t2.RAK833" | ||
echo_yellow "*\t3.RAK2245" | ||
echo_yellow "*\t4.RAK2247" | ||
echo_yellow "*\t5.RAK7243" | ||
echo_yellow "Please enter 1-5 to select the model:\c" | ||
} | ||
|
||
function do_set_model_to_json() | ||
{ | ||
JSON_FILE=./rak/rak/rak_gw_model.json | ||
if [ $1 -eq 1 ]; then | ||
GW_MODEL=RAK831 | ||
elif [ $1 -eq 2 ]; then | ||
GW_MODEL=RAK833 | ||
elif [ $1 -eq 3 ]; then | ||
GW_MODEL=RAK2245 | ||
elif [ $1 -eq 4 ]; then | ||
GW_MODEL=RAK2247 | ||
elif [ $1 -eq 5 ]; then | ||
GW_MODEL=RAK7243 | ||
else | ||
# Never come here | ||
echo "error" | ||
return 1 | ||
fi | ||
linenum=`sed -n "/gw_model/=" $JSON_FILE` | ||
sed -i "${linenum}c\\\\t\"gw_model\": \"$GW_MODEL\"," $JSON_FILE | ||
} | ||
|
||
function do_set_model() | ||
{ | ||
echo_model_info | ||
while [ 1 -eq 1 ] | ||
do | ||
read RAK_MODEL | ||
if [ -z "$RAK_MODEL" ]; then | ||
echo_yellow "IF Please enter 1-5 to select the model:\c" | ||
continue | ||
fi | ||
|
||
do_check_variable_type $RAK_MODEL | ||
RET=$? | ||
|
||
if [ $RET -eq 0 ]; then | ||
if [ $RAK_MODEL -lt 1 ] || [ $RAK_MODEL -gt 5 ]; then | ||
echo_yellow "IF Please enter 1-5 to select the model:\c" | ||
continue | ||
else | ||
do_set_model_to_json $RAK_MODEL | ||
return 0 | ||
fi | ||
else | ||
echo_yellow "IF Please enter 1-5 to select the model:\c" | ||
continue | ||
|
||
fi | ||
done | ||
} | ||
|
||
do_set_model | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/sh | ||
|
||
do_expand_rootfs() { | ||
ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p') | ||
|
||
PART_NUM=${ROOT_PART#mmcblk0p} | ||
if [ "$PART_NUM" = "$ROOT_PART" ]; then | ||
whiptail --msgbox "$ROOT_PART is not an SD card. Don't know how to expand" 20 60 2 | ||
return 0 | ||
fi | ||
|
||
# NOTE: the NOOBS partition layout confuses parted. For now, let's only | ||
# agree to work with a sufficiently simple partition layout | ||
if [ "$PART_NUM" -ne 2 ]; then | ||
whiptail --msgbox "Your partition layout is not currently supported by this tool. You are probably using NOOBS, in which case your root filesystem is already expanded anyway." 20 60 2 | ||
return 0 | ||
fi | ||
|
||
LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:) | ||
if [ $LAST_PART_NUM -ne $PART_NUM ]; then | ||
whiptail --msgbox "$ROOT_PART is not the last partition. Don't know how to expand" 20 60 2 | ||
return 0 | ||
fi | ||
|
||
# Get the starting offset of the root partition | ||
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g') | ||
[ "$PART_START" ] || return 1 | ||
# Return value will likely be error for fdisk as it fails to reload the | ||
# partition table because the root fs is mounted | ||
fdisk /dev/mmcblk0 <<EOF | ||
p | ||
d | ||
$PART_NUM | ||
n | ||
p | ||
$PART_NUM | ||
$PART_START | ||
p | ||
w | ||
EOF | ||
ASK_TO_REBOOT=1 | ||
|
||
# now set up an init.d script | ||
cat <<EOF > /etc/init.d/resize2fs_once && | ||
#!/bin/sh | ||
### BEGIN INIT INFO | ||
# Provides: resize2fs_once | ||
# Required-Start: | ||
# Required-Stop: | ||
# Default-Start: 3 | ||
# Default-Stop: | ||
# Short-Description: Resize the root filesystem to fill partition | ||
# Description: | ||
### END INIT INFO | ||
. /lib/lsb/init-functions | ||
case "\$1" in | ||
start) | ||
log_daemon_msg "Starting resize2fs_once" && | ||
resize2fs /dev/$ROOT_PART && | ||
update-rc.d resize2fs_once remove && | ||
rm /etc/init.d/resize2fs_once && | ||
log_end_msg \$? | ||
;; | ||
*) | ||
echo "Usage: \$0 start" >&2 | ||
exit 3 | ||
;; | ||
esac | ||
EOF | ||
chmod +x /etc/init.d/resize2fs_once && | ||
update-rc.d resize2fs_once defaults && | ||
if [ "$INTERACTIVE" = True ]; then | ||
whiptail --msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" 20 60 2 | ||
fi | ||
} | ||
|
||
do_expand_rootfs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# Try to get gateway ID from MAC address | ||
# First try eth0, if that does not exist, try wlan0 (for RPi Zero) | ||
GATEWAY_EUI_NIC="eth0" | ||
if [[ `grep "$GATEWAY_EUI_NIC" /proc/net/dev` == "" ]]; then | ||
GATEWAY_EUI_NIC="wlan0" | ||
fi | ||
|
||
if [[ `grep "$GATEWAY_EUI_NIC" /proc/net/dev` == "" ]]; then | ||
echo "ERROR: No network interface found. Cannot set gateway ID." | ||
exit 1 | ||
fi | ||
|
||
GATEWAY_EUI=$(ip link show $GATEWAY_EUI_NIC | awk '/ether/ {print $2}' | awk -F\: '{print $1$2$3"FFFE"$4$5$6}') | ||
GATEWAY_EUI=${GATEWAY_EUI^^} | ||
|
||
sudo -u postgres psql loraserver_as -c "update gateway set mac='\x$GATEWAY_EUI';" | ||
sudo -u postgres psql loraserver_ns -c "update gateway set gateway_id='\x$GATEWAY_EUI';" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
# Stop on the first sign of trouble | ||
set -e | ||
|
||
SCRIPT_COMMON_FILE=$(pwd)/../rak/rak/shell_script/rak_common.sh | ||
source $SCRIPT_COMMON_FILE | ||
|
||
if [ $UID != 0 ]; then | ||
echo_error "Operation not permitted. Forgot sudo?" | ||
exit 1 | ||
fi | ||
|
||
|
||
cp ../first_boot /usr/local/rak/ -rf | ||
rm /usr/local/rak/first_boot/install.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
GATEWAY_EUI_NIC="wlan0" | ||
if [[ `grep "$GATEWAY_EUI_NIC" /proc/net/dev` == "" ]]; then | ||
GATEWAY_EUI_NIC="eth0" | ||
fi | ||
if [[ `grep "$GATEWAY_EUI_NIC" /proc/net/dev` == "" ]]; then | ||
echo "ERROR: No network interface found. Cannot set gateway ID." | ||
exit | ||
fi | ||
GATEWAY_EUI=$(ip link show $GATEWAY_EUI_NIC | awk '/ether/ {print $2}' | awk -F\: '{print $5$6}') | ||
GATEWAY_EUI=${GATEWAY_EUI^^} | ||
|
||
sed -i "26c SSID=Rakwireless_$GATEWAY_EUI" /usr/local/rak/ap/create_ap.conf | ||
|
||
sed -i "s/^.*ap_ssid.*$/\"ap_ssid\":\"Rakwireless_$GATEWAY_EUI\",/" /usr/local/rak/gateway-config-info.json | ||
sed -i "s/^.*ap_pwd.*$/\"ap_pwd\":\"rakwireless\"/" /usr/local/rak/gateway-config-info.json | ||
|
Oops, something went wrong.