Compare commits
3 Commits
master
...
856d590eeb
| Author | SHA1 | Date | |
|---|---|---|---|
| 856d590eeb | |||
| c83e7d0901 | |||
| bbceb8683b |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -114,4 +114,5 @@ dmypy.json
|
|||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|
||||||
/test/lora.conf
|
/test/
|
||||||
|
/make.conf
|
||||||
|
|||||||
8
.idea/dictionaries/akira.xml
generated
Normal file
8
.idea/dictionaries/akira.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="akira">
|
||||||
|
<words>
|
||||||
|
<w>hweui</w>
|
||||||
|
<w>preprogrammed</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
1
.idea/rn2483lora.iml
generated
1
.idea/rn2483lora.iml
generated
@@ -3,6 +3,7 @@
|
|||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/rn2483lora" isTestSource="false" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/test" />
|
<excludeFolder url="file://$MODULE_DIR$/test" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.6" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.6" jdkType="Python SDK" />
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
port = /dev/ttyUSB0
|
port = /dev/ttyUSB0
|
||||||
|
baud = 57600
|
||||||
appskey =
|
appskey =
|
||||||
nwkskey =
|
nwkskey =
|
||||||
devaddr =
|
devaddr =
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""Module for LoRaWAN chip RN2483."""
|
"""Module for LoRaWAN chip RN2483."""
|
||||||
|
from rn2483 import RN2483
|
||||||
__author__ = "Sven Sager"
|
__author__ = "Sven Sager"
|
||||||
__copyright__ = "Copyright (C) 2019 Sven Sager"
|
__copyright__ = "Copyright (C) 2019 Sven Sager"
|
||||||
__license__ = "GPLv3"
|
__license__ = "LGPLv3"
|
||||||
|
__version__ = "0.1.0"
|
||||||
|
__all__ = [
|
||||||
|
"RN2483",
|
||||||
|
]
|
||||||
79
rn2483lora/cli.py
Normal file
79
rn2483lora/cli.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Command line for RN2483 LoRaWAN."""
|
||||||
|
from rn2483 import RN2483
|
||||||
|
|
||||||
|
__author__ = "Sven Sager"
|
||||||
|
__copyright__ = "Copyright (C) 2019 Sven Sager"
|
||||||
|
__license__ = "LGPLv3"
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from configparser import ConfigParser
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
conf = ConfigParser()
|
||||||
|
conf.read("lora.conf")
|
||||||
|
|
||||||
|
root = RN2483(
|
||||||
|
conf.get("DEFAULT", "port"),
|
||||||
|
conf.get("DEFAULT", "baud", fallback=57600),
|
||||||
|
)
|
||||||
|
|
||||||
|
def first_init() -> None:
|
||||||
|
"""Init our RN2483 after firmware startup."""
|
||||||
|
|
||||||
|
print(root.version)
|
||||||
|
print(root.hweui)
|
||||||
|
|
||||||
|
# Configuration: ["cmd", results]
|
||||||
|
cmd_list = [
|
||||||
|
["mac reset 868", 1],
|
||||||
|
|
||||||
|
# Set TTN configurations form .conf file
|
||||||
|
["mac set appskey {0}".format(conf.get("DEFAULT", "appskey")), 1],
|
||||||
|
["mac set nwkskey {0}".format(conf.get("DEFAULT", "nwkskey")), 1],
|
||||||
|
["mac set devaddr {0}".format(conf.get("DEFAULT", "devaddr")), 1],
|
||||||
|
|
||||||
|
["mac join abp", 2],
|
||||||
|
["mac set ar on", 1],
|
||||||
|
]
|
||||||
|
for do_cmd in cmd_list:
|
||||||
|
print("<-", do_cmd[0])
|
||||||
|
print("->", root.send(do_cmd[0]))
|
||||||
|
|
||||||
|
# Get awaited extra results results
|
||||||
|
for i in range(do_cmd[1] - 1):
|
||||||
|
print(" ", root.get_result())
|
||||||
|
|
||||||
|
first_init()
|
||||||
|
|
||||||
|
# Command mode
|
||||||
|
while True:
|
||||||
|
results = 1
|
||||||
|
|
||||||
|
cmd_input = input("<- ")
|
||||||
|
if cmd_input == "exit":
|
||||||
|
break
|
||||||
|
elif cmd_input == "reset":
|
||||||
|
root.send("sys reset")
|
||||||
|
sleep(3)
|
||||||
|
first_init()
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Functions to make live more easier
|
||||||
|
elif cmd_input.find("send ") > -1:
|
||||||
|
lst = cmd_input.split()
|
||||||
|
cmd_input = "mac tx uncnf {port} {bytes}".format(
|
||||||
|
port=lst[2] if len(lst) > 2 else 1,
|
||||||
|
bytes=lst[1] if len(lst) > 1 else "",
|
||||||
|
)
|
||||||
|
results = 2
|
||||||
|
|
||||||
|
# Always send command
|
||||||
|
if cmd_input:
|
||||||
|
print("->", root.send(cmd_input))
|
||||||
|
|
||||||
|
# Get awaited extra results results
|
||||||
|
for i in range(results - 1):
|
||||||
|
print(" ", root.get_result())
|
||||||
|
|
||||||
|
root.close()
|
||||||
@@ -7,7 +7,7 @@ from serial import Serial
|
|||||||
|
|
||||||
__author__ = "Sven Sager"
|
__author__ = "Sven Sager"
|
||||||
__copyright__ = "Copyright (C) 2019 Sven Sager"
|
__copyright__ = "Copyright (C) 2019 Sven Sager"
|
||||||
__license__ = "GPLv3"
|
__license__ = "LGPLv3"
|
||||||
|
|
||||||
|
|
||||||
class RN2483:
|
class RN2483:
|
||||||
@@ -83,71 +83,22 @@ class RN2483:
|
|||||||
if get_result:
|
if get_result:
|
||||||
return self.get_result(timeout)
|
return self.get_result(timeout)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hweui(self):
|
||||||
|
"""
|
||||||
|
Reads the preprogrammed EUI node address.
|
||||||
|
|
||||||
if __name__ == '__main__':
|
This command reads the preprogrammed EUI node address from the RN2483
|
||||||
from configparser import ConfigParser
|
module. The value returned by this command is a globally unique number
|
||||||
from time import sleep
|
provided by Microchip.
|
||||||
|
:return: Preprogrammed EUI node address
|
||||||
|
"""
|
||||||
|
return self.send("sys get hweui", True)
|
||||||
|
|
||||||
conf = ConfigParser()
|
@property
|
||||||
conf.read("lora.conf")
|
def version(self) -> str:
|
||||||
|
"""
|
||||||
root = RN2483(conf.get("DEFAULT", "port"))
|
Get information on hardware platform, firmware version, release date.
|
||||||
|
:return: RN2483 X.Y.Z MMM DD YYYY HH:MM:SS
|
||||||
def first_init() -> None:
|
"""
|
||||||
"""Init our RN2483 after firmware startup."""
|
return self.send("sys get ver", True)
|
||||||
|
|
||||||
# Configuration: ["cmd", results]
|
|
||||||
cmd_list = [
|
|
||||||
["sys get ver", 1],
|
|
||||||
["mac reset 868", 1],
|
|
||||||
["sys get hweui", 1],
|
|
||||||
|
|
||||||
# Set TTN configurations form .conf file
|
|
||||||
["mac set appskey {0}".format(conf.get("DEFAULT", "appskey")), 1],
|
|
||||||
["mac set nwkskey {0}".format(conf.get("DEFAULT", "nwkskey")), 1],
|
|
||||||
["mac set devaddr {0}".format(conf.get("DEFAULT", "devaddr")), 1],
|
|
||||||
|
|
||||||
["mac join abp", 2],
|
|
||||||
["mac set ar on", 1],
|
|
||||||
]
|
|
||||||
for do_cmd in cmd_list:
|
|
||||||
print("<-", do_cmd[0])
|
|
||||||
print("->", root.send(do_cmd[0]))
|
|
||||||
|
|
||||||
# Get awaited extra results results
|
|
||||||
for i in range(do_cmd[1] - 1):
|
|
||||||
print(" ", root.get_result())
|
|
||||||
|
|
||||||
first_init()
|
|
||||||
|
|
||||||
# Command mode
|
|
||||||
while True:
|
|
||||||
results = 1
|
|
||||||
|
|
||||||
cmd_input = input("<- ")
|
|
||||||
if cmd_input == "exit":
|
|
||||||
break
|
|
||||||
elif cmd_input == "reset":
|
|
||||||
root.send("sys reset")
|
|
||||||
sleep(3)
|
|
||||||
first_init()
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Functions to make live more easier
|
|
||||||
elif cmd_input.find("send ") > -1:
|
|
||||||
lst = cmd_input.split()
|
|
||||||
cmd_input = "mac tx uncnf {port} {bytes}".format(
|
|
||||||
port=lst[2] if len(lst) > 2 else 1,
|
|
||||||
bytes=lst[1] if len(lst) > 1 else "",
|
|
||||||
)
|
|
||||||
results = 2
|
|
||||||
|
|
||||||
# Always send command
|
|
||||||
if cmd_input:
|
|
||||||
print("->", root.send(cmd_input))
|
|
||||||
|
|
||||||
# Get awaited extra results results
|
|
||||||
for i in range(results - 1):
|
|
||||||
print(" ", root.get_result())
|
|
||||||
|
|
||||||
root.close()
|
|
||||||
44
setup.py
Normal file
44
setup.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Setup for rn2482lora module."""
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
__author__ = "Sven Sager"
|
||||||
|
__copyright__ = "Copyright (C) 2019 Sven Sager"
|
||||||
|
__license__ = "LGPLv3"
|
||||||
|
|
||||||
|
setup(
|
||||||
|
version='0.1.0',
|
||||||
|
|
||||||
|
packages=['rn2483lora'],
|
||||||
|
python_requires="~=3.4",
|
||||||
|
install_requires=["pyserial"],
|
||||||
|
keywords="lora network lorawan iot",
|
||||||
|
|
||||||
|
# Additional meta-data
|
||||||
|
name='rn2483lora',
|
||||||
|
author='Sven Sager',
|
||||||
|
author_email='akira@narux.de',
|
||||||
|
maintainer="Sven Sager",
|
||||||
|
maintainer_email="akira@narux.de",
|
||||||
|
url='https://narux.de',
|
||||||
|
description='Wraper module for microchips LoRaWAN chip RN2483',
|
||||||
|
long_description="Add LoRaWAN capabilities to your python program. This module will help you "
|
||||||
|
"to use the RN2483 chip of microchips. It will manage the serial communication "
|
||||||
|
"and send data over LoRaWAN.",
|
||||||
|
download_url="",
|
||||||
|
classifiers=[
|
||||||
|
"Development Status :: 1 - Planning",
|
||||||
|
# "Development Status :: 2 - Pre-Alpha",
|
||||||
|
# "Development Status :: 3 - Alpha",
|
||||||
|
# "Development Status :: 4 - Beta",
|
||||||
|
# "Development Status :: 5 - Production/Stable",
|
||||||
|
"Environment :: Console",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||||
|
"Topic :: System :: Networking",
|
||||||
|
],
|
||||||
|
license='LGPLv3',
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user