gotthardp / lorawan-server

Compact server for private LoRaWAN networks
https://gotthardp.github.io/lorawan-server
MIT License
932 stars 324 forks source link

uplink_missand and downlink_missed, and can not confirm ack #641

Open vinsanitycarter opened 5 years ago

vinsanitycarter commented 5 years ago

I am having uplink_missed and downlink_missed error. server_dashboard

First of all, let me know the test enviroment.

[End device setting]

[gateway setting]

Here is global_conf.json

   "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": {
        /* TX gain table, index 0 */
        "pa_gain": 0,
        "mix_gain": 8,
        "rf_power": -6,
        "dig_gain": 0
    },
    "tx_lut_1": {
        /* TX gain table, index 1 */
        "pa_gain": 0,
        "mix_gain": 10,
        "rf_power": -3,
        "dig_gain": 0
    },
    "tx_lut_2": {
        /* TX gain table, index 2 */
        "pa_gain": 0,
        "mix_gain": 12,
        "rf_power": 0,
        "dig_gain": 0
    },
    "tx_lut_3": {
        /* TX gain table, index 3 */
        "pa_gain": 1,
        "mix_gain": 8,
        "rf_power": 3,
        "dig_gain": 0
    },
    "tx_lut_4": {
        /* TX gain table, index 4 */
        "pa_gain": 1,
        "mix_gain": 10,
        "rf_power": 6,
        "dig_gain": 0
    },
    "tx_lut_5": {
        /* TX gain table, index 5 */
        "pa_gain": 1,
        "mix_gain": 12,
        "rf_power": 8,
        "dig_gain": 0
    },
    "tx_lut_6": {
        /* TX gain table, index 6 */
        "pa_gain": 1,
        "mix_gain": 13,
        "rf_power": 11,
        "dig_gain": 0
    },
    "tx_lut_7": {
        /* TX gain table, index 7 */
        "pa_gain": 2,
        "mix_gain": 9,
        "rf_power": 12,
        "dig_gain": 0
    },
    "tx_lut_8": {
        /* TX gain table, index 8 */
        "pa_gain": 1,
        "mix_gain": 15,
        "rf_power": 13,
        "dig_gain": 0
    },
    "tx_lut_9": {
        /* TX gain table, index 9 */
        "pa_gain": 2,
        "mix_gain": 10,
        "rf_power": 14,
        "dig_gain": 0
    },
    "tx_lut_10": {
        /* TX gain table, index 10 */
        "pa_gain": 2,
        "mix_gain": 11,
        "rf_power": 16,
        "dig_gain": 0
    },
    "tx_lut_11": {
        /* TX gain table, index 11 */
        "pa_gain": 3,
        "mix_gain": 9,
        "rf_power": 20,
        "dig_gain": 0
    },
    "tx_lut_12": {
        /* TX gain table, index 12 */
        "pa_gain": 3,
        "mix_gain": 10,
        "rf_power": 24,
        "dig_gain": 0
    },
    "tx_lut_13": {
        /* TX gain table, index 13 */
        "pa_gain": 3,
        "mix_gain": 11,
        "rf_power": 25,
        "dig_gain": 0
    },
    "tx_lut_14": {
        /* TX gain table, index 14 */
        "pa_gain": 3,
        "mix_gain": 12,
        "rf_power": 26,
        "dig_gain": 0
    },
    "tx_lut_15": {
        /* TX gain table, index 15 */
        "pa_gain": 3,
        "mix_gain": 14,
        "rf_power": 27,
        "dig_gain": 0
    }
"gateway_conf": {
        "gateway_ID": "BB00112341234BBA",
        /* change with default server address/ports, or overwrite in local_conf.json */
        "server_address": "192.168.0.235",
        "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
    }
}   

[lorawan-server]

Here is a description of the test environment. When i send a LoRaWAN message, the server does not display any data like this. Frame_blank

and this is gateway console display. confirmed_EEFF

However, the message that end device is turned on and transmitted for the first time is normal.

This problem occurs when sending a confrmed message. When sending an unconfirmed message, it is normal as shown below. frame_unconfirmed

And if the payload size is reduced and a confirmed message is sent, the data received from the server is displayed, but the downlink is not performed. End device can not confirm the ack signal. frames_confirmed

gateway console display confirmed_010203040506

And, I've senn warning message on the gateway console.

The warning message is "|a downlink was already scheduled, overwritting it."

I post parse_uplink and build downlink for reference.

