forked from TheThingsArchive/packet_forwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Raspberry Pi + IMST build and pin-reset flag
- Loading branch information
Eric Gourlaouen
committed
May 11, 2017
1 parent
b3a0465
commit 395377b
Showing
7 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters