Skip to content

Commit

Permalink
Added Raspberry Pi + IMST build and pin-reset flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Gourlaouen committed May 11, 2017
1 parent b3a0465 commit 395377b
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,22 @@ kerlink-iot-station-pktfwd:
paths:
- release/

imst-rpi-pktfwd:
stage: build
image: "ubuntu:xenial"
script:
- pushd $GOPATH/src/github.com/TheThingsNetwork/packet_forwarder
- apt install -y gcc-arm-linux-gnueabi # Installing cross-compiler
- GOOS=linux GOARM=7 GOARCH=arm PLATFORM=imst_rpi CFG_SPI=native CC=arm-linux-gnueabi-gcc make build
- cp scripts/rpi/install-systemd.sh release
- popd
artifacts:
paths:
- release/

sign:
before_script: []
after_script: []
only:
- develop@thethingsnetwork/packet_forwarder
- master@thethingsnetwork/packet_forwarder
Expand All @@ -97,6 +111,7 @@ sign:

azure-binaries:
before_script: []
after_script: []
only:
- develop@thethingsnetwork/packet_forwarder
- master@thethingsnetwork/packet_forwarder
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ Installation manuals are available for main available gateways:

+ [Kerlink IoT Station installation manual](docs/INSTALL_INSTRUCTIONS/KERLINK.md)
+ [Multitech Conduit installation manual](docs/INSTALL_INSTRUCTIONS/MULTITECH.md)
+ [Raspberry Pi + IMST ic880a installation manual](docs/INSTALL_INSTRUCTIONS/IMST_RPI.md)

## <a name="build"></a>Build

If you have a custom-made gateway, or if you want to contribute to the development of the packet forwarder, you will have to build the binary yourself.

