LoRa server(appserver and networkserver) Installation on Raspberry pi3

Hi,

i changed the [dsn] to as below:-

Did it as above.

i changed them to default, where we dont need username and password.

Then i restarted the server with

sudo systemctl restart loraserver

and this time to view the log i added sudo as

sudo journalctl -u loraserver -f -n 50

i got the following output

Mar 01 11:57:02 raspberrypi loraserver[18653]: time=“2018-03-01T11:57:02Z” level=error msg=“backend/gateway: connecting to mqtt broker failed, will retry in 2s: Network Error : dial tcp [::1]:1883: getsockopt: connection refused”
Mar 01 11:57:04 raspberrypi loraserver[18653]: time=“2018-03-01T11:57:04Z” level=error msg=“backend/gateway: connecting to mqtt broker failed, will retry in 2s: Network Error : dial tcp [::1]:1883: getsockopt: connection refused”
Mar 01 11:57:06 raspberrypi loraserver[18653]: time=“2018-03-01T11:57:06Z” level=error msg=“backend/gateway: connecting to mqtt broker failed, will retry in 2s: Network Error : dial tcp [::1]:1883: getsockopt: connection refused”

I think i have set mqtt credentials as in the docs section.
Mosquitto authentication
Mosquitto, as the main conduit for messaging between the gateways and the LoRa servers and the applications receiving LoRa data, should be secured to prevent third party access to the data. To set up Mosquitto security:

Create a password file for your mosquitto users, starting with a “root” user.

The “-c” parameter creates the new password file. The command will prompt for

a new password for the user.

sudo mosquitto_passwd -c /etc/mosquitto/pwd loraroot

Add users for the various MQTT protocol users

sudo mosquitto_passwd /etc/mosquitto/pwd loragw
sudo mosquitto_passwd /etc/mosquitto/pwd loraserver
sudo mosquitto_passwd /etc/mosquitto/pwd loraappserver

Secure the password file

sudo chmod 600 /etc/mosquitto/pwd
Note that further configuration is possible, such as limiting the topics to which the various users can have access. These settings are beyond the scope of this document.

Mosquitto configuration
Add a new local configuration file (this should survive mosquitto upgrades) called /etc/mosquitto/conf.d/local.conf with the following configuration:

Tell mosquitto where the password file is by adding the lines:

allow_anonymous false
password_file /etc/mosquitto/pwd

May be due to these i am unable to connect. I think i should do a fresh installation again of all the packages.
So, i will start from scratch again.

Hi, @Osman

I believe that if you change from:

to

allow_anonymous true

you should be able to connect without credentials.

1 Like

Oh, but i just re installed the raspbian jessie and now starting from again. :frowning:

I will be in touch with you and update you about my progress.
Thanks a lot :slight_smile:

Hi :slight_smile:

I finally managed to get some positive output. I have only changed [dsn] in both configuration files (lora server and lora app server) and added the following security.

The log results from LoRa server are as below:-
– Logs begin at Thu 2018-03-01 15:43:52 UTC. –
Mar 01 15:43:56 raspberrypi systemd[1]: Starting LoRa Server…
Mar 01 15:43:56 raspberrypi systemd[1]: Started LoRa Server.
Mar 01 15:43:57 raspberrypi loraserver[569]: time=“2018-03-01T15:43:57Z” level=info msg=“starting LoRa Server” band=EU_863_870 docs=“https://docs.loraserver.io/” net_id=010203 version=0.24.3
Mar 01 15:43:57 raspberrypi loraserver[569]: time=“2018-03-01T15:43:57Z” level=info msg=“setup redis connection pool” url=“redis://localhost:6379”
Mar 01 15:43:57 raspberrypi loraserver[569]: time=“2018-03-01T15:43:57Z” level=info msg=“connecting to postgresql”
Mar 01 15:43:57 raspberrypi loraserver[569]: time=“2018-03-01T15:43:57Z” level=error msg=“ping database error, will retry in 2s: dial tcp [::1]:5432: getsockopt: connection refused”
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“backend/gateway: TLS config is empty”
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“backend/gateway: connecting to mqtt broker” server=“tcp://localhost:1883”
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“configuring join-server client” ca_cert= server=“http://localhost:8003” tls_cert= tls_key=
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“no network-controller configured”
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“applying database migrations”
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“backend/gateway: connected to mqtt server”
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“backend/gateway: subscribing to rx topic” topic=gateway/+/rx
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“backend/gateway: subscribing to stats topic” topic=gateway/+/stats
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“migrations applied” count=0
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“starting api server” bind=“0.0.0.0:8000” ca-cert= tls-cert= tls-key=
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“starting gateway api server” bind=“0.0.0.0:8002” ca-cert= tls-cert= tls-key=
Mar 01 15:43:59 raspberrypi loraserver[569]: time=“2018-03-01T15:43:59Z” level=info msg=“starting downlink device-queue scheduler”
Mar 01 15:44:43 raspberrypi systemd[1]: Started LoRa Server.


