iegomez / lds

Loraserver device simulator with a simple GUI.
44 stars 25 forks source link

client crashes after connection to mqtt #25

Closed PhilDay-CT closed 4 years ago

PhilDay-CT commented 4 years ago

Hi,

This is probably a newby issue but please bear with me:

I have chirpstack running via docker-compose and am trying to get your client to connect to it. I've registered a gateway in chirpstack with an gateway ID of DEADBEEFDEADBEEF

I then run the client with no other parameters (i.e. default configuration), and tell it to connect to the MQTT server (localhost:1883)

In the chirpstack log I can see the connection being made, but the it immediately disconnects

mosquitto_1 | 1597846740: New connection from 172.20.0.1 on port 1883. mosquitto_1 | 1597846740: New client connected from 172.20.0.1 as lds-1597846740191835856 (p2, c1, k30). mosquitto_1 | 1597846740: Socket error on client lds-1597846740191835856, disconnecting.

The log from the client shows teh connection, but it then exits without any error being shown:

phil@pol-r:~/go/github.com/legomez/lds$ ./gui time="2020-08-19T15:17:28+01:00" level=info msg="open conf.toml: no such file or directory" time="2020-08-19T15:17:28+01:00" level=error msg="devEUI error: lorawan: exactly 8 bytes are expected" time="2020-08-19T15:19:00+01:00" level=info msg="MQTT connecting..." time="2020-08-19T15:19:00+01:00" level=info msg="connection established" time="2020-08-19T15:19:00+01:00" level=info msg=subscribed

The last line is an extra log statement I added to check that its getting past the call to mqqtClient.SubScribe()

Looking at the code I can't even see where it would be going next as this seems to be the complete callback on the "connect" button.

Any ideas or suggestion on what I can do to debug this further ?

PhilDay-CT commented 4 years ago

BTW I have tried connecting to the network server instead:

chirpstack-network-server:8000

That logs that it has started the UDP forwarder, but if I now add a device in chirpstack, set the same details in client UI and hit Join I get an "Neither client is connected" error

time="2020-08-19T15:26:48+01:00" level=info msg="UDP Forwarder started (MQTT disabled)" time="2020-08-19T15:31:51+01:00" level=error msg="Neither client is connected"

PhilDay-CT commented 4 years ago

