Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adafruit LoRa Radio Bonnet with OLED — RFM95W @ 915MHz — RadioFruit #69

Closed
donnahs opened this issue Jan 9, 2022 · 1 comment
Closed

Comments

@donnahs
Copy link

donnahs commented Jan 9, 2022

I brough one a few weeks ago and I cant get it to send data to the things network I have this code

import threading
import time
import subprocess
import busio
from digitalio import DigitalInOut,Direction,Pull
import board
import adafruit_ssd1306
from adafruit_tinylora.adafruit_tinylora import TTN,TinyLoRa

#Button A
btnA = DigitalInOut(board.D5)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP

#Button B
btnB = DigitalInOut(board.D6)
btnB.direction = Direction.INPUT
btnB.pull = Pull.UP

#Button C
btnC = DigitalInOut(board.D12)
btnC.direction = Direction.INPUT
btnC.pull = Pull.UP

#Create the I2C interface
i2c = busio.I2C(board.SCL,board.SDA)

#128x32 OLED Display
reset_pin = DigitalInOut(board.D4)
display = adafruit_ssd1306.SSD1306_I2C(128,32,i2c,reset=reset_pin)
#clear the display
display.fill(0)
display.show()
width = display.width
height = display.height

#TinyLora Configuration
spi = busio.SPI(board.SCK, MOSI=board.MOSI,MISO=board.MISO)
cs= DigitalInOut(board.CE1)
irq = DigitalInOut(board.D22)
rst = DigitalInOut(board.D25)

#TTN Device Address,4 Bytes MSB
devaddr = bytearray([0x00, 0x00, 0x00, 0x00])
#TTN Network Key 16 bytes,MSB
nwkey = bytearray([0x3C, 0xD4, 0x7D, 0xEF, 0x75, 0xF1, 0xFA, 0x28, 0xD8, 0x84, 0xDA, 0x5D, 0xB6, 0xF8, 0x9D, 0x0D])
#TTN Application Key,16 Bytes,MSB
app = bytearray([0x99, 0xEC, 0x31, 0x76, 0x43, 0xC7, 0x9E, 0xE1, 0xFB, 0x08, 0x61, 0xD3, 0x72, 0xD4, 0xE3, 0xB3])

#Initialize ThingsNetwork configuration
ttn_config = TTN(devaddr,nwkey,app, country='AUS')
#Initialize lora object
lora = TinyLoRa(spi, cs ,irq, rst, ttn_config)
#2b array to store sensor data
data_pkt = bytearray(2)
#time to delay periodic packet sends (in second)
data_pkt_delay = 5.0

def send_pi_data_periodic():
threading.Timer(data_pkt_delay,send_pi_data_periodic).start()
print("Sending periodic data...")
send_pi_data(CPU)
print('CPU:',CPU)

def send_pi_data(data):
#Encode float as int
data = int(data * 100)
#Encode payload as bytes
data_pkt[0] = (data >> 8) & 0xff
data_pkt[1] = data & 0xff
#send data packet
lora.send_data(data_pkt,len(data_pkt),lora.frame_counter)
lora.frame_counter += 1
display.fill(0)
display.text('send Data to TTN!',15,15,1)
print('Data sent!')
display.show()
time.sleep(0.5)

while True:
packet = None
#draw a bow to clear the image
display.fill(0)
display.text('RASPI LORAWAN',35,0,1)

#read the raspberry pi cpu load
cmd = "top -bn1 | grep load | awk '{printf\"%.1f\",$(NF-2)}'"
CPU = subprocess.check_output(cmd , shell = True)
CPU = float(CPU)

if not btnA.value:
    #send packet
    send_pi_data(CPU)
if not btnB.value:
    #Display CPU Load
    display.fill(0)
    display.text('CPU load%',45,0,1)
    display.text(str(CPU), 60, 15, 1)
    display.show()
    time.sleep(0.1)
if not btnC.value:
    display.fill(0)
    display.text('*Periodic Mode *' , 15, 0, 1)
    display.show()
    time.sleep(0.5)
    send_pi_data_periodic()
    
display.show
time.sleep(.1)

The code doen't work on the things network v3 does anyone know how to fix this

@jerryneedell
Copy link
Contributor

jerryneedell commented Jan 9, 2022

Unfortunately, the Adafruit CircuitPython TinyLora library does not support the TTN v3 stack.
See the note in this guide https://learn.adafruit.com/multi-device-lora-temperature-network/things-network-raspberry-pi-setup

Since this is not an issue with the RFM9X library.
There probably should be an issue opened on the TinyLora library regards this. I'll open one there.
Since this is not an issue with the RFM9x library, I will close this and reference it in the TinyLora issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants