Comments (12)
Successfully tested with 32bytes payload
from adafruit_circuitpython_tinylora.
not surprising - we've only use mini payloads. if you have a fix we'd super appreciate a PR, we cobbled this together from tinylora
and it kinda works but is missing a lot :)
from adafruit_circuitpython_tinylora.
FYI - I have confirmed this -- payload of 10 bytes fails -- I tried this fix, but it did not work:
diff --git a/adafruit_tinylora/adafruit_tinylora_encryption.py b/adafruit_tinylora/adafruit_tinylora_encryption.py
index 357c623..37de395 100755
--- a/adafruit_tinylora/adafruit_tinylora_encryption.py
+++ b/adafruit_tinylora/adafruit_tinylora_encryption.py
@@ -83,7 +83,7 @@ class AES():
# k = data ptr
k = 0
i = 1
- while i <= 1:
+ while i <= num_blocks:
block_a[0] = 0x01
block_a[1] = 0x00
block_a[2] = 0x00
from adafruit_circuitpython_tinylora.
Was tinylora ever tested with packets > 16 bytes either?
from adafruit_circuitpython_tinylora.
Some additional information:
I've attached a simple application that can be used for test purposes (you have to insert your keys, id and region). There are also two screenshots to illustrate whats getting to the gateway and what gets to the application at TTN.
What makes me wonder is that the data becomes "invalid" when the the full LoRa packet reaches 16bytes (two blocks mic). So I think it may have something to do with the encryption or calculation of the mic.
from adafruit_circuitpython_tinylora.
"""Simple program to demonstrate the issue with payloads larger than 7 bytes..
"""
import time
import busio
import digitalio
import board
from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa
# Create library object using our bus SPI port for radio
spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI)
# RFM9x Breakout Pinouts (They are swapped compared to the original application since the tutorial had the pins swapped when it comes to soldering)
cs = digitalio.DigitalInOut(board.D6)
irq = digitalio.DigitalInOut(board.D5)
# TTN Device Address, 4 Bytes, MSB
devaddr = bytearray([0x00, 0x00, 0x00, 0x00])
# TTN Network Key, 16 Bytes, MSB
nwkey = bytearray([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
# TTN Application Key, 16 Bytess, MSB
app = bytearray([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
ttn_config = TTN(devaddr, nwkey, app, country='EU')
lora = TinyLoRa(spi, cs, irq, ttn_config)
# Data Packet to send to TTN
# 7 bytes of Payload are working
shortPayload = bytearray(7)
# 8 bytes and more won't
longPayload = bytearray(8)
while True:
print('Sending short packet...')
lora.send_data(shortPayload, len(shortPayload), lora.frame_counter)
lora.frame_counter += 1
print('Sending long packet...')
lora.send_data(longPayload, len(longPayload), lora.frame_counter)
lora.frame_counter += 1
time.sleep(5)
from adafruit_circuitpython_tinylora.
nope we only tested with very small packets - so this is probably a real bug
from adafruit_circuitpython_tinylora.
OK -- I think I found the problem -- made these fixes
index 357c623..af8e388 100755
--- a/adafruit_tinylora/adafruit_tinylora_encryption.py
+++ b/adafruit_tinylora/adafruit_tinylora_encryption.py
@@ -83,7 +83,7 @@ class AES():
# k = data ptr
k = 0
i = 1
- while i <= 1:
+ while i <= num_blocks:
block_a[0] = 0x01
block_a[1] = 0x00
block_a[2] = 0x00
@@ -272,11 +272,12 @@ class AES():
old_data[i] = block_b[i]
block_counter = 1
# calculate until n-1 packet blocks
+ k = 0 # ptr
while block_counter < num_blocks:
+# k = 0 # ptr
# copy data into array
- k = 0 # ptr
for i in range(16):
- new_data[k] = lora_packet[i]
+ new_data[i] = lora_packet[k]
k += 1
# XOR new_data with old_data
self._xor_data(new_data, old_data)
@@ -290,7 +291,8 @@ class AES():
# perform calculation on last block
if incomplete_block_size == 0:
for i in range(16):
- new_data[i] = lora_packet[i]
+ new_data[i] = lora_packet[k]
+ k += 1
# xor with key 1
self._xor_data(new_data, key_k1)
# xor with old data
@@ -299,10 +301,10 @@ class AES():
self._aes_encrypt(new_data, self._network_key)
else:
# copy the remaining data
- k = 0 # ptr
+ # k = 0 # ptr
for i in range(16):
if i < incomplete_block_size:
- new_data[k] = lora_packet[i]
+ new_data[i] = lora_packet[k]
k += 1
if i == incomplete_block_size:
new_data[i] = 0x80
and my 10 byte payload is now getting to my appiicatiion
from adafruit_circuitpython_tinylora.
I'll do a little more testing for larger packets then put in a PR
from adafruit_circuitpython_tinylora.
I can confirm that this patch works with a 15 byte payload
Great job @jerryneedell
from adafruit_circuitpython_tinylora.
Great -- I also tested with a 30 byte payload and verified that it still works with a 6 byte payload. I'll create a PR later this evening or tomorrow.
from adafruit_circuitpython_tinylora.
amazing! !!! thank you so much :)
from adafruit_circuitpython_tinylora.
Related Issues (17)
- raise RuntimeError('Timeout during packet send') HOT 1
- Jetson Nano data transmit HOT 4
- RFM9x, RPi Zero W, Adafruit Blinka, and TinyLoRa failure HOT 15
- OOTA support HOT 1
- library for IN region
- Feature Request: Downlink HOT 8
- Clarify LICENSE HOT 2
- OTAA progress HOT 1
- API documentation HOT 5
- TTN V3 HOT 2
- TinyLora Receive? HOT 1
- Missing Type Annotations HOT 1
- TTN V3 stack not supported HOT 3
- Library uses short argument names HOT 1
- Receive example HOT 4
- ttn_AU.py incorrect HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adafruit_circuitpython_tinylora.