RAK831 TTN Gateway Monitoring

Having setup an outdoor gateway for The Things Network I was worried about it being exposed to the sun during the day. I built an aluminium shade for it but I even with it, I feared it might get too hot under the sun even in the winter. The RAK 831 and the Rasperry Pi are housed inside a plastic box with no ventilation, and they both require some cooling. It was obviously asking for trouble on the long term, so I needed a way to monitor the temperature. Ideally, they should be inside a metal box wich also acts as a heatsink, but that needed to wait.

I already had another Raspberry Pi running Node-Red to monitor and control some other things around the house so the plan was obvious. I would add another tab to the existing dashboard with a temperature graph.

Raspberry Pi Temperature

The ARM processor on the Raspberry Pi board offers a lot of information about itself, including the core temperature. The temperature reading can be requested from the Raspbian command line with the simple command:

pi@rbarriosgw:~/temperature $ vcgencmd measure_temp

We can strip the unnecessary characters and send via http just the value to the Node-Red Raspberry, and do it every 1800 seconds with the following python script:

# monitor-temp.py
import os, time, urllib
def measure_temp():
      temp = os.popen("vcgencmd measure_temp").readline()
      temp = temp.replace("temp=","")
      temp = temp.replace("'C","")
      params = urllib.urlencode({'temp': temp})
      f = urllib.urlopen("", params)
while True:

Now we add the following line to /etc/rc.local to launch the script on boot:

(sleep 10; python /home/pi/temperature/monitor-temp.py)&

The following Node-Red flow listens for incoming temperature readings and displays them in a chart:

Click on the picture to download the flow.

Monitoring Traffic Through the Gateway

It is easy to add a graph with the traffic going through your gateway, in my case I was interested in knowing the number of messages per hour. To do this, we dump the network traffic to the other Raspberry Pi and we count the number of relevant messages in Node-Red.

As before, we add the following line to etc.rc so it starts to run when the system boots up:

sudo tcpdump port 1700 -s 500 -U -n -t -w - -i eth0 | nc 5659 &

In Node-Red, we need to receive that dumped traffic. There are many status messages sent to TTN by the gateway, and we are not interested in them so we need to filter them out. We detect those packets because they contain the string "rxpk", and we count the number of appearances:

Click on the picture to download the flow.

The graph and conclusions

Having everything correctly setup and after a few days of data, I could see a clear pattern on temperature vs traffic that repeats everyday:

There seemed to be a clear relationship between temperature and traffic. I thought that the gateway was performing poorly under the sun, with high temperatures. It turns out, it has nothing do with temperature, the reason is there are many vampire nodes around here that only run at night...

Roberto Barrios, EB4EQA