JS Error on ChirpStack codec

Hi, I am encountering a JavaScript error while working with ChirpStack OS v4.5.4, raspberry pi Zero w and rak2287. The error description is as follows:

level:“ERROR”
code:“UPLINK_CODEC”
description:"JS error: Error: interrupted "

This issue arises when I use the following example codec functions:

function decodeUplink(input) {
return {
data: {
temp: 22.5
}
};
}

function encodeDownlink(input) {
return {
//bytes: [225, 230, 255, 0]
};
}

Could you please provide guidance on how to resolve this error? Any insights would be greatly appreciated.
Thank you!

I see nothing wrong with the code besides maybe the fact that encodeDownlink doesn’t have a proper return (which I’m sure you’ve tried multiple ways). Have you tried removing the encodeDownlink function entirely? It’s not strictly necessary, I never use it and just send hex from the UI to my devices directly.

Also incase you are unaware: the input given to the decodeUplink function has an input.bytes and an input.fPort property. You must take the input.bytes and extract the temperature yourself from the bytes. Clearly what you are doing is just a test case though.

It should be “temp”: 22.5?
Your codec is only for partial testing only as the value is hardcoded.

You may check the guide here.

I’m not sure about that, I have a codec with a return statement as such:

return {
     data: {
        serial: serial_number,
        soil_val: soil,
        battery_v: battery,
        hum: humidity,
        temp: airtemp
      }
    };

And it properly decodes the packets:

Couldn’t hurt to try though.

1 Like

Perhaps this is the solution: Trying to run Chirpstack on a custom gateway - #9 by giobauermeister

1 Like

So the server is too slow to execute the JS script within the default 1s.
Interesting.

So I fixed this by modifying the chirpstack.init script so the generated Toml file includes this parameter. Persistent across Chirpstack OK reboots … but not upgrade friendly :wink:
Unfortunately, I don’t have enough dev skills to propose a code change to support this param natively :frowning:

Default script

configuration() {
	mkdir -p /var/etc/$PACKAGE_NAME
	rm -rf /var/etc/$PACKAGE_NAME/*.toml
	echo "" > /var/etc/$PACKAGE_NAME/$PACKAGE_NAME.toml

	cat >> /var/etc/$PACKAGE_NAME/$PACKAGE_NAME.toml <<- EOF
		[sqlite]
		path="/srv/chirpstack/chirpstack.sqlite"

		[gateway]
		allow_unknown_gateways=true

		[integration]
		enabled = [
				"mqtt",
		]

		[integration.mqtt]
		json=true
		server="tcp://127.0.0.1:1883/"
	EOF

	config_load "$PACKAGE_NAME"
	config_foreach conf_rule_network "network"
}

*Modified

configuration() {
	mkdir -p /var/etc/$PACKAGE_NAME
	rm -rf /var/etc/$PACKAGE_NAME/*.toml
	echo "" > /var/etc/$PACKAGE_NAME/$PACKAGE_NAME.toml

	cat >> /var/etc/$PACKAGE_NAME/$PACKAGE_NAME.toml <<- EOF
		[sqlite]
		path="/srv/chirpstack/chirpstack.sqlite"

		[gateway]
		allow_unknown_gateways=true

                # Codec configuration.
                [codec]
                
                  # JS codec configuration.
                  [codec.js]
                
                    # Maximum execution time.
                    max_execution_time="5000ms"

		[integration]
		enabled = [
				"mqtt",
		]

		[integration.mqtt]
		json=true
		server="tcp://127.0.0.1:1883/"
	EOF

	config_load "$PACKAGE_NAME"
	config_foreach conf_rule_network "network"
}

Hello ChirpStack team,

I am hitting that exact same “JS error: Error: interrupted” (aka JS Codec timeout) on my Raspberry PI 0 W with Chirpstack OS v4 (just made a new fresh install because of SD Card corruption on the PI …). I remember I was hitting the same issue on Chirpstack V3 - even for the most basic codec JS code.

As far as I remember, increasing max_execution_time did the trick …
Can you guide me on how to change this value on Chirpstack OS v4 (and make it persistent) ? I am a bit lost with the new UCI config model for Chirpstack OS, which file I should tweak, etc …

# Codec configuration.
[codec]

  # JS codec configuration.
  [codec.js]

    # Maximum execution time.
    max_execution_time="1000ms"

Thx,
Guillaume.

Try uci show chirpstack, I don’t have my Pi with me so I can’t do this myself but that should show you all of the configuration options that you can change with UCI. If max_execution_time is a setting there then you can change it with a UCI commit (if you share the output of the UCI show and it has the setting I could tell you the commit command), if it’s not a setting you will likely have to do what you did in V3 of changing the configuration load script.

This topic was automatically closed after 90 days. New replies are no longer allowed.