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 #Environment Variables
##Required global variables ##Required global variables
* GW_TYPE required
* GW_ID required * GW_ID required
* GW_KEY required * GW_KEY required
* GW_CONTACT_EMAIL required - default an empty string * GW_CONTACT_EMAIL required - default an empty string
The gateway owner's contact information. The gateway owner's contact information.
##Optional global variables ##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 * GW_GPS optional - default False
* If True, use the hardware GPS. * If True, use the hardware GPS.
* If False, * 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 # Endless loop to reset and restart packet forwarder
while True: while True:
# Reset the gateway board # Reset the gateway board - this only works for the Raspberry Pi.
GPIO.setmode(GPIO.BCM) # hardware pin numbers, just like gpio -1 GPIO.setmode(GPIO.BOARD) # hardware pin numbers, just like gpio -1
if (os.environ.get("GW_TYPE")=="imst-ic880a-spi"): if (os.environ.get("GW_RESET_PIN")!=""):
print ("[TTN Gateway]: Toggling reset pin on IMST iC880A-SPI Board") 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.setup(22, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(22, 0) GPIO.output(22, 0)
time.sleep(0.1) time.sleep(0.1)
@ -264,11 +280,9 @@ while True:
time.sleep(0.1) time.sleep(0.1)
GPIO.output(22, 0) GPIO.output(22, 0)
time.sleep(0.1) time.sleep(0.1)
GPIO.input(22)
GPIO.cleanup(22) GPIO.cleanup(22)
#TODO: reset other gateway boards
# Start forwarder # Start forwarder
subprocess.call(["./mp_pkt_fwd"]) subprocess.call(["./mp_pkt_fwd"])
time.sleep(15) time.sleep(15)