This repository has been archived by the owner on Dec 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathiot-lora-installer
executable file
·248 lines (201 loc) · 8.66 KB
/
iot-lora-installer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env python3
# IOT LoRa Installer
# by Ryan Walmsley
# (C) Pi Supply 2018-2019
# This file downloads the current software for the LoRa Gateway Packet
# Forwarder by Kersing and installs it on your Raspberry Pi. At the same time
# it also enables SPI, Installs a service to automatically start it on boot,
# a configuration script and sets the core clock to a fixed frequency which
# fixes bugs on Models 3B & 3B+.
#
# This software is designed to be run on a vanilla installation of Raspbian!
# We cannot guarantee that it will not break other software you are running
# on your Raspberry Pi.
# Making Gateways, making lora Gateways, get some lora and put it in a gateway,
# making gateways, making lora gateways, Loraaaa gatewaysssss
# Imports!
from time import sleep
import os
import shutil
import sys
# End imports
# START
print('''
___ ___ _____ _ ___ ___ _
|_ _/ _ \_ _| | | ___| _ \__ _ / __|__ _| |_ _____ __ ____ _ _ _
| | (_) || | | |__/ _ \ / _` | | (_ / _` | _/ -_) V V / _` | || |
|___\___/ |_| |____\___/_|_\__,_| \___\__,_|\__\___|\_/\_/\__,_|\_, |
|__/
This script will install the software required to get your Pi Supply IoT Lora
Gateway HAT up and running with The Things Network.
The script will automatically continue in 10 seconds.
If you are not happy press Control + C to quit.
''')
sleep(10)
# We need to check which system this is running on
# Set variable model to
# Expected results:
# RPi : Raspberry
# Odroid C2: ODROID-C2
# Tinkerboard: Rockchip
# Unknown: 42
try:
dtModel = open('/proc/device-tree/model', 'r')
modelUsed = dtModel.read().split(" ")[0]
except Exception:
print("Device Tree directory not found, this is likely because you are "
"running this program on a normal computer or a non supported SBC")
try:
if(sys.argv[1] == "balena"):
modelUsed = "Raspberry"
except Exception:
exit()
print("Detected SBC: %s" % modelUsed)
print("Updating, Upgrading and installing packages from APT")
# Update Apt repository List, Upgrade Any Other Packages and then install the
# required packages.
os.system("apt-get update")
os.system("apt-get upgrade -y")
packages = ['python3-dialog',
'protobuf-compiler',
'libprotobuf-dev',
'libprotoc-dev',
'automake',
'libtool',
'autoconf',
'git',
'pkg-config',
'protobuf-c-compiler',
'libprotobuf-c-dev']
os.system("apt-get install %s -y" % ' '.join(packages))
print("Deleting old files")
# Delete all of the old software this is fine as the configuration files are
# stored on the /boot partition
os.system("rm -rf /opt/iotloragateway")
# Remake the directory structure
os.system("mkdir -p /opt/iotloragateway")
os.system("mkdir -p /opt/iotloragateway/dev")
print("Downloading software to compile")
# Download all of the software required
os.chdir("/opt/iotloragateway/dev")
os.system("git clone https://github.com/PiSupply/lora_gateway.git")
os.system("git clone https://github.com/PiSupply/paho.mqtt.embedded-c.git")
os.system("git clone https://github.com/PiSupply/ttn-gateway-connector.git")
os.system("git clone https://github.com/PiSupply/protobuf-c.git")
os.system("git clone https://github.com/PiSupply/packet_forwarder.git")
os.system("git clone -b release --single-branch https://github.com/PiSupply/iot-lora-gateway.git")
print("Compiling LoRa Gateway Driver")
# First lets compile the LoRa Gateway driver library which provides the SPI
# interface
# Define some directory variables.
base_dir = "/opt/iotloragateway"
compilation_dir = "%s/dev" % base_dir
boot_dir = "/boot/iotloragateway"
confs_dir = "%s/global_confs" % boot_dir
os.chdir("%s/lora_gateway/libloragw" % compilation_dir)
# Change the configuration file based on what system is being used.
if(modelUsed == "Raspberry"):
platform = "iotloragw_rpi"
if(modelUsed == "Rockchip"):
platform = "iotloragw_tnk"
if(modelUsed == "ASUS"):
platform = "iotloragw_tnk"
if(modelUsed == "ODROID-C2\x00"):
platform = "iotloragw_odc2"
os.system("sed -i -e 's/PLATFORM= .*$/PLATFORM= %s/g' library.cfg" % platform)
# Compile the gateway driver
os.system("make -j 4")
compileProtobuf = 0
if(compileProtobuf):
print("Compiling protobuf-c library")
# Move to the Protobuf-c library and compile it
os.chdir("%s/protobuf-c" % compilation_dir)
os.system("./autogen.sh")
os.system("./configure")
os.system("make protobuf-c/libprotobuf-c.la -j 4")
os.system("mkdir bin")
# Install the library
install_cmd = './libtool install /usr/bin/install'
os.system("%s -c protobuf-c/libprotobuf-c.la `pwd`/bin" % install_cmd)
os.system("rm -f `pwd`/bin/*so*")
else:
print("Skipping protobuf-c compilation")
print("Compiling MQTT library")
# Move to the MQTT Embedded library
os.chdir("%s/paho.mqtt.embedded-c" % compilation_dir)
os.system("make -j 4")
os.system("make install")
print("Compiling TTN Connector library")
# Move to the TTN Connector library
os.chdir("%s/ttn-gateway-connector" % compilation_dir)
os.system("cp config.mk.in config.mk")
os.system("make -j 4")
# Copy it to the /usr/lib directory for usage
os.system("cp %s/ttn-gateway-connector/bin/libttn-gateway-connector.so"
" /usr/lib" % compilation_dir)
# Move to the packet forwarder itself
os.chdir("%s/packet_forwarder/mp_pkt_fwd" % compilation_dir)
# Compile it
os.system("make -j 4")
# And move this up one directory for the user to run
os.system("cp %s/packet_forwarder/mp_pkt_fwd/mp_pkt_fwd "
"/opt/iotloragateway/iot-lora-gateway" % compilation_dir)
# Move to the directory with all of our template configuration files
os.chdir("%s/iot-lora-gateway" % compilation_dir)
# Create folders on the SD Card's boot, this will get ignored if it all exists
os.system("mkdir %s" % boot_dir)
os.system("mkdir %s" % confs_dir)
# Copy all of the template files over
configFiles = ["EU-global_conf.json",
"AS1-global_conf.json",
"AS2-global_conf.json",
"AU-global_conf.json",
"IN-global_conf.json",
"KR-global_conf.json",
"US-global_conf.json"]
for configFile in configFiles:
os.system("cp %s/iot-lora-gateway/template_configs/%s %s/%s"
% (compilation_dir, configFile, confs_dir, configFile))
# Copy over the local config files
os.system("cp %s/iot-lora-gateway/template_configs/local_conf.json.template "
"%s/local_conf.json.template" % (compilation_dir, confs_dir))
# And copy over the service files
os.system("cp %s/iot-lora-gateway/template_configs/iot-lora-gateway.service "
"/lib/systemd/system/iot-lora-gateway.service" % compilation_dir)
# Copy over the correct reset script into the /opt directory
if(modelUsed == "Raspberry"):
os.system("cp %s/iot-lora-gateway/template_configs/start-rpi.sh "
"%s/iot-lora-gateway-reset.sh" % (compilation_dir, base_dir))
if(modelUsed == "Rockchip"):
os.system("cp %s/iot-lora-gateway/template_configs/start-tinker.sh "
"%s/iot-lora-gateway-reset.sh" % (compilation_dir, base_dir))
if(modelUsed == "ODRID-C2"):
os.system("cp %s/iot-lora-gateway/template_configs/start-odroidc2.sh "
"%s/iot-lora-gateway-reset.sh" % (compilation_dir, base_dir))
# if raspberry Pi enable the SPI bus and set the core clock to 250mhz
if(modelUsed == "Raspberry"):
os.system("raspi-config nonint do_spi 0")
os.system("raspi-config nonint set_config_var "
"core_freq 250 /boot/config.txt")
# Reload systemctl daemon and enable the service
os.system("systemctl daemon-reload")
os.system("systemctl enable iot-lora-gateway.service")
# Copy the configuration script to /usr/local/bin
shutil.copyfile("%s/iot-lora-gateway/iot-lora-configure" % compilation_dir,
"/usr/local/bin/iot-lora-configure")
st = os.stat("/usr/local/bin/iot-lora-configure")
os.chmod("/usr/local/bin/iot-lora-configure", st.st_mode | 0o111)
print('''
___ ___ _____ _ ___ ___ _
|_ _/ _ \_ _| | | ___| _ \__ _ / __|__ _| |_ _____ __ ____ _ _ _
| | (_) || | | |__/ _ \ / _` | | (_ / _` | _/ -_) V V / _` | || |
|___\___/ |_| |____\___/_|_\__,_| \___\__,_|\__\___|\_/\_/\__,_|\_, |
|__/
Congratulations the gateway software is now fully installed!
You need to edit the configuration file for your gateway to be setup which
is located at /boot/iotloragateway/
You can either do this using a text editor or run "sudo iot-lora-configure" for our
wizard based editor.
After rebooting your Raspberry Pi your gateway should be up and running.
''')
# File end