Taming the RAK5146 / SX1303

Its been a while - but good things come to those who wait ;).

Trying to work out a new system you're unfamiliar with can be quite a challenge. In my case I got my first LoRaWAN concentrator along with some CubeCell HTCC-AB01 and tried to get them to work. It turned out - it was quite hit and miss. On the one hand, the firmware support for the RAK5146 with USB, GPS and LBT was not really ready yet - on the other hand, the CubeCell Arduino code has a fatal flaw with the preamble size so that those cannot join a LoRa network if used in EU868 MHz Band (the perfect fix by 1rabbit is linked as well!).

In the end, as I wanted to get this working as best as possible, I bought myself the RAK2287 Pi Hat and started modifying it. I was quite sure that the I2C signals should be available somewhere on that board - as well as 5V + 3v3 along with the raw PPS signal of the GPS module within the RAK5146. I was right and could bridge the PPS signal to an used RPi GPIO pin.

PPS Pin bridged to GPIO 04

Using the I2C signal lines, Ground and 3v3 I added an I2C sensor interface (call it an ugly QWIIC connector ;)).

PPS hack and "poor mans QWIIC connector added"

I installed the latest UDP Packet Forwarder package by Xose - and everything was working perfectly since then.

I even added brocaars Packet Multiplexer and started running a local ChirpStack instance on my home server. Now my sensors are feeding their data directly to my local InfluxDBv2 and Grafana - but at the same time my Gateway is still available for TTNv3 users to receive their data. Its awesome and with that I even receive my private data during WAN outages. Nice!

As added "bonus", my gpsTime project is running on the same RPi, using the GPS time of the RAK5146 and its PPS signal to be an extremely precise GPS timeserver in my network - and an additional BME280 is running as the "room sensor", because adding another battery operated device - if you are having more than enough CPU power (in form of the RPi ;)) is really not needed. The whole device fits behind the TV.

"Not Great, Not Terrible"

All in all, the project was very successful, I am working on some new ideas regarding the sensors, but this is pending on my KiCad 6 skills and deliveries of new RAK hardware currently on the way ;).

I still keep all infos in the balena Forums, so head over if you want more details.

LoRaWAN with RAKwireless RAK5146: The SX1303 in the field, a rocky start

Setting the scene

Working with the guys over at balena comes with some perks - including the peer pressure of getting into new technologies and trying them out. My go-to person this time was balena Developer Advocate Marc Pous - who is not only no stranger to soldering - but also deeply rooted in the LoRaWAN field (and he is also doing balenaHub projects for LoRaWAN applications 1, 2).

I heared about LoRaWAN a while back, when I was working with Sigfox - but never really gave it a try, other than trying to run a basestation for a certain satellite using LoRa for its communication.

This changed through Marcs constant LoRa presentations and work - I just gave in and wanted to try it. I had already three projects at hand: One was getting some BME280s into a network (because due to 2.4 GHz spectrum hell induced by too many neighbours with too many WiFi APs cranked to 11 using WiFi with ESP8266 did not work anymore...). This project would be the "first hello-world" to maybe be allowed to deploy a network in my company to care for our sensors - and lastly, strapping LoRa technology to a rocket and see whether we can muster the about 250 km+ downrange.

But things start small, so I wanted to get into the field with best-in-class technology - and the latest available products (especially thinking about ultra-long communications like on my last usecase). Luckily, the new Semtech SX1303 came to market 8 months ago and RAKwireless decided to make their first concentrator on its base, the RAKwireless Wislink RAK5146 - and I wanted to be an "early adopter".

Wrong expectations

If I am getting into a new product, I am used to finding a certain amount of good documentation, software and support. I must admit that I was really spoiled with my latest endeavors using Paul Stoffregens excellent Teensy series (loyal customer since Teensy 2.0/2010 ;)), some new STM32s and also NVIDIAs Jetson lineup.

So I went into this whole project with wrong expectations, as RAKwireless had made a ton of useful stuff available already for their older systems like the RAK2287 - and I thought everything would be in place for the new system as well, which was wrong.

I started the project more than a month ago and at that time not even a real firmware was available. The only project I found was this Github Repo - which could not even install for my RAK5146 USB because someone forgot the chmod +x on the install script, which gave a bad first impression regarding how tested this official project would be - and I was not disappointed, as I had to try to figure out how to get it working with TTN - because the important step (after the installation was done) to changing the server address in the configuration file - was not included in the setup instructions, so my gateway never connected.

Also, no RPi Hat was available - which brought me into looking for own solutions, which I found in an USB WWAN adapter card to be stacked onto the RPi.

A last thing which was confusing, especially with trying to figure out how to connect everything were the Pinout and Blockdiagram. I remind you, there are 6 different configurations of the RAK5146:

  • SPI (always without LBT)
    • with GPS
    • without GPS
  • USB
    • with LBT
      • with GPS
      • without GPS
    • without LBT
      • with GPS
      • without GPS

Both the Blockdiagram and Pinout for all these variations were handled in one graphic. While one could handle the block diagram, the pinout is just confusing. Which Pins are actually on the card using the USB version with LBT and GPS? What is going on with the SPI pins? Are they not even routed?

