Registering an ABP device via the API

Hey all, back to TTN after quite a long hiatus and trying to solve a problem.

I have a node that I’ve developed using Micropython for various reasons around hardware compatibility.

Unfortunately, I’ve been unable to find a Micropython library that supports connecting via OTAA, so I’m stuck with ABP.

I’ve taken some code from elsewhere on this forum and updated it to use the appropriate API keys etc, and the device is being created without issue, however it’s always created as an OTAA device.

I’ve looked through the API reference, however I’m unable to see which field I need to set in order to switch from OTAA to ABP.

Obviously OTAA would be the preferred join method, but I have neither the time or expertise to update the Micropython LoRaWAN library that I’m using to add OTAA support.

Thanks in advance for any light you can shed on this!

Hey Matt, welcome back :slight_smile: ! Saw your ‘return’ originaly >year ago after Mockingbird and follow on biz but had noted you had been quite since… a year is a long time and feels even longer with the effects of pandemic and follow on!

No direct experience on this but :thinking: have you tried googling generally or using Forum search specifically and looking at anything done around either the PyCom devices (think micropython based) or recent activities using Raspberry Pi Pico boards - not great for a node but I know from from posts some have looked at (perhaps Nick @descartes or Leonel @bluejedi have some comments/direction wrt latter).

May help if you give additional disclosure wrt device hardware details used and more on

So we know where you come from and got to :slight_smile:

Yeah, good shout… :smiley:

The device is a Heltec WiFi LoRa 32 v2 with an MFRC522 RFID reader attached to it (hence the challenges around hardware - the support for MFRC522 in ESPIDF is shocking, but the support for TTN v3 in the Arduino Framework using SPI isn’t great either as I’ve been finding out! :frowning: )

The code has been taken from this post and amended slightly, but only to move it into a dedicated python function as opposed to a straightforward script.

I’m starting to think it’s something to do with the version_ids in the JSON, so I’m going to play around with that this evening and hopefully I can find out what’s causing this!

Can you be persuaded to use the CLI which can be called as a long command line from any number of languages?

The API is good for most things except it is not atomic on device creation and when it goes wrong (one of the calls fails or doesn’t get through or some such), it leaves sufficient cruft behind that you have to be very very careful about deleting what did make it in to the stack before trying again.

Hmmmm, I did wonder how reliable the API was given that the docs are basically a “reference” rather than an actual guide, and three separate calls are required just to create a new device.

I’d rather not shell out to run the cli as this is a DJango web application, but in the absence of the equivalent of an SDK like we had back in v2 if that’s the only option then I’ll have to explore it :frowning:

Far better to import requests in my eyes than subprocess :frowning:

It’s reliable as that’s how the web console works - but if you aren’t totally in the LoRaWAN groove and you are hacking on it all, it can get messy and other peeps tend to use their specially formatted id’s that they previously were unable to roll back.

I know you have the groove, and if it’s Django it’s not a tall order for me to get the right incantation of ABP - although all I do is register a device via the console with the developer tools open and snaffle the code from there, but as I’ve just got an LS300 that can only do ABP (as it uplinks to a satellite, just say’n, not boasting, well, not much), I will need ABP registration anyway.

More anon.

Oh, great idea, I’d not thought about intercepting the traffic!

The connection and endpoints are all fine, it’s just the make up of the JSON body I’m struggling with, so if I can grab that from the debug tools then I’m all good I think!


@descartes - thanks for putting me on the right track, I can now create ABP devices by calling each of the API endpoints in order and passing JSON that does NOT include the OTAA fields for join servers etc.

I’m now pulling the data back from the API for another part of the code and frustratingly I can’t seem to find anything about getting the application session key and network session key back in a format other than nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.

It’s frustrating, because I’m now having to work out how to convert that into the 0xnn needed for the bytearray in my code!

Ah well, half the battle won anyway! :smiley:

Welcome to my world! I’ve not seen any formatting of data options in the API.

But you can generate the keys yourself in the data structure of your choice and then format for the API call & your byte array.

Yeah, looks like that’s my option from now on.

As you may remember, when I was doing this stuff commercially I was running Chirpstack. One of the (many!) great things that they had was a solid example of using their Python SDK to connect to the API.

I’m not sure why TTN/TTI decided to stop releasing the SDK’s because it makes automating this stuff far harder and automation is how any company increases the value they provide to their customers, but it’s also not enough pain right now for me to go back to running my own Chirpstack setup!

I just had a brainwave that I could look at the javascript in the console that translates between the various formats and work out from there how to create a python version for myself, but the javascript is both minified and obfuscated… :frowning:

That’s not obfuscation, that’s the impenetrable output you get from the React framework. I would suggest that you look at the source code but the input to React is mostly magic incantations from those that have chosen to join The Church of Counter-Productive Programming.

I personally use and have done since the day that LiveScript was released and almost everyone can read & maintain my code. The only ones that can’t are the ones looking for the monolithic framework includes.


Ah, fair enough, I’m definitely not a front-end developer so assumed it had been obfuscated.

I’m going to log a ticket against the docs in the hope someone can at least “close - won’t fix” it with a comment about the actual formats used so I can try and get some more clues around it.

I’ll post back here if I get anywhere!

Improve documentation on API responses from the registration/network servers · Issue #960 · TheThingsIndustries/lorawan-stack-docs · GitHub logged

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.