the log from lora-app-server

– Logs begin at Thu 2018-03-01 15:43:52 UTC. –
Mar 01 15:43:59 raspberrypi systemd[1]: Starting LoRa App Server…
Mar 01 15:43:59 raspberrypi systemd[1]: Started LoRa App Server.
Mar 01 15:44:00 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:00Z” level=info msg=“starting LoRa App Server” docs=“https://docs.loraserver.io/” version=0.18.0
Mar 01 15:44:00 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:00Z” level=info msg=“connecting to postgresql”
Mar 01 15:44:00 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:00Z” level=info msg=“setup redis connection pool”
Mar 01 15:44:00 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:00Z” level=info msg=“handler/mqtt: TLS config is empty”
Mar 01 15:44:00 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:00Z” level=info msg=“handler/mqtt: connecting to mqtt broker” server=“tcp://localhost:1883”
Mar 01 15:44:00 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:00Z” level=info msg=“handler/mqtt: connected to mqtt broker”
Mar 01 15:44:00 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:00Z” level=info msg=“handler/mqtt: subscribling to tx topic” topic=application/+/node/+/tx
Mar 01 15:44:00 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:00Z” level=info msg=“applying database migrations”
Mar 01 15:44:01 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:01Z” level=info msg=“migrations applied” count=0
Mar 01 15:44:01 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:01Z” level=info msg=“starting application-server api” bind=“0.0.0.0:8001” ca-cert= tls-cert= tls-key=
Mar 01 15:44:01 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:01Z” level=info msg=“starting join-server api” bind=“0.0.0.0:8003” ca_cert= tls_cert= tls_key=
Mar 01 15:44:01 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:01Z” level=info msg=“starting client api server” bind=“0.0.0.0:8080” tls-cert=/etc/lora-app-server/certs/http.pem tls-key=/etc/lora-app-server/certs/http-key.pem
Mar 01 15:44:01 raspberrypi lora-app-server[768]: time=“2018-03-01T15:44:01Z” level=info msg=“registering rest api handler and documentation endpoint” path=/api
Mar 01 15:44:54 raspberrypi systemd[1]: Started LoRa App Server.

///////////////////////////////////////////////////////////////////////////////////////////////////////////
I hope this is the right configuration.

I think there is still one problem left to be solved:

Try this:

cat /var/log/postgresql/postgresql-9.6-main.log

If you see something like

2018-02-18 16:32:14.334 UTC [1042] loraserver_ns@loraserver_ns DETAIL: Password does not match for user "loraserver_ns". Connection matched pg_hba.conf line 94: "host all all ::1/128 md5"

you still have to change a postgresql configuration file.

Use the following

sudo vi /etc/postgresql/9.6/main/pg_hba.conf

(or use another editor) to edit pg_hba.conf.

Change the line

host all all ::1/128 md5

to

host all all ::1/128 trust

As I said in the other post ([release] LoRa Gateway Bridge 2.3.0 / LoRa Server 0.24.0 / LoRa App Server 0.18.0 - #12 by dpmendes - Announcements - ChirpStack Community Forum), this is not the safe way to configure the database. You’re letting any IPv6 host to access it. However, it make things work for testing until I have time to test the proper way.

No, there’s no error, is just that when loraserver started, postgres wasn’t running yet, but in a second try it was and loraserver carried on initializing. If postgres was indeed permanently unreachable, something like these would be seen, with the error message continuing to repeat every 2 seconds:

INFO[0000] starting LoRa Server                          band=US_902_928 docs="https://docs.loraserver.io/" net_id=010203 version=0.21.0-99-g8c309f3
INFO[0000] setup redis connection pool                   url="redis://localhost:6379"
INFO[0000] connecting to postgresql                     
INFO[0000] backend/gateway: TLS config is empty         
INFO[0000] backend/gateway: connecting to mqtt broker    server="tcp://localhost:1883"
ERRO[0000] backend/gateway: connecting to mqtt broker failed, will retry in 2s: Network Error : dial tcp 127.0.0.1:1883: getsockopt: connection refused 
ERRO[0002] backend/gateway: connecting to mqtt broker failed, will retry in 2s: Network Error : dial tcp 127.0.0.1:1883: getsockopt: connection refused 
ERRO[0004] backend/gateway: connecting to mqtt broker failed, will retry in 2s: Network Error : dial tcp 127.0.0.1:1883: getsockopt: connection refused

That may be fine for testing purposes, but it means that anyone may connect to your mosquitto broker, so don’t do this for any serious case (also see this, allow anonymous won’t always give access to topics, which could be confusing). Instead, follow carefully the docs on securing mosquitto.

The same goes for this, which is trusting any connection to postgres from any user who can access the server. This is a security risk, and this authentication method shouldn’t be used in production:

When in need to debug, try running programs manually to check the ouput directly so you can see what’s going on.

In summary, relaxing conditions on services in which loraserver relies may be fine just to get it working for the first time, but now that you have, you should try to address all security issues that this creates. You’ll eventually have to deal with them anyway, so why not do it now while you are still configuring things?

1 Like

@iegomez

Sorry :slight_smile:

Agreed. I won’t leave my test environment, so it won’t do any harm, but definitely make it right as soon as possible.

1 Like

Hi,

Thanks a lot for your reply. when i entered:

i did get output similar to this

but even after editing the file to

i am getting the same results.
I think @iegomez could be right.

I am thankful for your support guys :))) You are really amazing people.