I tried to use my new TTNv3 gateway with Heltec Cubecells - and while I got it working, there was just unreliable data transmission and huge packet loss.

I must admit, I went to this project with wrong expectations - because I saw the RAK5146 now freely available on RAKwireless shop - thinking it should be another product like the RAK2287 - but that was wrong. It seems to be a product which is firstly marketed towards huge OEM customers - and not for the hackers at heart.

Moving forwards

To try to get this issues resolved, I wrote a bunch of PRs and Issues on the Github repo and documented my findings on balenas Forum. Luckily, those comments did not fall onto deaf ears and the situation improved:

RAKwireless worked in enhancing the documentation of the RAK5146 - but sadly the Blockdiagram and Pinout is still in the same state. Also, no quickstart guide was added.

Thanks to Taylor there is now a firmware package made available, which can be downloaded from the RAK5146 page.

Regarding the documentation on using it, this is not available yet. Please stick to the RAK2287 Quickstart guide. You can set it up as "RAK Gateway LoRa Concentrator" for TTN like shown there - but need to edit the packet-forwarder config afterwards (see the main menu of gateway-config) and replace the "server_address": "router.us.thethings.network" with your things network router (e.g. eu1.cloud.thethings.network in Europe TTNv3). You should then restart the Gateway / Forwarded. In adding it to the TTNv3 stack, the Quickstart guide is a bit outdated. You can still find out the EUI of your gateway using gateway-version and use this for adding it to TTNv3, but please be careful not to choose the frequency plan "Europe 863-870 MHz (SF9 for RX2 - recommended)" - but the RX2 SF12 option to improve the signal quality.

I still have problems with bad performance - and the helpful Jose Marcelino decided to send me a RPi Hat for switching out my contraption, which should improve quality. However, after waiting a month I have not yet received this Hat yet and could therefore not test.

Also Xose Pérez did try to help and I am grateful for both of them trying to resolve the situation and getting the RAK5146 also working in the hands of power users.

After all, it looks like an extremely capable platform - and I would really like to see it performing accordingly.

What is next?

Even though the start was a bit rocky, I want to continue working on this project - after all, my room sensors need some LoRa, as well as my other projects - and when these issues are resolved, thr RAK5146 looks like a good offer. I will report back on my blog with updates - and wait for the RPi Hat which hopefully will resolve the issues - or helping me pin down the issue, if it were to be somewhere else.

gpsTime

I think there is nothing more pleasing than having extremely precise measurements at your fingertips. Like time. While in the past it was quite problematic to measure time accurately (not talking about sundials, but... why not? ;)) - mankind has created one precise time source as the byproduct (read: "waste") for usage in accurate navigation: GNSS and their different kinds like GPS, Glonass, Galileo, BaiDou and others.

Taping into this time source and providing it to your local computer network via NTP has been done by countless people and is an extreme rewarding task. Is it necessary? Maybe not. Is it really cool? Yes. And now it is even easier as you don't need to configure it yourself, but can use the balenaHub and the preconfigured gpsTime project.

We do not waste time on fancy logos 😉

Basically you just need an RPi B+ (2/3/4), Micro SD Card, Powersupply and 3v3 TTL Level GPS Module with PPS Output. The rest is just done by going on the balenaHub entry shown above, creating a free account and flashing balenaOS onto your SD card, booting the RPi on the internet for the first time and let it get the needed containers. Afterwards you can use the RPi offline and still enjoy your precise time source.

A watterott CQM-M8Q Breakout and an good old RPi 2B+ are more than powerful enough

More details can be found in the Github Repo and you can work and improve that project to your hearts content. I am probably going to do an PiAndMore talk about it - and use the project myself as a block for precise timing in some support equipment.

[WSL2/Win10] Limit Resource Consumption of WSLv2

Windows Subsystem for Linux 2 has a big problem called "Vmmem" - it is the process WSL uses to allocate RAM for usage within its user context. That itself is all fine, however, there are many known issues that show that even after closing your e.g. Debian session, this memory is not returned to the system. This is also valid for usage of Docker for Windows within the WSLv2 context (meaning using Docker in the "new-style" install, not with the old HyperV machine).

The easy way to mitigate the pain (meaning RAM-being eaten up faster than a Chrome Engine spinning up ;)) is to just shutdown the WSL engine after usage, which you can do by opening up a Powershell or CMD with admin rights and enter

wsl --shutdown

This will shutdown WSL until you start it manually again. (Thanks smigel!)

A better way to work with this is to create a .wslconfig in your Windows User directory. Here is a short example.

[wsl2]
 memory=2GB # Limits VM memory in WSL 2 to 2 GB
 processors=2 # Makes the WSL 2 VM use two virtual processors
 swap=0 # Do not use a swap file

Anyway, the issue is still open and not yet fixed, even though a fix was promised on 17.06.2019. Worse, Microsoft locked the issue in July 2020 for "spam". Talking about bad customer experience...

