Differenze tra le versioni di "Gruppo Meteo/HowTo/LorawanGateway"

Da raspibo.
Jump to navigation Jump to search
Riga 1: Riga 1:
 
= LoRaWAN Gateway on rapberry, IMST iC880A Concentrator 868MHz, Centos 7 =
 
= LoRaWAN Gateway on rapberry, IMST iC880A Concentrator 868MHz, Centos 7 =
 +
 +
== Main characteristics ==
 +
* User lorawan packet forwarder ( TTN legacy mode )
 +
* Remote access using ssh tunneling
 +
* Hardware reset for IMST concentrator
 +
* Autorestart services and network connections
 +
* Use system users for services (none run as root or privileged users)
 +
* All software (not configuration) is packaged and use standard public repo (not signed)
 +
* Use firewalld
  
 
== Assemble the gateway ==
 
== Assemble the gateway ==
Riga 10: Riga 19:
 
* 2200uF capacitor
 
* 2200uF capacitor
 
* internet key with SIM card
 
* internet key with SIM card
 +
* power supply 12V 2A
  
 
Assemble the gateway as described at:
 
Assemble the gateway as described at:
Riga 16: Riga 26:
 
Regulate the DC-DC power Supply to output 5.0V
 
Regulate the DC-DC power Supply to output 5.0V
 
Connect the capacitor to the output of DC-DC power Supply
 
Connect the capacitor to the output of DC-DC power Supply
 +
Connect power supply to DC-DC input
 +
Connect DC-DC output to raspberry
  
 
== Operative system ==
 
== Operative system ==
Riga 37: Riga 49:
  
 
change root password!
 
change root password!
 +
 +
== Install packages ==
 +
 +
TOBEDONE
 +
 +
 +
chkconfig ttn-gateway on
 +
chkconfig ttn-imstreset-setgpio on
 +
  
 
== Autossh ==
 
== Autossh ==
Riga 74: Riga 95:
 
ora dalla macchina remota si può fare:
 
ora dalla macchina remota si può fare:
 
  ssh root@localhost -p5022
 
  ssh root@localhost -p5022
 +
 +
== Monit ==
 +
 +
=== GSM ===
 +
/etc/monit.d/gsm-connection (change usb_modeswitch command and serial port to adapt to your gsm modem):
 +
CHECK PROGRAM check_gsm PATH /usr/local/bin/check_gsm TIMEOUT 30 SECONDS
 +
    if status != 0 then start
 +
 +
    start program = "/sbin/usb_modeswitch -v 12d1 -p 14fe -c /usr/share/usb_modeswitch/12d1:14fe ; sleep 10; /usr/bin/nmcli device connect ttyUSB2"
 +
    stop program  = "/usr/bin/nmcli device disconnect ttyUSB2"
 +
 +
 +
/usr/local/bin/check_gsm
 +
#!/bin/bash
 +
set -e
 +
 +
# "Check Mobile Broadband Connection."
 +
 +
# testing...to see if gsm is on the list of active devices
 +
 +
        LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:connected$"
 +
 +
=== Packet forwarder ===
 +
 +
/usr/local/bin/check_gateway (change your gateway id and coordinate):
 +
#!/usr/bin/python
 +
 +
import urllib2
 +
import json
 +
import dateutil.parser
 +
import datetime
 +
import sys
 +
 +
GATEWAYID="eui-0ceee6fffe9da82e"
 +
LAT=44.48842723017417
 +
LON=11.26079806901295
 +
 +
body=urllib2.urlopen("https://www.thethingsnetwork.org/gateway-data/location?latitude="+LAT+"&longitude="+LON+"&distance=15000").read()
 +
gatewaydata=json.loads(body)
 +
print gatewaydata[GATEWAYID]["last_seen"]
 +
 +
lastseen = dateutil.parser.parse(gatewaydata[GATEWAYID]["last_seen"]).replace(tzinfo=None)
 +
now=datetime.datetime.utcnow()
 +
print lastseen
 +
print now
 +
 +
elapsed=now-lastseen
 +
print "elapsed: ", elapsed
 +
if ( elapsed > datetime.timedelta(seconds=300)):
 +
    sys.exit(1)
 +
 +
sys.exit(0)
 +
 +
/etc/monit.d/gateway-connection
 +
CHECK PROGRAM gateway-connection PATH /usr/local/bin/check_gateway TIMEOUT 30 SECONDS
 +
    if status != 0 then restart
 +
 +
    start program = "/usr/sbin/service ttn-gateway start"
 +
    stop program  = "/usr/sbin/service ttn-gateway stop"
 +
 +
    every 5 cycles
 +
 +
 +
=== Activate monit ===
 +
 +
chkconfig monit on
 +
service monit start

Versione delle 18:05, 19 mar 2018

LoRaWAN Gateway on rapberry, IMST iC880A Concentrator 868MHz, Centos 7

Main characteristics

  • User lorawan packet forwarder ( TTN legacy mode )
  • Remote access using ssh tunneling
  • Hardware reset for IMST concentrator
  • Autorestart services and network connections
  • Use system users for services (none run as root or privileged users)
  • All software (not configuration) is packaged and use standard public repo (not signed)
  • Use firewalld

Assemble the gateway

Parts:

Assemble the gateway as described at: https://github.com/ttn-zh/ic880a-gateway/wiki

Regulate the DC-DC power Supply to output 5.0V Connect the capacitor to the output of DC-DC power Supply Connect power supply to DC-DC input Connect DC-DC output to raspberry

Operative system

Follow https://wiki.centos.org/SpecialInterestGroup/AltArch/Arm32/RaspberryPi3

enable epel:

cat > /etc/yum.repos.d/epel.repo << EOF
[epel]
name=Epel rebuild for armhfp
baseurl=https://armv7.dev.centos.org/repodir/epel-pass-1/
enabled=1
gpgcheck=0

EOF

enable ttn:

cd /etc/yum.repos.d
wget http://rmap.cc/repo/ttn/rmapcentos.repo


change root password!

Install packages

TOBEDONE


chkconfig ttn-gateway on chkconfig ttn-imstreset-setgpio on


Autossh

  • attivare autossh, ossia un tunneling ssh su macchina pubblica per

permettere l'accesso remoto di amministrazione; infatti la connesione tramite wifi o ethernet o GSM non espongono un ip pubblico (almeno senza fare un reindirizzamento di porta):

yum install autossh da root:

ssh-keygen
ssh-copy-id 

/usr/lib/systemd/system/autossh.service

[Unit]
Description=Autossh tunneling
After=network.target

[Service]
#User=ttn
#Group=ttn
WorkingDirectory=/root
#ExecStart=/usr/bin/autossh -M 5023  -N -R 5022:localhost:22 pat1@ttn.rmap.it
ExecStart=/usr/bin/autossh -M 0 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -N -R 5022:localhost:22 <user>@<remotehost>
SyslogIdentifier=autossh
Restart=always
RestartSec=30

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
service autossh start
chkconfig autossh on

ora dalla macchina remota si può fare:

ssh root@localhost -p5022

Monit

GSM

/etc/monit.d/gsm-connection (change usb_modeswitch command and serial port to adapt to your gsm modem):

CHECK PROGRAM check_gsm PATH /usr/local/bin/check_gsm TIMEOUT 30 SECONDS
   if status != 0 then start
   start program = "/sbin/usb_modeswitch -v 12d1 -p 14fe -c /usr/share/usb_modeswitch/12d1:14fe ; sleep 10; /usr/bin/nmcli device connect ttyUSB2"
   stop program  = "/usr/bin/nmcli device disconnect ttyUSB2"


/usr/local/bin/check_gsm

#!/bin/bash
set -e

# "Check Mobile Broadband Connection." 

# testing...to see if gsm is on the list of active devices
       LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:connected$"

Packet forwarder

/usr/local/bin/check_gateway (change your gateway id and coordinate):

#!/usr/bin/python

import urllib2
import json
import dateutil.parser
import datetime
import sys

GATEWAYID="eui-0ceee6fffe9da82e"
LAT=44.48842723017417
LON=11.26079806901295

body=urllib2.urlopen("https://www.thethingsnetwork.org/gateway-data/location?latitude="+LAT+"&longitude="+LON+"&distance=15000").read()
gatewaydata=json.loads(body)
print gatewaydata[GATEWAYID]["last_seen"]
lastseen = dateutil.parser.parse(gatewaydata[GATEWAYID]["last_seen"]).replace(tzinfo=None)
now=datetime.datetime.utcnow()
print lastseen
print now
elapsed=now-lastseen
print "elapsed: ", elapsed
if ( elapsed > datetime.timedelta(seconds=300)):
   sys.exit(1)
sys.exit(0)

/etc/monit.d/gateway-connection

CHECK PROGRAM gateway-connection PATH /usr/local/bin/check_gateway TIMEOUT 30 SECONDS
   if status != 0 then restart

   start program = "/usr/sbin/service ttn-gateway start"
   stop program  = "/usr/sbin/service ttn-gateway stop"

   every 5 cycles


Activate monit

chkconfig monit on
service monit start