TheThingsNetwork / arduino-node-lib

Arduino Library for The Things Node
MIT License
22 stars 26 forks source link

Guidance: Tweaking US915 frequencies #28

Closed gerfen closed 2 years ago

gerfen commented 2 years ago

I'm looking for some guidance to tweak the US frequencies on the Things Node so I can use it to test my gateway deployments.

The TTN US-915 frequencies are defined like this [1]. My gateways are using this frequency plan [2]. Could some one provide guidance on how I can program the Things Node to support plan [2]?

Thanks!

[1] US-915 plan defined for TTN Network

{
    "SX1301_conf": {
        "lorawan_public": true,
        "clksrc": 1,
        "clksrc_desc": "radio_1 provides clock to concentrator for most devices except MultiTech. For MultiTech set to 0.",
        "antenna_gain": 0,
        "antenna_gain_desc": "antenna gain, in dBi",
        "radio_0": {
            "enable": true,
            "type": "SX1257",
            "freq": 904300000,
            "rssi_offset": -166.0,
            "tx_enable": true,
            "tx_freq_min": 923000000,
            "tx_freq_max": 928000000
        },
        "radio_1": {
            "enable": true,
            "type": "SX1257",
            "freq": 905000000,
            "rssi_offset": -166.0,
            "tx_enable": false
        },
        "chan_multiSF_0": {
            "desc": "Lora MAC, 125kHz, all SF, 903.9 MHz",
            "enable": true,
            "radio": 0,
            "if": -400000
        },
        "chan_multiSF_1": {
            "desc": "Lora MAC, 125kHz, all SF, 904.1 MHz",
            "enable": true,
            "radio": 0,
            "if": -200000
        },
        "chan_multiSF_2": {
            "desc": "Lora MAC, 125kHz, all SF, 904.3 MHz",
            "enable": true,
            "radio": 0,
            "if": 0
        },
        "chan_multiSF_3": {
            "desc": "Lora MAC, 125kHz, all SF, 904.5 MHz",
            "enable": true,
            "radio": 0,
            "if": 200000
        },
        "chan_multiSF_4": {
            "desc": "Lora MAC, 125kHz, all SF, 904.7 MHz",
            "enable": true,
            "radio": 1,
            "if": -300000
        },
        "chan_multiSF_5": {
            "desc": "Lora MAC, 125kHz, all SF, 904.9 MHz",
            "enable": true,
            "radio": 1,
            "if": -100000
        },
        "chan_multiSF_6": {
            "desc": "Lora MAC, 125kHz, all SF, 905.1 MHz",
            "enable": true,
            "radio": 1,
            "if": 100000
        },
        "chan_multiSF_7": {
            "desc": "Lora MAC, 125kHz, all SF, 905.3 MHz",
            "enable": true,
            "radio": 1,
            "if": 300000
        },
        "chan_Lora_std": {
            "desc": "Lora MAC, 500kHz, SF8, 904.6 MHz",
            "enable": true,
            "radio": 0,
            "if": 300000,
            "bandwidth": 500000,
            "spread_factor": 8
        },
        "chan_FSK": {
            "desc": "disabled",
            "enable": false
        },
        "tx_lut_0": {
            "desc": "TX gain table, index 0",
            "pa_gain": 0,
            "mix_gain": 8,
            "rf_power": -6,
            "dig_gain": 0
        },
        "tx_lut_1": {
            "desc": "TX gain table, index 1",
            "pa_gain": 0,
            "mix_gain": 10,
            "rf_power": -3,
            "dig_gain": 0
        },
        "tx_lut_2": {
            "desc": "TX gain table, index 2",
            "pa_gain": 0,
            "mix_gain": 12,
            "rf_power": 0,
            "dig_gain": 0
        },
        "tx_lut_3": {
            "desc": "TX gain table, index 3",
            "pa_gain": 1,
            "mix_gain": 8,
            "rf_power": 3,
            "dig_gain": 0
        },
        "tx_lut_4": {
            "desc": "TX gain table, index 4",
            "pa_gain": 1,
            "mix_gain": 10,
            "rf_power": 6,
            "dig_gain": 0
        },
        "tx_lut_5": {
            "desc": "TX gain table, index 5",
            "pa_gain": 1,
            "mix_gain": 12,
            "rf_power": 10,
            "dig_gain": 0
        },
        "tx_lut_6": {
            "desc": "TX gain table, index 6",
            "pa_gain": 1,
            "mix_gain": 13,
            "rf_power": 11,
            "dig_gain": 0
        },
        "tx_lut_7": {
            "desc": "TX gain table, index 7",
            "pa_gain": 2,
            "mix_gain": 9,
            "rf_power": 12,
            "dig_gain": 0
        },
        "tx_lut_8": {
            "desc": "TX gain table, index 8",
            "pa_gain": 1,
            "mix_gain": 15,
            "rf_power": 13,
            "dig_gain": 0
        },
        "tx_lut_9": {
            "desc": "TX gain table, index 9",
            "pa_gain": 2,
            "mix_gain": 10,
            "rf_power": 14,
            "dig_gain": 0
        },
        "tx_lut_10": {
            "desc": "TX gain table, index 10",
            "pa_gain": 2,
            "mix_gain": 11,
            "rf_power": 16,
            "dig_gain": 0
        },
        "tx_lut_11": {
            "desc": "TX gain table, index 11",
            "pa_gain": 3,
            "mix_gain": 9,
            "rf_power": 20,
            "dig_gain": 0
        },
        "tx_lut_12": {
            "desc": "TX gain table, index 12",
            "pa_gain": 3,
            "mix_gain": 10,
            "rf_power": 23,
            "dig_gain": 0
        },
        "tx_lut_13": {
            "desc": "TX gain table, index 13",
            "pa_gain": 3,
            "mix_gain": 11,
            "rf_power": 25,
            "dig_gain": 0
        },
        "tx_lut_14": {
            "desc": "TX gain table, index 14",
            "pa_gain": 3,
            "mix_gain": 12,
            "rf_power": 26,
            "dig_gain": 0
        },
        "tx_lut_15": {
            "desc": "TX gain table, index 15",
            "pa_gain": 3,
            "mix_gain": 14,
            "rf_power": 27,
            "dig_gain": 0
        }
    },
    "gateway_conf": {
        "server_address": "router.us.thethings.network",
        "serv_port_up": 1700,
        "serv_port_down": 1700,
        "servers": [ {
            "server_address": "router.us.thethings.network",
            "serv_port_up": 1700,
            "serv_port_down": 1700,
            "serv_enabled": true
        } ]
    }

}

