GithubHelp home page GithubHelp logo

adafruit_circuitpython_tinylora's Introduction

Introduction

Documentation Status

Discord

Build Status

Code Style: Black

WARNING: This library is not compatible with The Things Network v3 stack. Since TTN has fully migrated to v3, this library is not longer able to communicate with TTN.

LoRaWAN/The Things Network V2, for CircuitPython.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-tinylora

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-tinylora

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-tinylora

Usage Example

Usage is described in the learn guide for this library.

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

License

This library was written by ClemensRiederer. We've converted it to work with Adafruit CircuitPython and made changes so it works with the Raspberry Pi and Adafruit Feather M0/M4. We've added examples for using this library to transmit data and sensor data to The Things Network.

This open source code is licensed under the LGPL license (see LICENSE for details).

adafruit_circuitpython_tinylora's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_tinylora's Issues

Feature Request: Downlink

Project works great. However, I am missing the implementation to receive downlink data (i.e. data sent from the TTN to the node). To my understanding, processing of downlink data will immediately follow after the send_packet() function for uplink data. There are two receiption windows RX1 and RX2. And the latter requires considerable reconfiguration of datarate and frequencies (according to TTN spec datarate SF9BW125 at 869.525 MHz).

Already tried to extend the code to process RX1 and RX2 with no success.

Could anyone provide a working solution?

OTAA progress

Is there any progress on OTAA support, the upcoming TTNv3 migration this year is really pushing for OTAA usage.

Jetson Nano data transmit

tegwyn@tegwyn/ultrasonic_classifier/development_stuff$ cd /home/tegwyn/ultrasonic_classifier/development_stuff/ && sudo python3 lora_test_01.py
Hello blinka!
Digital IO ok!
I2C ok!
SPI ok!
done!
Temperature: 17.00 C
relative humidity: 96.0 %
Sending packet...
Traceback (most recent call last):
File "lora_test_01.py", line 119, in
lora.send_data(data, len(data), lora.frame_counter)
File "/home/tegwyn/.local/lib/python3.6/site-packages/adafruit_tinylora/adafruit_tinylora.py", line 277, in send_data
self.send_packet(lora_pkt, lora_pkt_len, timeout)
File "/home/tegwyn/.local/lib/python3.6/site-packages/adafruit_tinylora/adafruit_tinylora.py", line 323, in send_packet
raise RuntimeError("Timeout during packet send")
RuntimeError: Timeout during packet send
Exiting...
Cleaning up pins
tegwyn@tegwyn:~/ultrasonic_classifier/development_stuff$

I got all my TTN configurations sorted out on a RPi 4 and then ran the same test.py file on the Nano after installing all the circuit python stuff. Worked fine on the Pi with data seen on TTN, but not the Nano !!!!! Please help .....

Here is my code:

import time
import busio
import digitalio
import board
import adafruit_si7021
from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa

print("Hello blinka!")

Try to great a Digital input

pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")

Try to create an I2C device

i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")

Try to create an SPI device

spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
print("SPI ok!")

print("done!")

"""Using TinyLoRa with a Si7021 Sensor.
"""

Board LED

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

Create library object using our bus i2c port for si7021

i2c = busio.I2C(board.SCL, board.SDA)

sensor = adafruit_si7021.SI7021(i2c)

Create library object using our bus SPI port for radio

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

RFM9x Breakout Pinouts

cs = digitalio.DigitalInOut(board.D5)

irq = digitalio.DigitalInOut(board.D6)

rst = digitalio.DigitalInOut(board.D4)

cs = digitalio.DigitalInOut(board.D25)
irq = digitalio.DigitalInOut(board.D7)
irq = digitalio.DigitalInOut(board.D7)
rst = digitalio.DigitalInOut(board.D17)

"freq": 868100000,

"freq_2": 868100000,

"spread_factor": 7,

"pin_nss": 6,

"pin_dio0": 7,

"pin_nss_2": 6,

"pin_dio0_2": 7,

"pin_rst": 3,

"pin_led1":4,

"pin_NetworkLED": 22,

"pin_InternetLED": 23,

"pin_ActivityLED_0": 21,

"pin_ActivityLED_1": 29

Feather M0 RFM9x Pinouts

cs = digitalio.DigitalInOut(board.RFM9X_CS)

irq = digitalio.DigitalInOut(board.RFM9X_D0)

rst = digitalio.DigitalInOut(board.RFM9X_RST)

TTN Device stuff NOT shown, but tested ok.

ttn_config = TTN(devaddr, nwkey, app, country='EU')

lora = TinyLoRa(spi, cs, irq, rst, ttn_config)

Data Packet to send to TTN

data = bytearray(4)

while True:
# temp_val = sensor.temperature
# humid_val = sensor.relative_humidity
temp_val = 17
humid_val = 96
print('Temperature: %0.2f C' % temp_val)
print('relative humidity: %0.1f %%' % humid_val)

# Encode float as int
# temp_val = int(temp_val * 100)
# humid_val = int(humid_val * 100)
temp_val = 17
humid_val = 97

# Encode payload as bytes
data[0] = (temp_val >> 8) & 0xff
data[1] = temp_val & 0xff
data[2] = (humid_val >> 8) & 0xff
data[3] = humid_val & 0xff

# Send data packet
print('Sending packet...')
lora.send_data(data, len(data), lora.frame_counter)
print('Packet Sent!')
led.value = True
lora.frame_counter += 1
time.sleep(2)
led.value = False

API documentation

There doesn't seem to be an API for this, just an example of usage.

TinyLora Receive?

I need to Send and Receive from one Radio to a Second Radio not an online network. I can NOT find a Receive Example on the TinyLora Library.
Is there Anyway I can receive an Example code?

Pete

OOTA support

I got this project working very reliable, which I'm very thankful for. However, I'm in an unfortunate position that TTN does not cover the location where I'd like to deploy one of my sensors. This means I'm obligated to use a nationwide LoRa network offered by our national telecom provider KPN. Although unfortunate, this doesn't bother me too much. Anyway, this does imply that I'd need to Identify using OOTA, instead of ABP (as documented here). As the latter is not supported by KPN due to it being (and I quote) "not secure enough".

What are the chances you'll be implementing OOTA support in this Library? If you could guide me in the right direction I may be able to contribute (if desirable).

Kind regards.

Clarify LICENSE

Hello,

LICENSE file says MIT, LICENSES folder has several, and README says LGPL. Which is it? :)

Thanks

RFM9x, RPi Zero W, Adafruit Blinka, and TinyLoRa failure

I have a newly purchased RFM9x bonnet on a new RPi Zero W, and am trying to run the tinylora_simpletest.py program. This fails every time with the claim that the rfm is the wrong version. Basically, the program attempts to read register 0x42 of the rfm, expecting 0x12 to be returned. It appears that the read never happens.

Here is Python3 debug session isolating the problem:

pi@LoRa-Edge:~$ ls
pycache rfm9x_check.py rfm9x_transmit.py tinylora_simpletest_si7021.py
font5x8.bin rfm9x_rpi_interrupt.py tinylora_simpletest.py tinylora_simpletest_single_channel.py

pi@LoRa-Edge:~$ python3 tinylora_simpletest.py

/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/spi.py(55)write()
-> self._spi.writebytes2(buf[start:end])
(Pdb) w
/home/pi/tinylora_simpletest.py(36)()
-> lora = TinyLoRa(spi, cs, irq, rst, ttn_config)
/home/pi/.local/lib/python3.7/site-packages/adafruit_tinylora/adafruit_tinylora.py(159)init()
-> self._version = self._read_u8(_REG_VERSION)
/home/pi/.local/lib/python3.7/site-packages/adafruit_tinylora/adafruit_tinylora.py(370)_read_u8()
-> self._read_into(address, self._BUFFER, length=1)
/home/pi/.local/lib/python3.7/site-packages/adafruit_tinylora/adafruit_tinylora.py(363)_read_into()
-> device.write(self._BUFFER, end=1)
/home/pi/.local/lib/python3.7/site-packages/busio.py(207)write()
-> return self._spi.write(buf, start, end)
/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/spi.py(55)write()
-> self._spi.writebytes2(buf[start:end])
(Pdb) ll
43 def write(self, buf, start=0, end=None):
44 if not buf:
45 return
46 if end is None:
47 end = len(buf)
48 try:
49 self._spi.open(self._port, 0)
50 self.set_no_cs()
51 self._spi.max_speed_hz = self.baudrate
52 self._spi.mode = self.mode
53 self._spi.bits_per_word = self.bits
54 breakpoint()
55 -> self._spi.writebytes2(buf[start:end])
56 self._spi.close()
57 except FileNotFoundError as not_found:
58 print("Could not open SPI device - check if SPI is enabled in kernel!")
59 raise
(Pdb) buf[0]
66
(Pdb) buf[1]
0
(Pdb) s
/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/spi.py(56)write()
-> self._spi.close()
(Pdb) ll
43 def write(self, buf, start=0, end=None):
44 if not buf:
45 return
46 if end is None:
47 end = len(buf)
48 try:
49 self._spi.open(self._port, 0)
50 self.set_no_cs()
51 self._spi.max_speed_hz = self.baudrate
52 self._spi.mode = self.mode
53 self._spi.bits_per_word = self.bits
54 breakpoint()
55 self._spi.writebytes2(buf[start:end])
56 -> self._spi.close()
57 except FileNotFoundError as not_found:
58 print("Could not open SPI device - check if SPI is enabled in kernel!")
59 raise
(Pdb) buf[0]
66
(Pdb) buf[1]
0
(Pdb)