fun (#{fcnt:=Fcnt, devaddr:=DevAddr}=Fields, <<SOP:16, TagType, TagNum, MsgType, MsgLength, BeaconID:32/bitstring, BeaconRSSI, Emergency, Battery, EOP>>) ->
RequestID = base64:encode(crypto:strong_rand_bytes(12)),
  if 
    Fcnt < 1 ->
      #{<<"m2m:rqp">> => #{op => 1, to => <<"/MTag/Monitoring">>, fr => <<"SMonitoring">>, rqi => RequestID, ty => 3, pc => #{<<"m2m:cnt">> => #{rn => <<(lorawan_utils:binary_to_hex(DevAddr))/binary>>, lbl => [<<(lorawan_utils:binary_to_hex(DevAddr))/binary>>]}}}};
    Fcnt < 15 -> 
      #{<<"m2m:rqp">> => #{op => 1, to => <<"/MTag/Monitoring/", (lorawan_utils:binary_to_hex(DevAddr))/binary>>, fr => <<"SMonitoring">>, rqi => RequestID, ty => 23, pc => #{<<"m2m:sub">> => #{rn => <<"Sub_", (lorawan_utils:binary_to_hex(DevAddr))/binary>>, enc => #{net => ['3']}, nu => [<<"mqtt://127.0.0.1/SMonitoring">>], nct => 2}}}};
    true -> 
      #{<<"m2m:rqp">> => #{op => 1, to => <<"/MTag/Monitoring/" ,(lorawan_utils:binary_to_hex(DevAddr))/binary>>, fr => <<"SMonitoring_GPS">>, rqi => RequestID, ty => 4, pc => #{<<"m2m:cin">> => #{con => #{<<"msg_type">> => monitoring, <<"tag_type">> => TagType, <<"tag_id">> => <<(lorawan_utils:binary_to_hex(DevAddr))/binary>>, <<"beacon_id">> => <<(lorawan_utils:binary_to_hex(BeaconID))/binary>>, rssi => BeaconRSSI, emergency => Emergency, battery => Battery}}}}}
  end;

    (#{fcnt:=Fcnt, devaddr:=DevAddr, datetime:=ScanTime}=Fields, <<SOP, TagType, TagNum, LatFirst, LatSecond, LatThird, LatFourth, LonFirst, LonSecond, LonThird, LonFoutrh>>) ->
RequestID = base64:encode(crypto:strong_rand_bytes(12)),
  if 
    Fcnt < 5 ->
      #{<<"m2m:rqp">> => #{op => 1, to => <<"/MTag/Monitoring">>, fr => <<"SMonitoring">>, rqi => RequestID, ty => 3, pc => #{<<"m2m:cnt">> => #{rn => <<(lorawan_utils:binary_to_hex(DevAddr))/binary>>, lbl => [<<(lorawan_utils:binary_to_hex(DevAddr))/binary>>]}}}};
    Fcnt < 10 -> 
      #{<<"m2m:rqp">> => #{op => 1, to => <<"/MTag/Monitoring/", (lorawan_utils:binary_to_hex(DevAddr))/binary>>, fr => <<"SMonitoring">>, rqi => RequestID, ty => 23, pc => #{<<"m2m:sub">> => #{rn => <<"Sub_", (lorawan_utils:binary_to_hex(DevAddr))/binary>>, enc => #{net => ['3']}, nu => [<<"mqtt://127.0.0.1/SMonitoring">>], nct => 2}}}};
    true -> 
      #{<<"m2m:rqp">> => #{op => 1, to => <<"/MTag/Monitoring/" ,(lorawan_utils:binary_to_hex(DevAddr))/binary>>, fr => <<"SMonitoring_GPS">>, rqi => RequestID, ty => 4, pc => #{<<"m2m:cin">> => #{con => #{<<"msg_type">> => scanner, <<"tag_number">> => TagNum, lat1 => LatFirst, lat2 => LatSecond, lat3 => LatThird, lat4 => LatFourth, lon1 => LonFirst, lon2 => LonSecond, lon3 => LonThird, lon4 => LonFoutrh, time => ScanTime}}}}}
  end
end.
fun(#{data:=Data}=Fields) ->
  <<(lorawan_utils:binary_to_hex(Data))/binary>>
end.

I don' think there is a problem with the end device. Because, donwlink was normally done on The Thing Network[TTN].

ttn_application_data segger_rtt_viewer At "at+recv=1,0,0" message, if first parameter is 1, confirmed message transfer was successful and ack signal is received from server.

Downlink was also done normally. ttn_downlink downlink_rtt

At at+recv=0,2,-40,26,5,0908070605 0: Indication that data was received 2: port -40 : rssi 26 : snr 5 : data length 0908070605 : data

this picture is gateway traffic ttn_gateway_traffic

this gateway hardware is raspberry pi3 + risingHF rhfm031, and software is TTN Packet Forwarder on a raspberry pi with and IMST ic880a board.

There seems to be a problem with the gateway or the lorawan-server. First, I will check the lorawan-server. Is there anything wrong with the server settings?

gotthardp commented 5 years ago

What a great and throughout report! I love it.

From the channel setting it seems you want to downlinks to use a single channel (64). To achieve that you should use the "US 902-928MHz (Private Hybrid)" region. Try that, please.

vinsanitycarter commented 5 years ago

What a great and throughout report! I love it.

From the channel setting it seems you want to downlinks to use a single channel (64). To achieve that you should use the "US 902-928MHz (Private Hybrid)" region. Try that, please.

Thank you for answer. I didn't think to use a single channel(64). Just i set it to [0-7, 64] because uplink uses channel 0-7 channel. But i tried changing the region to US902-928MHz(Private Hybrid) as you told me. And test it. The results are nothing new. I also tested the changing the region to [0-71]. There was nothing that changed either. It seems that setting the server's region is not a problem. Is there anything else that could be a problem?

vinsanitycarter commented 5 years ago

What a great and throughout report! I love it.

From the channel setting it seems you want to downlinks to use a single channel (64). To achieve that you should use the "US 902-928MHz (Private Hybrid)" region. Try that, please.

Additional testing has confirmed that this is not a gateway issue. There seems to be a problem on the lorawan-server side.

gotthardp commented 5 years ago

I have no idea what could be wrong, unfortunately. These types of errors are hard to debug remotely.