[2] Modified US-915 frequency plan

{
    "SX1301_conf": {
             "lorawan_public": true,
        "clksrc": 1, /* radio_1 provides clock to concentrator */
        "antenna_gain": 0, /* antenna gain, in dBi */
        "radio_0": {
            "enable": true,
            "type": "SX1257",
            "freq": 902700000,
            "rssi_offset": -166.0,
            "tx_enable": true,
            "tx_freq_min": 902000000,
            "tx_freq_max": 928000000
        },
        "radio_1": {
            "enable": true,
            "type": "SX1257",
            "freq": 903400000,
            "rssi_offset": -166.0,
            "tx_enable": false
        },
        "chan_multiSF_0": {
            /* Lora MAC channel, 125kHz, all SF, 902.3 MHz */
            "enable": true,
            "radio": 0,
            "if": -400000
        },
        "chan_multiSF_1": {
            /* Lora MAC channel, 125kHz, all SF, 902.5 MHz */
            "enable": true,
            "radio": 0,
            "if": -200000
        },
        "chan_multiSF_2": {
            /* Lora MAC channel, 125kHz, all SF, 902.7 MHz */
            "enable": true,
            "radio": 0,
            "if": 0
        },
        "chan_multiSF_3": {
            /* Lora MAC channel, 125kHz, all SF, 902.9 MHz */
            "enable": true,
            "radio": 0,
            "if": 200000
        },
        "chan_multiSF_4": {
            /* Lora MAC channel, 125kHz, all SF, 903.1 MHz */
            "enable": true,
            "radio": 1,
            "if": -300000
        },
        "chan_multiSF_5": {
            /* Lora MAC channel, 125kHz, all SF, 903.3 MHz */
            "enable": true,
            "radio": 1,
            "if": -100000
        },
        "chan_multiSF_6": {
            /* Lora MAC channel, 125kHz, all SF, 903.5 MHz */
            "enable": true,
            "radio": 1,
            "if": 100000
        },
        "chan_multiSF_7": {
            /* Lora MAC channel, 125kHz, all SF, 903.7 MHz */
            "enable": true,
            "radio": 1,
            "if": 300000
        },
        "chan_Lora_std": {
            /* Lora MAC channel, 500kHz, SF8, 903.0 MHz */
            "enable": true,
            "radio": 0,
            "if": 300000,
            "bandwidth": 500000,
            "spread_factor": 8
        },
        "chan_FSK": {
            /* FSK 100kbps channel, 903.0 MHz */
            "enable": false,
            "radio": 0,
            "if": 300000,
            "bandwidth": 250000,
            "datarate": 100000
        },
                "tx_lut_0": {
                        "desc": "TX gain table, index 0",
                        "pa_gain": 0,
                        "mix_gain": 8,
                        "rf_power": -6,
                        "dig_gain": 0
                },
                "tx_lut_1": {
                        "desc": "TX gain table, index 1",
                        "pa_gain": 0,
                        "mix_gain": 10,
                        "rf_power": -3,
                        "dig_gain": 0
                },
                "tx_lut_2": {
                        "desc": "TX gain table, index 2",
                        "pa_gain": 0,
                        "mix_gain": 12,
                        "rf_power": 0,
                        "dig_gain": 0
                },
                "tx_lut_3": {
                        "desc": "TX gain table, index 3",
                        "pa_gain": 1,
                        "mix_gain": 8,
                        "rf_power": 3,
                        "dig_gain": 0
                },
                "tx_lut_4": {
                        "desc": "TX gain table, index 4",
                        "pa_gain": 1,
                        "mix_gain": 10,
                        "rf_power": 6,
                        "dig_gain": 0
                },
                "tx_lut_5": {
                        "desc": "TX gain table, index 5",
                        "pa_gain": 1,
                        "mix_gain": 12,
                        "rf_power": 10,
                        "dig_gain": 0
                },
                "tx_lut_6": {
                        "desc": "TX gain table, index 6",
                        "pa_gain": 1,
                        "mix_gain": 13,
                        "rf_power": 11,
                        "dig_gain": 0
                },
                "tx_lut_7": {
                        "desc": "TX gain table, index 7",
                        "pa_gain": 2,
                        "mix_gain": 9,
                        "rf_power": 12,
                        "dig_gain": 0
                },
                "tx_lut_8": {
                        "desc": "TX gain table, index 8",
                        "pa_gain": 1,
                        "mix_gain": 15,
                        "rf_power": 13,
                        "dig_gain": 0
                },
                "tx_lut_9": {
                        "desc": "TX gain table, index 9",
                        "pa_gain": 2,
                        "mix_gain": 10,
                        "rf_power": 14,
                        "dig_gain": 0
                },
                "tx_lut_10": {
                        "desc": "TX gain table, index 10",
                        "pa_gain": 2,
                        "mix_gain": 11,
                        "rf_power": 16,
                        "dig_gain": 0
                },
                "tx_lut_11": {
                        "desc": "TX gain table, index 11",
                        "pa_gain": 3,
                        "mix_gain": 9,
                        "rf_power": 20,
                        "dig_gain": 0
                },
                "tx_lut_12": {
                        "desc": "TX gain table, index 12",
                        "pa_gain": 3,
                        "mix_gain": 10,
                        "rf_power": 23,
                        "dig_gain": 0
                },
                "tx_lut_13": {
                        "desc": "TX gain table, index 13",
                        "pa_gain": 3,
                        "mix_gain": 11,
                        "rf_power": 25,
                        "dig_gain": 0
                },
                "tx_lut_14": {
                        "desc": "TX gain table, index 14",
                        "pa_gain": 3,
                        "mix_gain": 12,
                        "rf_power": 26,
                        "dig_gain": 0
                },
                "tx_lut_15": {
                        "desc": "TX gain table, index 15",
                        "pa_gain": 3,
                        "mix_gain": 14,
                        "rf_power": 27,
                        "dig_gain": 0
                }
    },

    "gateway_conf": {
        "gateway_ID": "AA555A0000000000",
        /* change with default server address/ports, or overwrite in local_conf.json */
        "server_address": "192.168.0.17",
        "serv_port_up": 1680,
        "serv_port_down": 1680,
        /* adjust the following parameters for your network */
        "keepalive_interval": 10,
        "stat_interval": 30,
        "push_timeout_ms": 100,
        /* forward only valid packets */
        "forward_crc_valid": true,
        "forward_crc_error": false,
        "forward_crc_disabled": false
    }
}
gerfen commented 2 years ago

Looking into this further, it appears that there are several available frequency plans for US915. TTN uses this plan by default and it appears that the ThingsNode does as well. How can I change my sketch to force the ThingsNode to use this plan?

jpmeijers commented 2 years ago

Having a quick look at the library I see in the example we do this:

https://github.com/TheThingsNetwork/arduino-device-lib/blob/ea60c59a726d4147aad878a928da5c8baa7faa50/examples/SendOTAA/SendOTAA.ino#L13

TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);

Looking at the header file I see that constructer can take two more parameters to set the SF and FSB

https://github.com/TheThingsNetwork/arduino-device-lib/blob/ea60c59a726d4147aad878a928da5c8baa7faa50/src/TheThingsNetwork.cpp#L292

So what you should be able to do is to change that line in your code to:

TheThingsNetwork ttn(loraSerial, debugSerial, TTN_FP_US915, TTN_DEFAULT_SF, 1); // last parameter sets it to FSB 1

gerfen commented 2 years ago

@jpmeijers Your suggestion got me pointed in the right direction. For my application, I also had to change the spread factor from the default to 10. Thanks!

I'll close this issue.