Compare commits

..

No commits in common. "master" and "0.9.3" have entirely different histories.

4 changed files with 8 additions and 71 deletions

View File

@ -1,15 +0,0 @@
all: release
clean:
@echo Cleaning...
-rm -r ./build
-rm -r ./dist
build_wheel:
python3 setup.py sdist bdist_wheel
release: build_wheel
upload:
@echo Uploading to PyPi...
twine upload dist/*

View File

@ -33,8 +33,6 @@ If you already have Python3 and pip installed, you can easily install LoRaMon th
pip3 install loramon
```
On Arch Linux it is also possible to install using the `loramon` package from the [AUR](https://aur.archlinux.org/packages/loramon).
If you want to install directly from this repository, first install the dependencies:
```sh
@ -67,12 +65,4 @@ Like above, but also writes all captured packets individually to a specified dir
```sh
loramon /dev/ttyUSB0 --freq 868000000 --bw 125000 --sf 7 --cr 5 -C -W capturedir
```
### Sniff implicit header mode packets
If you want to sniff LoRa packets with implicit header mode, use the --implicit option along with the length in bytes of the expected packet. This mode needs an RNode with a firmware version of at least 1.17.
```sh
loramon /dev/ttyUSB0 --freq 868000000 --bw 125000 --sf 7 --cr 5 -C -W capturedir --implicit 12
```
```

View File

@ -1,4 +1,3 @@
#!/usr/bin/python3
from time import sleep
import argparse
import threading
@ -9,7 +8,7 @@ import datetime
import time
import math
import traceback
from importlib import util
import importlib
class RNS():
@staticmethod
@ -49,7 +48,6 @@ class KISS():
CMD_RADIO_STATE = 0x06
CMD_RADIO_LOCK = 0x07
CMD_DETECT = 0x08
CMD_IMPLICIT = 0x09
CMD_PROMISC = 0x0E
CMD_READY = 0x0F
CMD_STAT_RX = 0x21
@ -116,8 +114,6 @@ class RNode():
self.r_lock = None
self.r_stat_rssi = 0
self.r_stat_snr = 0
self.r_implicit_length = 0
self.rssi_offset = 157
self.sf = None
@ -125,7 +121,6 @@ class RNode():
self.txpower = None
self.frequency = None
self.bandwidth = None
self.implicit_length = 0
self.detected = None
@ -258,10 +253,6 @@ class RNode():
self.r_cr = byte
RNS.log("Radio reporting coding rate is "+str(self.r_cr))
self.updateBitrate()
elif (command == KISS.CMD_IMPLICIT):
self.r_implicit_length = byte
if self.r_implicit_length != 0:
RNS.log("Radio in implicit header mode, listening for packets with a length of "+str(self.r_implicit_length)+" bytes")
elif (command == KISS.CMD_RADIO_STATE):
self.r_state = byte
elif (command == KISS.CMD_RADIO_LOCK):
@ -326,7 +317,6 @@ class RNode():
self.setTXPower()
self.setSpreadingFactor()
self.setCodingRate()
self.setImplicitLength()
self.setRadioState(KISS.RADIO_STATE_ON)
def setFrequency(self):
@ -377,15 +367,6 @@ class RNode():
if written != len(kiss_command):
raise IOError("An IO error occurred while configuring coding rate for "+self(str))
def setImplicitLength(self):
if self.implicit_length != 0:
length = KISS.escape(bytes([self.implicit_length]))
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_IMPLICIT])+length+bytes([KISS.FEND])
written = self.serial.write(kiss_command)
if written != len(kiss_command):
raise IOError("An IO error occurred while configuring implicit header mode for "+self(str))
def setRadioState(self, state):
kiss_command = bytes([KISS.FEND])+bytes([KISS.CMD_RADIO_STATE])+bytes([state])+bytes([KISS.FEND])
written = self.serial.write(kiss_command)
@ -415,18 +396,11 @@ def device_probe(rnode):
def packet_captured(data, rnode_instance):
if rnode_instance.console_output:
if rnode_instance.print_hex:
if len(data) == 1:
data = [data]
datastring = "\n"+RNS.hexrep(data)+"\n"
else:
datastring = str(data)
RNS.log("["+str(rnode_instance.r_stat_rssi)+" dBm] [SNR "+str(rnode_instance.r_stat_snr)+" dB] ["+str(len(data))+" bytes]\t"+datastring);
RNS.log("["+str(rnode_instance.r_stat_rssi)+" dBm] [SNR "+str(rnode_instance.r_stat_snr)+" dB] ["+str(len(data))+" bytes]\t"+str(data));
if rnode_instance.write_to_disk:
try:
filename = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S.%f")+".pkt"
file = open(rnode_instance.write_dir+"/"+filename, "wb")
file = open(rnode_instance.write_dir+"/"+filename, "w")
file.write(data)
file.close()
except Exception as e:
@ -436,7 +410,7 @@ def packet_captured(data, rnode_instance):
def main():
try:
if not util.find_spec("serial"):
if not importlib.util.find_spec("serial"):
raise ImportError("Serial module could not be found")
except ImportError:
print("")
@ -450,14 +424,12 @@ def main():
try:
parser = argparse.ArgumentParser(description="LoRa packet sniffer for RNode hardware.")
parser.add_argument("-C", "--console", action="store_true", help="Print captured packets to the console")
parser.add_argument("-H", "--hex", action="store_true", help="Print out packets as hexadecimal")
parser.add_argument("-W", action="store", metavar="directory", type=str, default=None, help="Write captured packets to a directory")
parser.add_argument("--freq", action="store", metavar="Hz", type=int, default=None, help="Frequency in Hz")
parser.add_argument("--bw", action="store", metavar="Hz", type=int, default=None, help="Bandwidth in Hz")
parser.add_argument("--txp", action="store", metavar="dBm", type=int, default=None, help="TX power in dBm")
parser.add_argument("--sf", action="store", metavar="factor", type=int, default=None, help="Spreading factor")
parser.add_argument("--cr", action="store", metavar="rate", type=int, default=None, help="Coding rate")
parser.add_argument("--implicit", action="store", metavar="length", type=int, default=None, help="Packet length in implicit header mode")
parser.add_argument("port", nargs="?", default=None, help="Serial port where RNode is attached", type=str)
args = parser.parse_args()
@ -540,10 +512,10 @@ def main():
print("Bandwidth in Hz:\t", end=' ')
rnode.bandwidth = int(input())
if args.txp and (args.txp >= 0 and args.txp <= 17):
if args.txp:
rnode.txpower = args.txp
else:
rnode.txpower = 0
rnode.txpower = 2
if args.sf:
rnode.sf = args.sf
@ -557,16 +529,6 @@ def main():
print("Coding rate:\t\t", end=' ')
rnode.cr = int(input())
if args.implicit:
rnode.implicit_length = args.implicit
else:
rnode.implicit_length = 0
if args.hex:
rnode.print_hex = True
else:
rnode.print_hex = False
rnode.initRadio()
rnode.setPromiscuousMode(True)
sleep(0.5)

View File

@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="loramon",
version="0.9.7",
version="0.9.3",
author="Mark Qvist",
author_email="mark@unsigned.io",
description="LoRa packet sniffer for RNode hardware",