+ [Kerlink IoT Station build instructions](docs/INSTALL_INSTRUCTIONS/KERLINK.md#build)
+ [Multitech Conduit build instructions](docs/INSTALL_INSTRUCTIONS/MULTITECH.md#build)
+ [Raspberry Pi + IMST ic880a build instructions](docs/INSTALL_INSTRUCTIONS/IMST_RPI.md#build)
+ [SPI environment build instructions](docs/INSTALL_INSTRUCTIONS/SPI.md)
+ [FTDI environment build instructions](docs/INSTALL_INSTRUCTIONS/FTDI.md) *(Experimental)*

Expand Down
8 changes: 8 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ var startCmd = &cobra.Command{
ctx.WithField("File", traceFilename).Info("Trace writing active for this run")
}

if pin := config.GetInt("reset-pin"); pin != 0 {
ctx.WithField("ResetPin", pin).Info("Reset pin specified, resetting concentrator...")
if err := pktfwd.ResetPin(pin); err != nil {
ctx.WithError(err).Fatal("Couldn't reset pin")
}
}

ttnConfig := &pktfwd.TTNConfig{
ID: config.GetString("id"),
Key: config.GetString("key"),
Expand Down Expand Up @@ -83,6 +90,7 @@ func init() {
startCmd.PersistentFlags().String("gps-path", "", "The file system path to the GPS interface, if a GPS is available (example: /dev/nmea)")
startCmd.PersistentFlags().Int64("downlink-send-margin", getDefaultDownlinkSendMargin(), "The margin, in milliseconds, between a downlink is sent to a concentrator and it is being sent by the concentrator")
startCmd.PersistentFlags().String("run-trace", "", "File to which write the runtime trace of the packet forwarder. Can later be read with `go tool trace <trace_file>`.")
startCmd.PersistentFlags().Int("reset-pin", 0, "GPIO pin associated to the reset pin of the board")
startCmd.PersistentFlags().BoolP("verbose", "v", false, "Show debug logs")

viper.BindPFlags(startCmd.PersistentFlags())
Expand Down
76 changes: 76 additions & 0 deletions docs/INSTALL_INSTRUCTIONS/IMST_RPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Install the TTN Packet Forwarder on a Raspberry Pi with an IMST ic880a board

To follow this manual, you must have a Raspberry Pi with an IMST ic880a board, connected through SPI.

## Download and run

1. Download the [Raspberry Pi + IMST build](https://ttnreleases.blob.core.windows.net/packet_forwarder/master/imst-rpi-pktfwd.zip) of the packet forwarder.

2. Configure the packet forwarder:

```bash
$ <packet-forwarder-binary> configure
[...]
INFO New configuration file saved ConfigFilePath=/root/.pktfwd.yml
```

3. Run the packet forwarder:

```bash
$ <packet-forwarder-binary> start
```

### Permanent installation with systemd

If you want a permanent installation of the packet forwarder on your Raspberry Pi, with `systemd` managing the packet forwarder on the background, we provide a basic systemd installation script, `install-systemd.sh`.

1. Select the build, and copy it in a permanent location - such as `/usr/bin`.

2. Create a configuration file in a permanent location, such as in a `/usr/config` directory:

```bash
$ touch /usr/config/ttn-pkt-fwd.yml
```

3. Set up this configuration file:

```bash
$ <packet-forwarder-binary> configure /usr/config/ttn-pkt-fwd.yml
```

4. Use the `install-systemd.sh` script, with the binary as a first argument and the config file as a second argument:

```bash
$ ./install-systemd.sh <packet-forwarder-binary-path> <configuration-file-path>
./install-systemd.sh: Installation of the systemd service complete.
```

5. Reload the systemd daemon, and start the service:

```bash
sudo systemctl daemon-reload
sudo systemctl enable ttn-pkt-fwd
sudo systemctl start ttn-pkt-fwd
```

## <a name="build"></a>Build

If want to contribute to the development of the packet forwarder, you might want to build the TTN Packet Forwarder. You will need to use a Linux environment to run the toolchain necessary for the build.

### Getting the toolchain

If you want to build the packet forwarder for a Raspberry Pi, you will need a **Raspberry Pi cross-compiler**. On some Linux distributions, such as Ubuntu, a toolchain is available as a package: `sudo apt install gcc-arm-linux-gnueabi -y`.

### Building the binary

Make sure you have [installed](https://golang.org/dl/) and [configured](https://golang.org/doc/code.html#GOPATH) your Go environment.

Follow these commands:

```bash
$ make dev-deps
$ make deps
$ GOOS=linux GOARCH=arm GOARM=7 CC=gcc-arm-linux-gnueabi make build
```

The binary will then be available in the `release/` folder.
30 changes: 30 additions & 0 deletions pktfwd/gpio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package pktfwd

import (
"time"

"github.com/pkg/errors"
"github.com/stianeikeland/go-rpio"
)

const gpioTimeMargin = 100 * time.Millisecond

// ResetPin resets the specified pin
func ResetPin(pinNumber int) error {
err := rpio.Open()
if err != nil {
return errors.Wrap(err, "couldn't get GPIO access")
}

pin := rpio.Pin(uint8(pinNumber))
pin.Output()
time.Sleep(gpioTimeMargin)
pin.Low()
time.Sleep(gpioTimeMargin)
pin.High()
time.Sleep(gpioTimeMargin)
pin.Low()
time.Sleep(gpioTimeMargin)

return errors.Wrap(err, "couldn't close GPIO access")
}
47 changes: 47 additions & 0 deletions scripts/rpi/install-systemd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

if [[ -z "$1" ]] ; then
# No binary specified
echo "$0: No binary specified."
exit 1
fi

binary="$1"
binary_name=`basename "$binary"`
binary_directory=`dirname "$binary"`
pushd "$binary_directory"
absolute_binary_directory="$(pwd)"
absolute_binary_path="$absolute_binary_directory/$binary_name"
popd

config="$2"

if [[ -z "$config" ]] ; then
echo "$0: No configuration file to use specified."
exit 1
fi

config_name=`basename "$config"`
config_directory=`dirname "$config"`
pushd "$config_directory"
absolute_config_directory="$(pwd)"
absolute_config_path="$absolute_config_directory/$config_name"
popd

echo "[Unit]
Description=TTN Packet Forwarder Service
[Install]
WantedBy=multi-user.target
[Service]
TimeoutStartSec=infinity
Type=simple
TimeoutSec=infinity
RestartSec=10
WorkingDirectory=$absolute_binary_directory
ExecStart=$absolute_binary_path start --config=\"$absolute_config_path\"
Restart=always
BusName=org.thethingsnetwork.ttn-pkt-fwd" > /etc/systemd/system/ttn-pkt-fwd.service

echo "$0: Installation of the systemd service complete."
6 changes: 6 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@
"revision": "7538d73b4eb9511d85a9f1dfef202eeb8ac260f4",
"revisionTime": "2017-02-17T16:38:17Z"
},
{
"checksumSHA1": "dyI8tS2bXHlHpPIp6VGZ/HXKyJQ=",
"path": "github.com/stianeikeland/go-rpio",
"revision": "896db2ee1c7f95240dd6a09e56edf9cece107a34",
"revisionTime": "2015-12-08T00:50:14Z"
},
{
"checksumSHA1": "ZaU56svwLgiJD0y8JOB3+/mpYBA=",
"path": "golang.org/x/crypto/ssh/terminal",
Expand Down

0 comments on commit 395377b

Please sign in to comment.