The relevant point is that the SpiDev device’s method self._spi.writebytes2(buf[start:end]) doesn’t work. In fact, it doesn’t even appear in dir(self._spi). I assume the actual code of this method is supposed to be in the spidev.cpython-37m-arm-linux-gnueabihf.so file coming from the spi.cc C++ code somewhere; I can’t find it.

I installed all the python locally as a user. Hers what I’ve go.

pi@LoRa-Edge:$ ls -a .local/lib/python3.7/site-packages/
. adafruit_circuitpython_si7021-3.1.5.dist-info neopixel_write.py
.. adafruit_circuitpython_ssd1306-2.7.3.dist-info pulseio.py
Adafruit_Blinka-4.1.0.dist-info adafruit_circuitpython_tinylora-2.0.2.dist-info pyftdi
Adafruit_PlatformDetect-2.3.0.dist-info adafruit_framebuf.py pyftdi-0.44.2.dist-info
Adafruit_PureIO adafruit_platformdetect pyserial-3.4.dist-info
Adafruit_PureIO-1.0.4.dist-info adafruit_rfm9x.py pyusb-1.0.2.dist-info
RPi adafruit_si7021.py rpi_ws281x
RPi.GPIO-0.7.0.dist-info adafruit_ssd1306.py rpi_ws281x-4.2.3.dist-info
pycache adafruit_tinylora serial
_rpi_ws281x.cpython-37m-arm-linux-gnueabihf.so analogio.py spidev-3.4.dist-info
adafruit_blinka bitbangio.py spidev.cpython-37m-arm-linux-gnueabihf.so
adafruit_bus_device board.py sysv_ipc-1.0.1.dist-info
adafruit_circuitpython_bitmap_font-1.0.5.dist-info busio.py sysv_ipc.cpython-37m-arm-linux-gnueabihf.so
adafruit_circuitpython_busdevice-4.2.1.dist-info digitalio.py usb
adafruit_circuitpython_framebuf-1.2.2.dist-info microcontroller
adafruit_circuitpython_rfm9x-1.2.2.dist-info micropython.py
pi@LoRa-Edge:
$

Help or pointers would be appreciated. Thank you.

raise RuntimeError('Timeout during packet send')

Hello

I have followed that procedure to use TinyLora with a Raspberry Zero to send data to the Thing network TTN with LoRaWAN
https://learn.adafruit.com/lora-and-lorawan-radio-for-raspberry-pi/usage

All went well, excepted when I send the data, I always get that error even if TTN receive the message

Sending periodic data...
Traceback (most recent call last):
File "radio_lorawan.py", line 114, in
send_pi_data_periodic()
File "radio_lorawan.py", line 70, in send_pi_data_periodic
send_pi_data(CPU)
File "radio_lorawan.py", line 80, in send_pi_data
lora.send_data(data_pkt, len(data_pkt), lora.frame_counter)
File "/usr/local/lib/python3.5/dist-packages/adafruit_tinylora/adafruit_tinylora.py", line 234, in send_data
self.send_packet(lora_pkt, lora_pkt_len, timeout)
File "/usr/local/lib/python3.5/dist-packages/adafruit_tinylora/adafruit_tinylora.py", line 275, in send_packet
raise RuntimeError('Timeout during packet send')
RuntimeError: Timeout during packet send