Proceeding the installation, i was able to add network server

However, when i create service profile it gives me an error.

I want to eventually view the data of node? am i heading to the right direction?
Edit: i am able to add service profile.

1 Like

Yes you are on the right path!

After you’re able to register a device for your application, you can check either the data received by the gateway or by the device.
Look for the JSON field that represents the data, but keep in mind that it will be Base64-encoded.

Hi,

Could you tell me how to check if my Lora-gateway bridge is working properly or not? I have installed the lora-gateway bridge on the multitech conduit but i could not find any command to test that its functioning.

Best Regards

1 Like

Hello, @Osman.

I don’t have access to a hardware piece to test it now, but I believe this link might help you:

https://docs.loraserver.io/lora-gateway-bridge/install/debug/

Regards

1 Like

Having the same issue that was mentioned here. And your example for a Postgres issue doesn’t seem to be my problem despite what you posted here at the beginning of last month.

My Postgres seems to be working fine, and from what I can tell is on the port that my other files should looking at by default. This issue has come up multiple other times without any direct resolution from what I’ve been able to tell through this forum. If people are fixing their problem they aren’t sharing that fix for others like Osman here. It just seems to fall into place without any further comment.

Could you share some relevant code, logs, etc.? And what’s exactly the issue you are facing?

Sorry, I was referring to this piece that you had mentioned. Also I apologize, I was in a rush with other stuff last night.

I was following through the Quick Install Guide and have installed Mosquitto and set the passwords for the four users (loraroot, loragw, loraserver, and loraappserver). My local.conf just has the two lines:

allow_anonymous false
password_file /etc/mosquitto/pwd

I then installed Postgresql, and set up the two users and databases loraserver_as and loraserver_ns, followed by adding the extension pg_trgm to the loraserver_as database.

I then went about installing the Lora Gateway Bridge and the Lora Server. For the Gateway Bridge is my udp.bind is set to 0.0.0.0:1700, and the mqtt.username is set to loragw and the mqtt.password is set to the corresponding password that I set for that user earlier. For the Lora Server my band is set to the US_902_928, the postgresql.dsn is set to postgres://loraserver_ns:dbpassword@localhost/loraserver_ns?sslmode=disable where dbpassword is the same as the one I set up for the database for loraserver_ns. My postgresql.automigrate is set to true, mqtt.username is set to loraserver and the mqtt.password is the one I setup for that user. Everything else is set as it was mentioned in the quick install guide, and when I did sudo systemctl start loraserver and journalctl -u loraserver the first time it seemed to be ok, I received an error message at first but I just went with the fact that it was the one indicating the Lora App Server was not running.

I then went on to install the Lora App Server and set the following in the lora-app-server.toml file.
postgresql.dsn postgres://loraserver_as:dbpassword@localhost/loraserver_as?sslmode=disable
postgresql.automigrate true
mqtt.username loraappserver
mqtt.password the_corresponding_password_that_I_set_earlier_for_loraappserver
api.bind localhost:8001
external_api.bind 0.0.0.0:8080

After setting up that file I started the lora app server and stopped for the evening. Coming back the next day, I did a restart on everything just to check to see if it would reset itself easily. When I checked the journals for the loraserver and lora-app-server that is when I first started noticing the issue that you had mentioned and that I have copied above.

Lastly I checked the status of each of the services, and mosquitto and postgresql are labeled as active (exited) while loraserver, lora-app-server and lora-gateway-bridge are listed as active(running). I don’t know if that is of any help.

Here exactly are the outputs of the status.

