diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 08c70a2..9323d96 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -31,6 +31,8 @@ Forward packets with a valid CRC. * GW_ANTENNA_GAIN optional - default 0. Set this to the dBd gain of your antenna. The dBd value is the dBi value minus 2.15dB, ie. dBd = dBi-2.15. This is used to reduce the TX power of the concentrator to stay within the legal limits. +* CAYENNE_SCRIPT optional + When this variable is set to a Raspberry Pi Cayenne monitoring script, the script will be downloaded and executed. This allows monitoring of your gateway on Cayenne. ##Server variables All server variables are optional, but when a server is enabled, it is recommended to set all variables to configure it completely. diff --git a/run.py b/run.py index 1b27fed..ad23880 100755 --- a/run.py +++ b/run.py @@ -7,6 +7,7 @@ Based on: https://github.com/rayozzie/ttn-resin-gateway-rpi/blob/master/run.sh import os import os.path import sys +import stat import urllib2 import time import uuid @@ -273,7 +274,21 @@ with open('global_conf.json', 'w') as the_file: the_file.write(json.dumps(local_conf, indent=4)) -# TODO: Cayenne monitoring script +# Cayenne monitoring script +""" +wget https://cayenne.mydevices.com/dl/rpi_lv7d88b029.sh +sudo bash rpi_lv7d88b029.sh -v +""" +if(os.environ.get("CAYENNE_SCRIPT")!=None): + try: + response = urllib2.urlopen(os.environ.get("CAYENNE_SCRIPT"), timeout=30) + cayenne_script = response.read() + with open('rpi_cayenne.sh', 'w') as the_file: + the_file.write(cayenne_script) + os.chmod('rpi_cayenne.sh', stat.S_IEXEC) + subprocess.call(["./rpi_cayenne.sh"]) + except urllib2.URLError as err: + print ("Unable to fetch Cayenne script") # Endless loop to reset and restart packet forwarder