2019-10-08

Setup TTN Gateway using Raspi3 with RAK831 and converter board

Finally I was able to put my TTN Gateway into operation.


The first attempt a few month ago failed and therefore the project was on hold until now. An article in make 03/2019 gave me the impetus for a new attempt.

My essential setup steps:
  1. Put the parts together.
    Caution: Do not power up the RAK831 card without connecting the antenna.
  2. Prepare a SDCard with a Raspberry Image - I use "Raspbian Buster with desktop" (Release date: 2019-09-26, Kernel 4.19)
  3. Perform a general update
    sudo apt-get update && sudo apt-get upgrade
  4. Enable SPI using raspi-config
  5. Clone the ttn gateway repo
    git clone https://github.com/ttn-zh/ic880a-gateway.git
  6. Run the setup script
    cd ic880a-gateway
    sudo ./install.sh
  7. Register the gateway on TTN website
After the restart I check the service status:

pi@ttn-gateway:~ $ systemctl status ttn-gateway
● ttn-gateway.service - The Things Network Gateway
   Loaded: loaded (/lib/systemd/system/ttn-gateway.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Tue 2019-10-08 14:05:42 CEST; 779ms ago
  Process: 346 ExecStart=/opt/ttn-gateway/bin/start.sh (code=exited, status=1/FAILURE)
 Main PID: 346 (code=exited, status=1/FAILURE)

ttn-gw ttn-gateway[346]: INFO: Statusstream data is enabled
ttn-gw ttn-gateway[346]: INFO: Beacon is disabled
ttn-gw ttn-gateway[346]: INFO: Monitor is disabled
ttn-gw ttn-gateway[346]: INFO: Contact email configured to "my email"
ttn-gw ttn-gateway[346]: INFO: Description configured to "ttn-rak831"
ttn-gw ttn-gateway[346]: INFO: Successfully contacted server router.eu.thethings.network
ttn-gw ttn-gateway[346]: INFO: [main] Starting the concentrator
ttn-gw ttn-gateway[346]: ERROR: [main] failed to start the concentrator
ttn-gw systemd[1]: ttn-gateway.service: Main process exited, code=exited, status=1/FAILURE
ttn-gw systemd[1]: ttn-gateway.service: Failed with result 'exit-code'.

Damn - the same problem as at first try! :-(

An issue thread on github list some possible reasons, among other "the wiring might be wrong". You may also interpret it as "other then expected or as default" and this was the key. On another page about the setup I found the crucial clue: The converter board uses a different reset pin (it use pin 17 instead of 25).

After changing the corresponding setting in /opt/ttn-gateway/bin/start.sh
#! /bin/bash

# Reset iC880a PIN
# SX1301_RESET_BCM_PIN=25
SX1301_RESET_BCM_PIN=17
echo "$SX1301_RESET_BCM_PIN"  > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$SX1301_RESET_BCM_PIN/direction

... it worked as expected. And I see the status "connected" on the TTN console (on TTN website).

To enable the GPS module I have to:
  1. Disable the serial login shell but keep the serial interface enabled - via raspi-config - interface setup.
  2. add the following lines to /opt/ttn-gateway/bin/local_conf.json
    "gps_tty_path": "/dev/ttyS0",
    "fake_gps": false,
    
  3. Reboot and check if it works (it may take some minutes to fetch the GPS position)
    pi@ttn-gateway:/opt/ttn-gateway/bin $ sudo tail -f /var/log/syslog | grep -i gps
    Oct  8 17:55:36 ...: INFO: GPS serial port path is configured to "/dev/ttyS0"
    Oct  8 17:57:39 ...: INFO: GPS is enabled
    Oct  8 17:57:39 ...: INFO: Using real GPS if available.
    Oct  8 17:57:39 ...: INFO: [main] TTY port /dev/ttyS0 open for GPS synchronization
    Oct  8 17:57:39 ...: INFO: GPS thread activated.
    Oct  8 17:57:39 ...: WARNING: [gps] GPS out of sync, keeping previous time reference
    Oct  8 17:57:39 ...: WARNING: [gps] GPS out of sync, keeping previous time reference
    Oct  8 17:57:39 ...: WARNING: [gps] GPS out of sync, keeping previous time reference
    Oct  8 17:57:39 ...: WARNING: [gps] GPS out of sync, keeping previous time reference
    Oct  8 17:57:39 ...: ### [GPS] ###
    Oct  8 17:57:39 ...: # Valid gps time reference (age: 0 sec)
    Oct  8 17:57:39 ...: # System GPS coordinates: latitude 50.94322, longitude 7.37443, altitude 272 m
    Oct  8 17:57:39 ...: ### [GPS] ###
    Oct  8 17:57:39 ...: # Valid gps time reference (age: 0 sec)
    Oct  8 17:57:39 ...: # System GPS coordinates: latitude 50.94322, longitude 7.37443, altitude 274 m
    
Used hardware:

Raspi3

The converter board with GPS support

RAK831 module

On the left side: 
top - the TTN antenna
bottom - the GPS module (optional)

Connection of the GPS signal

Update: The wiring of the converter board is available on the RAK website.

2019-07-14

Update: ESP8266 based SensorNode V2

I updated the circuit and pcb design of my Esp based SensorNode.
Further details in the github repository.

ESP Programmer

I put together an adapter board to attach a CP2104 board to ESP8266 and provide auto programming mode.


For further details see the github repository.

2019-04-29

ESP8266 based SensorNode

In last weeks I put together a Sensor-Node based on ESP8266. The software part provides:
  • the standard WiFiMonitor to setup the WiFi credentials
  • a web page to configure the connected sensors
  • a web service to read the configuration and current sensor values
  • the data are published via MQTT in a format to be feed into a influxdb
The following sensors are supported:
  • DS18B20 (multiple)
  • BME280
  • Si7021

SensorNode config page
SensorNode configuration page

I designed a board to be put into a USB port with a temperature and a humidity sensor. 
SensorNode circuit
SensorNodeUSB circuit

SensorNode pcb bottom side
SensorNodeUSB PCB bottom side

SensorNode pcb top side
SensorNodeUSB PCB top side
More information can be found in the GitHub repo SensorNode.




2018-03-25

ESP8266 - Convert from human readable date/time to epoch timestamp in Lua

For my current ESP8266 NodeMCU project I need a Lua function to convert the date/time returned by the DS3231 to epoch timestamp.

Update: I also wrote a function to verify the validity of the input parameter (see this github gist)

2017-01-07

Wifi Scanner with ESP8266 + TFT ST7735B (NodeMCU)

After successful connect the ESP8266 with the ST7735 display I want to do more than the demo - so here comes a Wifi Scanner.

Same hardware setup as in the previous blog post.



And here is the source code:

2017-01-02

ESP8266 (NodeMCU) + 1.8 Inch TFT LCD Display Modul 128X160 SPI Serial ST7735B

Some notes how to connect a "1.8 Inch TFT LCD Display Modul 128X160 SPI Serial ST7735B IC SD Card für Arduino" to a ESP8266 running with NodeMCU.




You need a NodeMCU firmware with (at least) the modules bit and UCG (with st7735 display option).

NodeMCU custom build  options.

NodeMCU custom build
options.
[Update] Also SPI must be selected! (Thanks to Lorenz)


Pinout/Connection

The display has a 8-pin and 16-pin interface. The TFT interface in both are the same. You can choose either of the two interfaces for wiring.

     ESP8266 --             DISP             -- ESP8266
     OPTION 1                                   OPTION 2
                 --------------------------
                |      ST7735B 1.8 TFT     |
                |                          |
         GND -- | GND  (1)                 |
         3V3 -- | VCC  (2)                 |
                | NC   (3)                 |
         3V3 -- | BL   (4)         (1) RST | -- GPIO16 (D0)
                | NC   (5)         (2) CS  | -- GPIO15* (D8) 
GPIO16  (D0) -- | RST  (6) TFT     (3) D/C | -- GPIO02 (D4)
GPIO02  (D4) -- | RS   (7) TFT     (4) DIN | -- GPIO13 (D7)
GPIO13  (D7) -- | SDA  (8) TFT     (5) CLK | -- GPIO14 (D5)
GPIO14  (D5) -- | SCK  (9) TFT     (6) VCC | -- 3V3
GPIO15* (D8) -- | CS   (10)TFT     (7) BL  | -- 3V3
                | CLK  (11)SD      (8) GND | -- GND
                | MISO (12)SD              |
                | MOSI (13)SD              |
                | CS   (14)SD              |
                | NC   (16)                |
                | NC   (15)                |
                 --------------------------

*) pull-down 10k to GND

ESP8266 NodeMCU dev board connected to 16pin interface of TFT
ESP8266 NodeMCU dev board connected to 8pin interface of TFT

Test

I use the GraphicsTest.lua to test the connection. GraphicsTest is part of the NodeMCU examples (you have to upload also all GT_*.lua files to run the test).