[WSL2/Win10] Install WSLv2

1.) Open an administrative Powershell and activate the WSL feature

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

2.) Activate the Virtual Machine Platform, afterwards reboot your computer

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

3.) Download and install the WSLv2 Linux Kernel package from https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi - another Reboot is needed afterwards

4.) Set WSLv2 as default WSL - open an administrative Powershell and enter

wsl --set-default-version 2

5.) Install one or multiple operating systems in WSLv2 - you can find them here. You can also install these "offline", meaning without the need to use Windows Store. For the offline install, download the needed package from this link, then install it by doubleclicking on the Icon - or via Powershell with

Add-AppxPackage .\app_name.appx

You can then start and use it :).

Its also not a bad idea to install Windows Terminal.

Presentations with Markdown: revealjs

Being an active contributor to the PiAndMore and other conferences, I happen to make quite a few presentations a year. In the past I was using the good old Microsoft Powerpoint - which has its strengths, but also its drawbacks. Positioning text and graphics were never my taste (I use LaTeX, btw) - so I set out to find a new way to create presentations - and found revealjs back in 2018.

What is revealjs? Basically: Write your presentations in Markdown. Show in a Webbrowser - or export as PDF. TL;DR? Navigate through the demo.

However, using revealjs by its own was cumbersome, I was missing a live preview - and while all of this was available at its freemium service slides.com - I do not want to be dependant on online connection - nor share every presentation with the world (some might involve senstive data... so no).

That was when I started to use hacker-slides - a small Go implementation for all OS types, with a Live Preview, local/offline usage. It was near perfect, other than issues like having problems with carriage return and similar signs at some points (usage other Windows...) and some other stuff (I lost some presentations when I opened up too many at the same time and edited different presentations in different tabs). It was also the first project where I changed some Go code for my local copy. However, the final nail in the coffin was that this project is not really maintained anymore.

Enter vscode-reveal - it works in VSCode or Codium - has live preview and all the features you need. Your basic, local, revealjs powered, operating system independant presentation-making-machine.

I have used it for the latest PiAndMore - and I am not going back to anything else (at least for the time being) - so maybe you want to give it a try?

Use Sonarqube with sonar-cxx

Installation

  • Download SonarQube from https://www.sonarqube.org/downloads/
    • If you are using Java 8, you need to download SonarQube 6.7.x LTS (look for Historical Downloads on the website)
    • If you are using Java 11 - SonarQube 7.9.x LTS (look for Long term support area on the website)
  • Unpack the SonarQube ZIP file
  • Download the latest sonar-c-plugin.jar and sonar-cxx-plugin.jar from https://github.com/SonarOpenCommunity/sonar-cxx/releases
  • Insert both jar files into the SONARQUBE_HOME/extensions/plugins extensions directory (within the unpacked ZIP file)
  • Start SonarQube and Login
    • On Windows 10, e.g. via SONARQUBE_HOME/bin/windows-x86-64/StartSonar.bat
    • Go to http://127.0.0.1:9000 as soon as "SonarQube is up" is announced
    • Default login is user admin, password admin
  • Navigate to Administration -> Marketplace and make sure the plugins "C (Community)" and "C++ (Community)" are installed

Configuration - General

  • Additional configuration can be done under Administration -> Configuration -> General Settings within the "C (Community)" and "C++ (Community)" areas

Configuration - Quality Profiles

  • You need to enable for which kinds of problems both plugins should scan. This needs to be done initially, as otherwise they will not detect anything by default.
  • Example for C (Community)
    • Go to Quality Profiles, click on the downwards arrow next to the "Sonar way (Built-in)" profile within the "C (Community)" area. Click Copy. Give it a catchy name, like "Sonar way - C"
    • A new quality profile pops up, you see the Rules (Bugs, Vulnerabilities, Code Smells) in the left table. You can click "Activate more". In the next table, you see the rules sorted by the same types. You can click all three types on the left side and mark them this way - if you want and then click on "Bulk Change" and "Activate In "Sonar way - C"" to activate all rules within our newly created Quality Profile. You have to acknowledge the change and SonarQube will report back as soon as the changes are done.
    • You can now navigate back to Quality Profiles, click on the downwards arrow next to the "Sonar way - C" profile within the "C (Community)" area and click on "Set as Default".
    • With this change, your newly created profile will now be used for the next scans.

Prepare first scan of C Code

# must be unique in a given SonarQube instance
sonar.projectKey=TestApplication
# defaults to 'not provided'
#sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Defaults to .
sonar.sources=.
#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
# project is c, please scan with c plugin (one needs to be enabled)
sonar.language=c
# project is c++, please scan with c++ plugin (one needs to be enabled)
#sonar.language=c++

First scan of C Code

  • Open up a shell within the project folder with the sonar-project.properties file
  • Within this shell, execute SonarScanner by starting its sonar-scanner exectubale, e.g. "D:\sonar-scanner-4.5.0.2216-windows\bin\sonar-scanner.bat"
  • The scanner will now work through the project and once its done, send the data to the SonarQube server, where it will be computed and shown as project

More infos