`
root@raspberrypi:/home/pi# sudo systemctl status loraserver
● loraserver.service - LoRa Server
Loaded: loaded (/lib/systemd/system/loraserver.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-04-08 12:56:17 EDT; 9min ago

Main PID: 1397 (loraserver)
CGroup: /system.slice/loraserver.service
└─1397 /usr/bin/loraserver

Apr 08 13:05:16 raspberrypi loraserver[1397]: time=“2018-04-08T13:05:16-04:00” level=error msg=“ping database error, will retry in 2s: dial tcp [::1]:5432: connect: connection refused”

root@raspberrypi:/home/pi# sudo systemctl status lora-app-server
● lora-app-server.service - LoRa App Server
Loaded: loaded (/lib/systemd/system/lora-app-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-04-08 12:56:37 EDT; 17min ago

Main PID: 1414 (lora-app-server)
CGroup: /system.slice/lora-app-server.service
└─1414 /usr/bin/lora-app-server

Apr 08 13:13:55 raspberrypi lora-app-server[1414]: time=“2018-04-08T13:13:55-04:00” level=error msg=“ping database error, will retry in 2s: dial tcp [::1]:5432: connect: connection refused”

@raspberrypi:/home/pi# sudo systemctl status lora-gateway-bridge
● lora-gateway-bridge.service - LoRa Gateway Bridge
Loaded: loaded (/lib/systemd/system/lora-gateway-bridge.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-04-08 12:56:53 EDT; 17min ago

Main PID: 1431 (lora-gateway-br)
CGroup: /system.slice/lora-gateway-bridge.service
└─1431 /usr/bin/lora-gateway-bridge

Apr 08 13:14:42 raspberrypi lora-gateway-bridge[1431]: time=“2018-04-08T13:14:42-04:00” level=error msg=“could not setup mqtt backend, retry in 2 seconds: Network Error : dial tcp 127.0.0.1:1883: getsockopt: connection refused”
Apr 08 13:14:44 raspberrypi lora-gateway-bridge[1431]: time=“2018-04-08T13:14:44-04:00” level=info msg=“backend: TLS config is empty”
Apr 08 13:14:44 raspberrypi lora-gateway-bridge[1431]: time=“2018-04-08T13:14:44-04:00” level=info msg=“backend: connecting to mqtt broker” server=“tcp://127.0.0.1:1883”

root@raspberrypi:/home/pi# sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Sat 2018-04-07 21:55:49 EDT; 15h ago
Process: 499 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 499 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/postgresql.service

Apr 07 21:55:37 raspberrypi systemd[1]: Starting PostgreSQL RDBMS…
Apr 07 21:55:49 raspberrypi systemd[1]: Started PostgreSQL RDBMS.

root@raspberrypi:/home/pi# sudo systemctl status mosquitto
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
Loaded: loaded (/etc/init.d/mosquitto; generated; vendor preset: enabled)
Active: active (exited) since Sun 2018-04-08 13:04:08 EDT; 13min ago
Docs: man:systemd-sysv-generator(8)
Process: 1505 ExecStop=/etc/init.d/mosquitto stop (code=exited, status=0/SUCCESS)
Process: 1512 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)

Apr 08 13:04:08 raspberrypi systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broker…
Apr 08 13:04:08 raspberrypi mosquitto[1512]: Starting network daemon:: mosquitto.
Apr 08 13:04:08 raspberrypi systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
`

The errors suggest that Postgres isn’t running or the connection DSNs are wrong.

That was probably from me screwing around with the .toml file last night. I’ll need to double check it.

Ok rechecked my files, and restarted everything. Now the error message seems to point to mosquitto.

Here’s what I’m seeing now.

Apr 08 19:09:37 raspberrypi lora-app-server[7701]: time=“2018-04-08T19:09:37-04:00” level=info msg=“starting LoRa App Server” docs=“https://docs.loraserver.io/” version=0.19.0
Apr 08 19:09:37 raspberrypi lora-app-server[7701]: time=“2018-04-08T19:09:37-04:00” level=info msg=“connecting to postgresql”
Apr 08 19:09:38 raspberrypi lora-app-server[7701]: time=“2018-04-08T19:09:38-04:00” level=info msg=“setup redis connection pool”
Apr 08 19:09:38 raspberrypi lora-app-server[7701]: time=“2018-04-08T19:09:38-04:00” level=info msg=“handler/mqtt: TLS config is empty”
Apr 08 19:09:38 raspberrypi lora-app-server[7701]: time=“2018-04-08T19:09:38-04:00” level=info msg=“handler/mqtt: connecting to mqtt broker” server=“tcp://localhost:1883”
Apr 08 19:09:38 raspberrypi lora-app-server[7701]: time=“2018-04-08T19:09:38-04:00” level=error msg=“handler/mqtt: connecting to broker error, will retry in 2s: Network Error : dial tcp [::1]:1883: connect: connection refused”

I can’t recall if that message was specific or generic and don’t have means to check it right now, but again it seems that either mosquitto isn’t running, credentials for mosquitto at lora-app-server configuration are wrong or mosquitto authentication is not correctly set. You’ll need to check those things to see which is the one causing the issue.