ADR plugin creation example

I am confused about the ADR plugin system. Is there anyone who can implement a new ADR plugin successfully? If so, can you share a tutorial about it? I know there are some entries about ADR plugins but I actually need a step-by-step tutorial. I appreciate it if you help.

Have you seen chirpstack-network-server/main.go at master · brocaar/chirpstack-network-server · GitHub? The adr.HandleRequest param provides you with the uplink context, the adr.HandleResponse return value defines the desired state of the device. Everything in-between is up to you to implement :slight_smile:

This is the default ADR implementation which is already embedded:

Thank you for your response and yes, I see that topic as I said before. And I can modify that algorithm.

However, now I am using chripstack NS on my computer, and I do not know how can update the algorithm with my new algorithm. Should I install NS from the source code. And then modify the code and then compile again or is there any simpler way. It is called as ADR plugin, so I thought that there is a way to update the ADR algorithm without recompiling. I checked .etc.chirpstack-network-server directory. There is only one setting file. So, I could not find anyway to update the default ADR algorithm. Can you explain me step-by-step so that I can run my own ADR algorithm.

  # ADR plugins.
  #
  # By default, the 'default' ADR algorithm is available. The number of available
  # ADR algorithms can be extended through plugins. This setting can be configured
  # to a list of one or multiple plugins.
  adr_plugins=[]

As far as I can tell you have to create a Go module based on chirpstack-network-server, compile it and “install” is so that I can be called systemwide, then you add that module’s name to the list of adr_plugins…

see Is there a way to customize the ADR algorithm for reference, also not a complete guide but has some hints…

ok I got it working, documentation is really the bare minimum so…

I installed the Go language, then I created a new mod:

mkdir my-new-mod
cd my-new-mod
go mod init my-new-mod

I copied the content from the adr example in main.go, changed relevant sections to “my-new-mod” and then I tried

go build

and followed what that put out:

go get github.com/brocaar/chirpstack-network-server/v3/adr
go get github.com/hashicorp/go-plugin@v1.4.0
go get my-new-mod

After that the build succeeded, I moved the my-new-mod binary to /usr/bin and edited the network server config toml:

adr_plugin=["my-new-mod"]
3 Likes

Alex, this is exactly what I need. I appreciate your help. Thank you.

There is no need to put the plugin in /usr/bin. You can configure the adr_plugin setting to the absolute path of the plugin binary :slight_smile:

Dear Alex9779,
I followed your steps and added the absolute path of the binary in adr_plugin section of chirpstack_network_server.toml file. But in the device profile section of the application server web interface, I am only able to select the default adr. Why there is no option to select my custom adr? appreciate it if you help.

Hmmmm I had no problems with that. Did you check the logs?

I copied the content from the adr example in main.go, changed relevant sections to “my-new-mod”

What does it mean changed relevant sections? I tried to follow this step by step by I get:
go: errors parsing go.mod:
go.mod:44:2: syntax error (unterminated block started at go.mod:14:1)