Change the gpio pins to use physical numbering.

Also allow the reset physical pin number to be set via environment variable.
This commit is contained in:
jpmeijers 2017-03-05 00:17:50 +01:00
parent 0c7c1dfd62
commit 8511a94b25
2 changed files with 23 additions and 8 deletions

View File

@ -1,12 +1,13 @@
#Environment Variables
##Required global variables
* GW_TYPE required
* GW_ID required
* GW_KEY required
* GW_CONTACT_EMAIL required - default an empty string
The gateway owner's contact information.
##Optional global variables
* GW_RESET_PIN - default 22
The physical pin number on the Raspberry Pi to which the concentrator's reset is connected. If you followed the [TTN-ZH instruction](https://github.com/ttn-zh/ic880a-gateway/wiki), or used [Gonzalo Casas' backplane board](https://www.tindie.com/stores/gnz/), this is most likely pin number 22. As pin 22 is the default value, you do not need to define it in this case.
* GW_GPS optional - default False
* If True, use the hardware GPS.
* If False,

28
run.py
View File

@ -252,11 +252,27 @@ with open('local_conf.json', 'w') as the_file:
# Endless loop to reset and restart packet forwarder
while True:
# Reset the gateway board
GPIO.setmode(GPIO.BCM) # hardware pin numbers, just like gpio -1
# Reset the gateway board - this only works for the Raspberry Pi.
GPIO.setmode(GPIO.BOARD) # hardware pin numbers, just like gpio -1
if (os.environ.get("GW_TYPE")=="imst-ic880a-spi"):
print ("[TTN Gateway]: Toggling reset pin on IMST iC880A-SPI Board")
if (os.environ.get("GW_RESET_PIN")!=""):
try:
pin_number = int(os.environ.get("GW_RESET_PIN"))
print ("[TTN Gateway]: Resetting concentrator on pin "+os.environ.get("GW_RESET"))
GPIO.setup(pin_number, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(pin_number, 0)
time.sleep(0.1)
GPIO.output(pin_number, 1)
time.sleep(0.1)
GPIO.output(pin_number, 0)
time.sleep(0.1)
GPIO.input(pin_number)
GPIO.cleanup(pin_number)
except ValueError:
print ("Can't interpret "+os.environ.get("GW_RESET_PIN")+" as a valid pin number.")
else:
print ("[TTN Gateway]: Resetting concentrator on default pin 22.")
GPIO.setup(22, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(22, 0)
time.sleep(0.1)
@ -264,11 +280,9 @@ while True:
time.sleep(0.1)
GPIO.output(22, 0)
time.sleep(0.1)
GPIO.input(22)
GPIO.cleanup(22)
#TODO: reset other gateway boards
# Start forwarder
subprocess.call(["./mp_pkt_fwd"])
time.sleep(15)