I have also tried starting the client with a conf.toml file based on the example, which gives a bit more logging since it now connects to redis (I guess that means there does have to be a config file, but also I underdtand you only use Redis for the results from OOAP so that doesn't sound like it would be the issue here)

However it still crashes as soon as it connects to mqtt

./gui time="2020-08-19T15:41:57+01:00" level=debug msg="Connecting to redis localhost:6379 %!s(int=10)" time="2020-08-19T15:41:57+01:00" level=debug msg=" Connected to Redis " time="2020-08-19T15:41:57+01:00" level=warning msg="[redis] missing ulFcnt key: redis: nil" time="2020-08-19T15:41:57+01:00" level=warning msg="[redis] missing dlFcnt key: redis: nil" time="2020-08-19T15:41:57+01:00" level=warning msg="[redis] missing join nonce key: redis: nil" time="2020-08-19T15:41:57+01:00" level=warning msg="[redis] missing dev nonce key: redis: nil" time="2020-08-19T15:41:57+01:00" level=error msg="redis convert error (fNwksSIntKey): redis: nil" time="2020-08-19T15:47:18+01:00" level=info msg="MQTT connecting..." time="2020-08-19T15:47:18+01:00" level=info msg="connection established ##" time="2020-08-19T15:47:18+01:00" level=info msg=subscribed

---- conf.toml --------------

log_level = "debug"

[mqtt] server = "tcp://localhost:1883" user = "username" password = "password"

Uplink topic. %s will be replaced with the gateway mac.

uplink_topic="gateway/%s/event/up"

Downlink topic. %s will be replaced with the gateway mac.

downlink_topic="gateway/%s/command/down"

[gateway] mac = "b827ebfffe9448d0"

[band] name = "AU_915_928"

[device] eui="eee11c479ba2b880" address="" network_session_encription_key="" serving_network_session_integrity_key="" forwarding_network_session_integrity_key="" application_session_key="" marshaler="json" nwk_key="5a9c0f305e9c6647342fea59a84c4af2" app_key="7bc312d8e6484d51d50d1414995f2013" join_eui="0000000000000000" mac_version=1 profile="OTAA" joined=false skip_fcnt_check=true

[data_rate] bandwith = 125 spread_factor = 10 bit_rate = 0

[rx_info] channel = 0 code_rate = "4/5" crc_status = 1 frequency = 916800000 lora_snr = 7.0 rf_chain = 1 rssi = -57

[raw_payload] payload = "ff00" use_raw = false script = "\n// Encode encodes the given object into an array of bytes.\n// - fPort contains the LoRaWAN fPort number\n// - obj is an object, e.g. {\"temperature\": 22.5}\n// The function must return an array of bytes, e.g. [225, 230, 255, 0]\nfunction Encode(fPort, obj) {\n\treturn [\n obj[\"Flags\"],\n obj[\"Battery\"],\n obj[\"Light\"],\n ];\n}\n" use_encoder = true max_exec_time = 500 js_object = "{\n \"Flags\": 0,\n \"Battery\": 65,\n \"Light\": 54\n}" fport = 2

[[encoded_type]] name = "Flags" value = 5.0 max_value = 255.0 min_value = 0.0 is_float = false num_bytes = 1

[[encoded_type]] name = "Batería" value = 80.0 max_value = 255.0 min_value = 0.0 is_float = false num_bytes = 1

[[encoded_type]] name = "Luz" value = 50.0 max_value = 255.0 min_value = -0.0 is_float = false num_bytes = 1

[redis] addr = "localhost:6379" password = "" db = 10

scartill commented 4 years ago

@PhilDay-CT I'd be glad to help but we need to factorize the issues mentioned. Could you please isolate all failure scenarios and provided corresponding configs and logs for each one. Thank you!

vladosam commented 4 years ago

I am also having the same problem. Lds is installed on ubuntu 18.04 vm machine. And when i try to connect to mqtt gui immediately crashes. Server is on another machine.

time="2020-09-18T15:06:29+02:00" level=warning msg="[redis] missing dlFcnt key: redis: nil"
time="2020-09-18T15:06:29+02:00" level=warning msg="[redis] missing join nonce key: redis: nil"
time="2020-09-18T15:06:29+02:00" level=error msg="redis convert error (fNwksSIntKey): redis: nil"
libEGL warning: DRI2: failed to authenticate
time="2020-09-18T15:06:31+02:00" level=info msg="MQTT connecting..."
time="2020-09-18T15:06:31+02:00" level=info msg="connection established"

I can connect to server with mqtt explorer so firewall is not a problem. And once i click connect on lds there is no change in number of connected clients in mosquitto. This is my conf.toml

log_level = "debug"

[mqtt]
  server = "tcp://SERVER_IP:1883"
  user = ""
  password = ""
  # Uplink topic. %s will be replaced with the gateway mac.
  uplink_topic="gateway/%s/event/up"
  # Downlink topic. %s will be replaced with the gateway mac.
  downlink_topic="gateway/%s/command/down"

[gateway]
  mac = "b827ebfffe9448d0"

[band]
  name = "EU_863_870"

[device]
eui="f7efadafb2f60bf6"
address="000f6e3b"
network_session_encription_key="50004000000300000600000000000000"
serving_network_session_integrity_key="60003000000300000600000000000000"
forwarding_network_session_integrity_key="90005000000300000600000000000000"
application_session_key="90001000000300000600000000000000"
marshaler="json"
nwk_key="000a85ff0e3ddf31e4c83b0933626996"
app_key="000a85ff0e3ddf31e4c83b0933626996"
join_eui="0000000006000005"
mac_version=0
profile="OTAA"
joined=false
skip_fcnt_check=true

[data_rate]
  bandwith = 125
  spread_factor = 10
  bit_rate = 0

[rx_info]
  channel = 0
  code_rate = "4/5"
  crc_status = 1
  frequency = 916800000
  lora_snr = 7.0
  rf_chain = 1
  rssi = -57

[raw_payload]
  payload = "ff00"
  use_raw = false
  script = "\n// Encode encodes the given object into an array of bytes.\n//  - fPort contains the LoRaWAN fPort number\n//  - obj is an object, e.g. {\"temperature\": 22.5}\n// The function must return an array of bytes, e.g. [225, 230, 255, 0]\nfunction Encode(fPort, obj) {\n\treturn [\n      obj[\"Flags\"],\n      obj[\"Battery\"],\n      obj[\"Light\"],\n    ];\n}\n"
  use_encoder = true
  max_exec_time = 500
  js_object = "{\n \"Flags\": 0,\n \"Battery\": 65,\n \"Light\": 54\n}"
  fport = 2

[[encoded_type]]
  name = "Flags"
  value = 5.0
  max_value = 255.0
  min_value = 0.0
  is_float = false
  num_bytes = 1

[[encoded_type]]
  name = "Batería"
  value = 80.0
  max_value = 255.0
  min_value = 0.0
  is_float = false
  num_bytes = 1

[[encoded_type]]
  name = "Luz"
  value = 50.0
  max_value = 255.0
  min_value = -0.0
  is_float = false
  num_bytes = 1

[redis]
  addr = "localhost:6379"
  password = ""
  db = 10
scartill commented 4 years ago

@PhilDay-CT @vladosam Many thanks for reporting. Fixed in c665ce093fcfa212bd118999cb5e43f4fe72ea80