element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Blog Set up Elecrow TTN LoRaWAN gateway on Raspberry Pi - Pt. 2: full install and run as service
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Internet of Things to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 29 Dec 2023 8:24 PM Date Created
  • Views 4329 views
  • Likes 7 likes
  • Comments 18 comments
  • raspberry
  • the things network
  • lorawan
  • ttn
  • gateway
  • iot
Related
Recommended

Set up Elecrow TTN LoRaWAN gateway on Raspberry Pi - Pt. 2: full install and run as service

Jan Cumps
Jan Cumps
29 Dec 2023
Set up Elecrow TTN LoRaWAN gateway on Raspberry Pi - Pt. 2: full install and run as service

In part 1,  Set up Elecrow TTN LoRaWAN gateway on Raspberry Pi - Pt. 1: build and test , I compiled the software for the Elecrow LoRaWAN gateway (see  Low-Cost LoRaWAN Gateways! ), and enabled the gateway on The Things Network (TTN). I used Raspberry OS bullseye 32-bit lite on a Raspberry Pi  A+. I tested this on a B+ with the same OS too.

In part 2, the software gets properly installed, and I configure it as a systemd service.

image

Install the software.

I'm going to install it in a bin folder of the user that will run the service (jancumps).

Instructions are on GitHub: SX1302 LoRa Gateway project - 4.2. Install executables and associated files in one directory:

mkdir ~/sx1302_hal

mkdir ~/sx1302_hal/bin

Then navigate to the build folder from post 1 and edit the install config file 

cd LR1302_loraWAN

cd LR1302_HAL

cd sx1302_hal

nano target.cfg

Check that the right folder and user are configured. Don't use the relative user path, but the full one.

image

Then it's time for installing the software in the bin folder we just created. It's worth investigating how to set up ssh certificate logon for localhost, or you'll have to type your password a lot of times. See the link at the start of this section for instructions.

Then install the binaries and config:

make install

make install_conf

Different than the instructions:

cd ~/sx1302_hal/bin

chmod +x reset_lgw.sh

The application is now installed.

Test: 

./lora_pkt_fwd -c global_conf.json.sx1250.EU868

success:

image

Install and run as a daemon

The instructions are also on Github: How to auto-start the with systemd.

In your build directory, there is a script file:

cd ~/LR1302_loraWAN/LR1302_HAL/sx1302_hal/tools/systemd

nano lora_pkt_fwd.service

Adapt to the directory structure and user for your install. If you followed my instructions, you should only check the home folder.

I also tell systemd what group and user name to run this particular service under:

User=jancumps
Group=jancumps

image

Then copy the service file, register it, and enable:

sudo cp lora_pkt_fwd.service /etc/systemd/system

sudo systemctl daemon-reload

Before starting the service, let's redirect the output, so we can monitor it

sudo cp lora_pkt_fwd.conf /etc/rsyslog.d

sudo systemctl restart rsyslog

Start a second console to the Pi, to view the log (a new PuTTY session, or whatever Terminal program you use):

journalctl -u lora_pkt_fwd -f

Let it sit there. Any message from the service will show up there.

In the original terminal, enable and start the service;

sudo systemctl enable lora_pkt_fwd.service

sudo systemctl start lora_pkt_fwd.service

 

image

You can safely close all consoles now. Things will keep on running. Even after reboot. Executing this command at any time will show the log:

journalctl -u lora_pkt_fwd -f

And this will show the service status:

systemctl status lora_pkt_fwd.service

Enjoy

In theory, you don't need the build directory structure anymore ...

See also: Set up Elecrow TTN LoRaWAN gateway on Raspberry Pi - Pt. 3: manage the service log size 

  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to Jan Cumps

     Linux commands can turn a log into structured data (turn a TTN Gatesway log into a csv) 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to Jan Cumps

    I settled for this command (BAR is var):

    stdbuf -o0 tail -f /BAR/log/lora_pkt_fwd.log 2> /dev/null | stdbuf -i0 -o0 awk '/: INFO: Received pkt from mote:/ {print $1, $2, $3, $11,$12}' | stdbuf -i0 -o0 cut -d ' ' -f 1,2,3,4,5 --output-delimiter=';' | stdbuf -i0 -o0 sed 's/(fcnt=//g' | stdbuf -i0 -o0 sed 's/)//g' | stdbuf -i0 -o0 tee output.csv

    image

    It writes both to the console and an output .csv file

    Kudos to the Linux command line tools. They manage to fish that out of megabytes of log file that look like this:

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz

    Some funky commands. 

    List all things that uplinked, and their message counters (BAR is actually var, but the forum doesn't accept slashvarslash)

    cat /BAR/log/lora_pkt_fwd.log | awk '/: INFO: Received pkt from mote:/ {print $11,$12}'

    image

    monitor the log file, only showing date, time, thing and counter: (again, replace BAR with var), as they happen

    tail -f /BAR/log/lora_pkt_fwd.log 2> /dev/null | awk '/: INFO: Received pkt from mote:/ {print $1, $2, $3, $11,$12}'

    image

    Turn the log into a csv:

    cat /BAR/log/lora_pkt_fwd.log | awk '/: INFO: Received pkt from mote:/ {print $1, $2, $3, $11,$12}' | cut -d ' ' -f 1,2,3,4,                                                                                       5 --output-delimiter=';' | sed 's/(fcnt=//g' | sed 's/)//g'

    image

    Or monitor real time to csv:

    tail -f /BAR/log/lora_pkt_fwd.log 2> /dev/null | awk '/: INFO: Received pkt from mote:/ {print $1, $2, $3, $11,$12}' | cut -d ' ' -f 1,2,3,4,5 --output-delimiter=';' | sed 's/(fcnt=//g' | sed 's/)//g'https://community.element14.com/technologies/internet-of-things/b/blog/posts/set-up-elecrow-ttn-lorawan-gateway-on-raspberry-pi---pt-2-full-install-and-run-as-service?CommentSortBy=CreatedDate&CommentSortOrder=Ascending#

    Each time,  > filename can be appended to write to a file instead of console.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 1 year ago in reply to Jan Cumps

    Good find! I think for the application I had, I will prefer the Linux log parser, so will use that as a basis, but can see that visibility of logs derived from TTN could be useful for other purposes too.

    I've been going down a rabbit hole this weekend so far, experimenting with antenna stuff for broadcast FM band. But hopefully some of the findings will be useful for LoRa experimentation eventually since the principles are the same, just higher frequency..!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to shabaz

     shabaz , I found a package that allows to get gateway stats from TTN.: https://github.com/bertrik/ttn-gateway-collector

    It will log all TTN relevant* traffic of your gateway to a CSV file. It doesn't need to run on the gateway because it gets the data from the TTN cloud. 


    image
    image; I configured and ran this on an Ubuntu laptop. Works good.

    * that is the big difference between this utility and my linux log parser on the gateway. That one logs all traffic. Even if it receives joins and uplinks of Things that aren't TTN. But that has to run on the gateway - or have access to the gateway's log file.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube