Difference between revisions of "Dragino Lora/GPS HAT"

From ArmadeusWiki
Jump to: navigation, search
m (Tested Software)
(Tested Software)
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Under_Construction}}
 
  
Instructions to use Dragino Lora/GPS HAT on [[OPOS6ULDev]] (thanks to RaspberryPi™ compatible connector).
+
Instructions to use the Dragino Lora/GPS HAT on [[OPOS6ULDev]] (thanks to RaspberryPi™ compatible connector).
  
 
[http://wiki.dragino.com/index.php?title=File:Hatpin.png]
 
[http://wiki.dragino.com/index.php?title=File:Hatpin.png]
  
==LoRa™==
+
=LoRa™=
 +
==Setup==
 
* RESET is connected to RPi GPIO0 which is gpio24 on [[OPOS6UL]] set as output
 
* RESET is connected to RPi GPIO0 which is gpio24 on [[OPOS6UL]] set as output
 
* nSS is connected to RPi GPIO6, which is gpio97 on [[OPOS6UL]] set as output
 
* nSS is connected to RPi GPIO6, which is gpio97 on [[OPOS6UL]] set as output
Line 11: Line 11:
 
* on recent models (like the one we tested) DIO1 is connected to RPi GPIO4, which is gpio18 on [[OPOS6UL]] set as input
 
* on recent models (like the one we tested) DIO1 is connected to RPi GPIO4, which is gpio18 on [[OPOS6UL]] set as input
 
* on recent models (like the one we tested) DIO1 is connected to RPi GPIO5, which is gpio19 on [[OPOS6UL]] set as input
 
* on recent models (like the one we tested) DIO1 is connected to RPi GPIO5, which is gpio19 on [[OPOS6UL]] set as input
 
+
* This Hat/Shield is using HOPERF RFM96W module (clone of Semtech's SX1276 ?) which is controlled through SPI bus.
* Uses HOPERF RFM96W module (clone of Semtech's SX1276 ?) which is controlled through SPI bus.
+
 
<pre class="apf">
 
<pre class="apf">
 
# modprobe spidev
 
# modprobe spidev
 
</pre>
 
</pre>
  
* Testing that chip is recognised with python spidev:
+
=== Testing that chip is recognized with python spidev ===
** Bring chip out of reset:
+
* Bring chip out of reset:
 
<pre class="apf">
 
<pre class="apf">
 
# echo 24 > /sys/class/gpio/export
 
# echo 24 > /sys/class/gpio/export
Line 25: Line 24:
 
# echo 1 > /sys/class/gpio/gpio24/value
 
# echo 1 > /sys/class/gpio/gpio24/value
 
</pre>
 
</pre>
** activate it:
+
* activate it:
 
<pre class="apf">
 
<pre class="apf">
 
# echo 97 > /sys/class/gpio/export
 
# echo 97 > /sys/class/gpio/export
Line 31: Line 30:
 
# echo 0 > /sys/class/gpio/gpio97/value
 
# echo 0 > /sys/class/gpio/gpio97/value
 
</pre>
 
</pre>
** read ID (register 0x42):
+
* read ID (register 0x42):
 
<source lang="python">
 
<source lang="python">
 
import spidev
 
import spidev
Line 42: Line 41:
 
</source>
 
</source>
  
===Tested Software===
+
==Tested Software==
 +
===Gateway===
 
* https://github.com/tftelkamp/single_chan_pkt_fwd
 
* https://github.com/tftelkamp/single_chan_pkt_fwd
 +
* To compile/install it:
 +
{| class="wikitable"
 +
|-
 +
! Buildroot !! Debian
 +
|-
 +
|
 
<pre class="host">
 
<pre class="host">
Compile it under Buildroot:
 
 
$ make lora-forwarder
 
$ make lora-forwarder
 +
</pre>
 +
||
 +
* [[AsDevices]] library (0.18+) and '''git''' are needed. Board date/time should be correct to use ''git clone''. Then:
 +
<pre class="apf">
 +
root@opos6ul:~# cd
 +
root@opos6ul:~# git clone https://github.com/tftelkamp/single_chan_pkt_fwd.git
 +
root@opos6ul:~# cd single_chan_pkt_fwd/
 +
root@opos6ul:~/single_chan_pkt_fwd# make CFLAGS="-Wall -I/usr/include/as_devices/" LIBS="-las_devices"
 +
</pre>
 +
|}
  
Compile it under Debian (as_devices needed):
+
* If not already loaded, load ''spidev'' driver:
# git clone https://github.com/tftelkamp/single_chan_pkt_fwd.git
+
<pre class="apf">
# make CFLAGS="-c -Wall -I/usr/include/as_devices/" LIBS="-las_devices"
+
root@opos6ul:~# modprobe spidev
 
</pre>
 
</pre>
  
 +
* edit a script and put in it:
 
<pre class="apf">
 
<pre class="apf">
# modprobe spidev
+
root@opos6ul:~# vim /root/start_gateway.sh
# echo 9 > /sys/class/gpio/export
+
# echo 24 > /sys/class/gpio/export
+
# echo 97 > /sys/class/gpio/export
+
# echo out > /sys/class/gpio/gpio97/direction
+
# echo out > /sys/class/gpio/gpio24/direction
+
# echo in > /sys/class/gpio/gpio9/direction
+
 
</pre>
 
</pre>
* to get & printout UDP data from gateway:
+
 
 +
<source lang="bash">
 +
#!/bin/sh
 +
 
 +
echo 9 > /sys/class/gpio/export
 +
echo 24 > /sys/class/gpio/export
 +
echo 97 > /sys/class/gpio/export
 +
echo out > /sys/class/gpio/gpio97/direction
 +
echo out > /sys/class/gpio/gpio24/direction
 +
echo in > /sys/class/gpio/gpio9/direction
 +
 
 +
/root/single_chan_pkt_fwd/single_chan_pkt_fwd
 +
</source>
 +
 
 +
* Make it executable:
 +
<pre class="apf">
 +
root@opos6ul:~# chmod a+x /root/start_gateway.sh
 +
</pre>
 +
 
 +
* Launch it ! ;-)
 +
<pre class="apf">
 +
root@opos6ul:~# /root/start_gateway.sh
 +
</pre>
 +
 
 +
* To get & printout UDP data forwarded by the gateway (if -i runtime option is used):
 
<source lang="python">
 
<source lang="python">
 
#!/usr/bin/python
 
#!/usr/bin/python
  
 
import socket
 
import socket
 +
import json
  
UDP_IP = "192.168.1.28"
+
UDP_IP = "192.168.1.28" # my IP
 
UDP_PORT = 1700
 
UDP_PORT = 1700
  
Line 77: Line 112:
 
while True:
 
while True:
 
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
 
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print "received message:", data
+
json_msg = data[12:]
 +
# print "received JSON message:", json_msg
 +
 
 +
try:
 +
decoded = json.loads(json_msg)
 +
# print json.dumps(decoded, sort_keys=True, indent=4)
 +
if decoded.get('rxpk'):
 +
print "Packet data: ", decoded['rxpk'][0]['data']
 +
 
 +
except (ValueError, KeyError, TypeError):
 +
print "JSON format error"
 
</source>
 
</source>
  
 +
===Node===
 
* http://wiki.dragino.com/index.php?title=Use_Lora/GPS_HAT_%2B_RaspberryPi_to_set_up_a_Lora_Node
 
* http://wiki.dragino.com/index.php?title=Use_Lora/GPS_HAT_%2B_RaspberryPi_to_set_up_a_Lora_Node
 +
 +
{| class="wikitable"
 +
|-
 +
! Buildroot !! Debian
 +
|-
 +
|
 
<pre class="host">
 
<pre class="host">
 
$ make lmic-pi
 
$ make lmic-pi
 
</pre>
 
</pre>
 +
||
 +
* [[AsDevices]] library (0.18+) and ''unzip'' (''apt-get install unzip'') are needed. Then:
 +
<pre class="apf">
 +
root@opos6ul:~# cd
 +
root@opos6ul:~# wget https://github.com/ernstdevreede/lmic_pi/archive/master.zip
 +
root@opos6ul:~# unzip master.zip
 +
root@opos6ul:~# cd lmic_pi-master/lmic
 +
root@opos6ul:~# make CFLAGS="-c -Wall -I/usr/include/as_devices/" LIBS="-las_devices"
 +
root@opos6ul:~# cd ../examples/thethingsnetwork-send-v1/
 +
root@opos6ul:~# make CFLAGS="-Wall -I/usr/include/as_devices/ -I../../lmic" LDFLAGS="-las_devices"
 +
root@opos6ul:~# chmod a+x thethingsnetwork-send-v1
 +
</pre>
 +
|}
 +
 +
* edit a script and put in it:
 +
<pre class="apf">
 +
root@opos6ul:~# vim /root/start_node.sh
 +
</pre>
 +
 +
<source lang="bash">
 +
#!/bin/sh
 +
 +
echo 9 > /sys/class/gpio/export
 +
echo 18 > /sys/class/gpio/export
 +
echo 19 > /sys/class/gpio/export
 +
echo 24 > /sys/class/gpio/export
 +
echo 97 > /sys/class/gpio/export
 +
 +
echo out > /sys/class/gpio/gpio97/direction
 +
echo out > /sys/class/gpio/gpio24/direction
 +
echo in > /sys/class/gpio/gpio9/direction
 +
echo in > /sys/class/gpio/gpio18/direction
 +
echo in > /sys/class/gpio/gpio19/direction
 +
 +
/root/lmic_pi/examples/thethingsnetwork-send-v1/thethingsnetwork-send-v1 &
 +
</source>
 +
 
<pre class="apf">
 
<pre class="apf">
 
# modprobe spidev
 
# modprobe spidev
# echo 9 > /sys/class/gpio/export
 
# echo 18 > /sys/class/gpio/export
 
# echo 19 > /sys/class/gpio/export
 
# echo 24 > /sys/class/gpio/export
 
# echo 97 > /sys/class/gpio/export
 
# echo out > /sys/class/gpio/gpio97/direction
 
# echo out > /sys/class/gpio/gpio24/direction
 
# echo in > /sys/class/gpio/gpio9/direction
 
# echo in > /sys/class/gpio/gpio18/direction
 
# echo in > /sys/class/gpio/gpio19/direction
 
 
</pre>
 
</pre>
  
==GPS==
+
* Make it executable:
* GPS is connected to UART2 (/dev/ttymxc1)
+
<pre class="apf">
* [[NTP#Time_synchronisation_from_GPS]]
+
root@opos6ul:~# chmod a+x /root/start_node.sh
 +
</pre>
 +
 
 +
* Launch it ! ;-)
 +
<pre class="apf">
 +
root@opos6ul:~# /root/start_node.sh
 +
</pre>
 +
 
 +
=GPS=
 +
* GPS is connected to UART2 (''/dev/ttymxc1'')
 +
* [[NTP#Time_synchronisation_from_GPS|Use GPS to get time/date with NTP]]
  
==Links==
+
=Links=
 
* http://www.dragino.com/products/module/item/106-lora-gps-hat.html
 
* http://www.dragino.com/products/module/item/106-lora-gps-hat.html
 
* http://wiki.dragino.com/index.php?title=Lora/GPS_HAT
 
* http://wiki.dragino.com/index.php?title=Lora/GPS_HAT
Line 112: Line 201:
  
 
[[Category:RPi_Hats]]
 
[[Category:RPi_Hats]]
 +
[[Category:LoRa]]
 +
[[Category:GPS]]

Latest revision as of 18:01, 21 April 2017

Instructions to use the Dragino Lora/GPS HAT on OPOS6ULDev (thanks to RaspberryPi™ compatible connector).

[1]

LoRa™

Setup

  • RESET is connected to RPi GPIO0 which is gpio24 on OPOS6UL set as output
  • nSS is connected to RPi GPIO6, which is gpio97 on OPOS6UL set as output
  • DIO0 is connected to RPi GPIO7, which is gpio10 on OPOS6UL set as input
  • on recent models (like the one we tested) DIO1 is connected to RPi GPIO4, which is gpio18 on OPOS6UL set as input
  • on recent models (like the one we tested) DIO1 is connected to RPi GPIO5, which is gpio19 on OPOS6UL set as input
  • This Hat/Shield is using HOPERF RFM96W module (clone of Semtech's SX1276 ?) which is controlled through SPI bus.
# modprobe spidev

Testing that chip is recognized with python spidev

  • Bring chip out of reset:
# echo 24 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio24/direction
# echo 0 > /sys/class/gpio/gpio24/value
# echo 1 > /sys/class/gpio/gpio24/value
  • activate it:
# echo 97 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio97/direction
# echo 0 > /sys/class/gpio/gpio97/value
  • read ID (register 0x42):
import spidev

spi = spidev.SpiDev()
spi.open(3,0)
to_send=[0x42,0x00]
spi.xfer(to_send)
[255, 255]

Tested Software

Gateway

Buildroot Debian
$ make lora-forwarder
  • AsDevices library (0.18+) and git are needed. Board date/time should be correct to use git clone. Then:
root@opos6ul:~# cd
root@opos6ul:~# git clone https://github.com/tftelkamp/single_chan_pkt_fwd.git
root@opos6ul:~# cd single_chan_pkt_fwd/
root@opos6ul:~/single_chan_pkt_fwd# make CFLAGS="-Wall -I/usr/include/as_devices/" LIBS="-las_devices"
  • If not already loaded, load spidev driver:
root@opos6ul:~# modprobe spidev
  • edit a script and put in it:
root@opos6ul:~# vim /root/start_gateway.sh
#!/bin/sh

echo 9 > /sys/class/gpio/export
echo 24 > /sys/class/gpio/export
echo 97 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio97/direction
echo out > /sys/class/gpio/gpio24/direction
echo in > /sys/class/gpio/gpio9/direction

/root/single_chan_pkt_fwd/single_chan_pkt_fwd
  • Make it executable:
root@opos6ul:~# chmod a+x /root/start_gateway.sh
  • Launch it ! ;-)
root@opos6ul:~# /root/start_gateway.sh
  • To get & printout UDP data forwarded by the gateway (if -i runtime option is used):
#!/usr/bin/python

import socket
import json

UDP_IP = "192.168.1.28"	# my IP
UDP_PORT = 1700

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

while True:
	data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
	json_msg = data[12:]
#	print "received JSON message:", json_msg

	try:
		decoded = json.loads(json_msg)
#		print json.dumps(decoded, sort_keys=True, indent=4)
		if decoded.get('rxpk'):
			print "Packet data: ", decoded['rxpk'][0]['data']

	except (ValueError, KeyError, TypeError):
		print "JSON format error"

Node

Buildroot Debian
$ make lmic-pi
  • AsDevices library (0.18+) and unzip (apt-get install unzip) are needed. Then:
root@opos6ul:~# cd
root@opos6ul:~# wget https://github.com/ernstdevreede/lmic_pi/archive/master.zip
root@opos6ul:~# unzip master.zip 
root@opos6ul:~# cd lmic_pi-master/lmic
root@opos6ul:~# make CFLAGS="-c -Wall -I/usr/include/as_devices/" LIBS="-las_devices"
root@opos6ul:~# cd ../examples/thethingsnetwork-send-v1/
root@opos6ul:~# make CFLAGS="-Wall -I/usr/include/as_devices/ -I../../lmic" LDFLAGS="-las_devices"
root@opos6ul:~# chmod a+x thethingsnetwork-send-v1
  • edit a script and put in it:
root@opos6ul:~# vim /root/start_node.sh
#!/bin/sh

echo 9 > /sys/class/gpio/export
echo 18 > /sys/class/gpio/export
echo 19 > /sys/class/gpio/export
echo 24 > /sys/class/gpio/export
echo 97 > /sys/class/gpio/export

echo out > /sys/class/gpio/gpio97/direction 
echo out > /sys/class/gpio/gpio24/direction 
echo in > /sys/class/gpio/gpio9/direction
echo in > /sys/class/gpio/gpio18/direction
echo in > /sys/class/gpio/gpio19/direction

/root/lmic_pi/examples/thethingsnetwork-send-v1/thethingsnetwork-send-v1 &
# modprobe spidev
  • Make it executable:
root@opos6ul:~# chmod a+x /root/start_node.sh
  • Launch it ! ;-)
root@opos6ul:~# /root/start_node.sh

GPS

Links


LoRa is a registered trademark of Semtech.

RaspberryPi is a registered trademark of RaspberryPi Foundation.