I looked at TTN console and each time the Raspberry send a message, I can see that my devise has been seen 1 second ago.
But my Phyton script return alway the above message instead of

Data sent!

I spend about 3 hours to understand why. I have my own gateway is in my flat, at 1m of the nodes and I just totaly reinstall the gateway.
In TTN console, the gateway is connected and seen.

I am based in Switzerland then I changed that line:

ttn_config = TTN(devaddr, nwkey, app, country='EU')

Any idea how I can debug and solve it?

By the way if you can tell me how I can display the power of signal when the message is sent, that would be GREAT.
My goal is to prepare a simple node and when I start moving away from my gateway, I would like to be able to read the power of the signal until I am too far from the gateway range. At this time the node should display "gateway lost" because it can not reach the gateway anymore.

That the only objectif of my Raspberry/TinyLoRa, but first I have to make sure that when I send a message, even if the message is receive at TTN, I do not have that message any more.

File "/usr/local/lib/python3.5/dist-packages/adafruit_tinylora/adafruit_tinylora.py", line 234, in send_data
self.send_packet(lora_pkt, lora_pkt_len, timeout)
File "/usr/local/lib/python3.5/dist-packages/adafruit_tinylora/adafruit_tinylora.py", line 275, in send_packet
raise RuntimeError('Timeout during packet send')
RuntimeError: Timeout during packet send

Thank a lot and have a good evening

Receive example

Super excited about this library. Is there an example of a downlink with this library?

Or alternatively, what functions should I use for this? That way I can test and submit a PR with a working example.

Alternatively I was also wondering if this library would work with something like LoraServer or is it only for TTN?

TTN V3

We're looking to migrate out TTN gateways to v3 as and when needed, so we need to look at using V3 in our code.
This looks to still be at v2. What's the status, if any, on planned TTN v3 compatibility.
If it's none, that's fine, just nice to know.

Library uses short argument names

pylint suggests using argument names with at least 3 letters. This library uses argument names of shorter length, and while these warnings have been disabled for now, they should be considered for renaming. This may require the rework of Learn Guides and other references to code snippets.

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_tinylora/adafruit_tinylora_encryption.py:14
  • adafruit_tinylora/adafruit_tinylora_encryption.py:46
  • adafruit_tinylora/adafruit_tinylora_encryption.py:52
  • adafruit_tinylora/adafruit_tinylora_encryption.py:59
  • adafruit_tinylora/adafruit_tinylora_encryption.py:106
  • adafruit_tinylora/adafruit_tinylora_encryption.py:137
  • adafruit_tinylora/adafruit_tinylora_encryption.py:149
  • adafruit_tinylora/adafruit_tinylora_encryption.py:178
  • adafruit_tinylora/adafruit_tinylora_encryption.py:188
  • adafruit_tinylora/adafruit_tinylora_encryption.py:197
  • adafruit_tinylora/adafruit_tinylora_encryption.py:206
  • adafruit_tinylora/adafruit_tinylora_encryption.py:217
  • adafruit_tinylora/adafruit_tinylora_encryption.py:225
  • adafruit_tinylora/adafruit_tinylora_encryption.py:248
  • adafruit_tinylora/adafruit_tinylora_encryption.py:326
  • adafruit_tinylora/adafruit_tinylora_encryption.py:347
  • adafruit_tinylora/adafruit_tinylora_encryption.py:361
  • adafruit_tinylora/adafruit_tinylora.py:73
  • adafruit_tinylora/adafruit_tinylora.py:114
  • adafruit_tinylora/adafruit_tinylora.py:207
  • adafruit_tinylora/adafruit_tinylora.py:223
  • adafruit_tinylora/adafruit_tinylora.py:269
  • adafruit_tinylora/adafruit_tinylora.py:315
  • adafruit_tinylora/adafruit_tinylora.py:333
  • adafruit_tinylora/adafruit_tinylora.py:339
  • adafruit_tinylora/adafruit_tinylora.py:356
  • adafruit_tinylora/adafruit_tinylora.py:363

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.