Пример #1
0
class LoRaWanRadio(Device):

    def __init__(self, spi, cs_pin, reset_pin,
                 dev_addr, nwk_key, app_key, tx_led=None,
                 name="lrw0", interval=10.0, *args, **kwargs):

        Device.__init__(self, name=name, interval=interval, *args, **kwargs)

        from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa
        import digitalio

        cs = digitalio.DigitalInOut(cs_pin)
        reset = digitalio.DigitalInOut(reset_pin)

        self.tx_led = tx_led
        if self.tx_led:
            self.tx_led = digitalio.DigitalInOut(tx_led)
            self.tx_led.direction = digitalio.Direction.OUTPUT

        ttn_config = TTN(dev_addr, nwk_key, app_key, country='US')
        # Suppose to be cs, irq, rst, ttn_config?
        self.lora = TinyLoRa(spi, cs, reset, ttn_config)

        self.data["tx_buffer"] = None

    def write(self):

        if self.tx_led:
            self.tx_led.value = True

        if self.data["tx_buffer"]:
            data = self.data["tx_buffer"]
            self.lora.send_data(data, len(data), self.lora.frame_counter)

            print("LORAWAN TX: {}".format(self.data["tx_buffer"]))
            self.data["tx_buffer"] = None

            self.lora.frame_counter += 1

        if self.tx_led:
            self.tx_led.value = False
Пример #2
0
    def __init__(self, spi, cs_pin, reset_pin,
                 dev_addr, nwk_key, app_key, tx_led=None,
                 name="lrw0", interval=10.0, *args, **kwargs):

        Device.__init__(self, name=name, interval=interval, *args, **kwargs)

        from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa
        import digitalio

        cs = digitalio.DigitalInOut(cs_pin)
        reset = digitalio.DigitalInOut(reset_pin)

        self.tx_led = tx_led
        if self.tx_led:
            self.tx_led = digitalio.DigitalInOut(tx_led)
            self.tx_led.direction = digitalio.Direction.OUTPUT

        ttn_config = TTN(dev_addr, nwk_key, app_key, country='US')
        # Suppose to be cs, irq, rst, ttn_config?
        self.lora = TinyLoRa(spi, cs, reset, ttn_config)

        self.data["tx_buffer"] = None
Пример #3
0
def init_lora():
    global lora
    # Create library object using our bus SPI port for radio
    spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI)
    # RFM9x Breakout Pinouts
    cs = digitalio.DigitalInOut(board.D6)
    irq = digitalio.DigitalInOut(board.D5)
    # TTN Device Address, 4 Bytes, MSB
    devaddr = bytearray([0x26, 0x01, 0x14, 0xE1])
    # TTN Network Key, 16 Bytes, MSB
    nwkey = bytearray([
        0xAF, 0x6E, 0xE8, 0xC4, 0x20, 0x42, 0x62, 0x86, 0x96, 0xFB, 0xFB, 0xF7,
        0x74, 0x00, 0xA7, 0xA1
    ])
    # TTN Application Key, 16 Bytess, MSB
    app = bytearray([
        0x7F, 0x06, 0x6A, 0xF1, 0xE2, 0xD9, 0xDB, 0x62, 0x53, 0x39, 0x53, 0xA7,
        0x90, 0x9D, 0x60, 0xC2
    ])
    ttn_config = TTN(devaddr, nwkey, app, country='EU')
    lora = TinyLoRa(spi, cs, irq, ttn_config)
Пример #4
0
# 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='US')

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

# Data Packet to send to TTN
data = bytearray(4)

while True:
    temp_val = sensor.temperature
    humid_val = sensor.relative_humidity
    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)

    # Encode payload as bytes
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([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])
# Initialize ThingsNetwork configuration
ttn_config = TTN(devaddr, nwkey, app, country='US')
# 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 seconds)
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)
Пример #6
0
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
])

ttn_config = TTN(devaddr, nwkey, app, country="US")

# Broadcasting on channel 0 in US Region - 903.9 MHz
lora = TinyLoRa(spi, cs, irq, rst, ttn_config, channel=0)

while True:
    data = bytearray(b"\x43\x57\x54\x46")
    print("Sending packet...")
    lora.send_data(data, len(data), lora.frame_counter)
    print("Packet sent!")
    led.value = True
    lora.frame_counter += 1
    time.sleep(1)
    led.value = False
Пример #7
0
# cs = digitalio.DigitalInOut(board.RFM9X_CS)

# 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='US')

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

# Data Packet to send to TTN
data = bytearray(4)

while True:
    temp_val = sensor.temperature
    humid_val = sensor.relative_humidity
    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)

    # Encode payload as bytes
Пример #8
0
# TTN Device Address, 4 Bytes, MSB
devaddr = bytearray([0x00, 0x79, 0xCD, 0x6D])
# TTN Network Key, 16 Bytes, MSB
nwkey = bytearray([
    0x3d, 0x7a, 0x37, 0x74, 0x27, 0x53, 0x66, 0xda, 0x39, 0x61, 0x6f, 0xf4,
    0x23, 0xbe, 0x97, 0x2e
])
# TTN Application Key, 16 Bytess, MSB
app = bytearray([
    0x4f, 0x5c, 0x0c, 0xb0, 0xd3, 0x2a, 0x80, 0x91, 0x54, 0x46, 0x67, 0x54,
    0x2d, 0x19, 0x36, 0x52
])
# Initialize ThingsNetwork configuration
gway_config = TTN(devaddr, nwkey, app, country='US')
# Initialize lora object
lora = TinyLoRa(spi, cs, irq, rst, gway_config)
lora.set_datarate("SF10BW125")
# 2b array to store sensor data
# data_pkt = bytearray(2)
# time to delay periodic packet sends (in seconds)
data_pkt_delay = 5.0


def send_pi_data(data):
    # data = int(data)
    # Encode payload as bytes
    # data_pkt[0] = (data >> 8) & 0xff
    # data_pkt[1] = data & 0xff
    # Send data packet
    data_pkt = (data).to_bytes(2, byteorder='big')
    print(data)
Пример #9
0
# Create library object using our bus SPI port for radio
spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI)
# RFM9x Breakout Pinouts
cs = digitalio.DigitalInOut(board.D6)
irq = digitalio.DigitalInOut(board.D5)
# TTN Device Address, 4 Bytes, MSB
devaddr = bytearray([0x26, 0x01, 0x14, 0xE1])
# TTN Network Key, 16 Bytes, MSB
nwkey = bytearray([0xAF, 0x6E, 0xE8, 0xC4, 0x20, 0x42, 0x62, 0x86,
                   0x96, 0xFB, 0xFB, 0xF7, 0x74, 0x00, 0xA7, 0xA1])
# TTN Application Key, 16 Bytess, MSB
app = bytearray([0x7F, 0x06, 0x6A, 0xF1, 0xE2, 0xD9, 0xDB, 0x62,
                 0x53, 0x39, 0x53, 0xA7, 0x90, 0x9D, 0x60, 0xC2])
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)
Пример #10
0
# TTN Network Key, 16 Bytes, MSB
nwkey = bytearray([
    0xEF, 0xD6, 0xD1, 0xD4, 0xB7, 0xDB, 0x64, 0x28, 0x60, 0xBE, 0x90, 0xD0,
    0xD8, 0x6D, 0x03, 0xDC
])

# TTN Application Key, 16 Bytess, MSB
app = bytearray([
    0xB9, 0xC2, 0x67, 0x8A, 0xF9, 0xF4, 0x92, 0x24, 0x1F, 0xED, 0x2D, 0x10,
    0xFF, 0x3D, 0xB6, 0x3B
])

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

lora = TinyLoRa(spi2, cs, irq, rst, ttn_config, channel=0)

# Data Packet to send to TTN
data = bytearray(7)


def get_image():
    with picamera.PiCamera() as camera:
        camera.resolution = (1296, 972)
        camera.start_preview()
        # Camera warm-up time
        count = 0
        while (count < 3):
            GPIO.output(PIN5, GPIO.HIGH)
            time.sleep(0.5)
            GPIO.output(PIN5, GPIO.LOW)
# 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='US')

lora = TinyLoRa(spi, cs, irq, ttn_config, channel=6)

# bme data packet
bme_d = bytearray(7)

while True:
    # Grab sensor data
    temp_val = int(bme280.temperature * 100)
    humid_val = int(bme280.humidity * 100)

    bme_d[0] = FEATHER_ID
    # Temperature data
    bme_d[1] = (temp_val >> 8) & 0xff
    bme_d[2] = temp_val & 0xff
    # Humidity data
    bme_d[3] = (humid_val >> 8) & 0xff
Пример #12
0
#set up the temperature sensor device for tiny lora
temp_addr = bytearray([0x26, 0x01, 0x18, 0x92])
# network key from the things network console
temp_netw_key = bytearray([
    0x4E, 0xF8, 0x21, 0xA4, 0x11, 0x98, 0xA8, 0x5D, 0x51, 0x2D, 0x2A, 0xD3,
    0x0C, 0xCA, 0x91, 0xB7
])
# application key from the things network console
temp_app_key = bytearray([
    0x22, 0xD5, 0xC3, 0x29, 0xE9, 0x06, 0x77, 0xD9, 0x22, 0xBB, 0x28, 0xA6,
    0x0B, 0x55, 0xB0, 0x62
])
#configure the moisture sensor for the things network
temp_ttn_config = TTN(temp_addr, temp_netw_key, temp_app_key, country="EU")
# create a tiny loar object for the temperature sensor
temp_lora = TinyLoRa(spi, cs, irq, rst, temp_ttn_config, channel=0)

# set up the moisture sensor device for tiny lora
moisture_addr = bytearray([0x26, 0x01, 0x15, 0xA9])
# network key from the things network console
moisture_netw_key = bytearray([
    0xD9, 0x56, 0xFE, 0x3B, 0xDB, 0x76, 0x78, 0x4D, 0xBA, 0x28, 0x1E, 0x5D,
    0x89, 0xE2, 0x11, 0xD4
])
# application key from the things network console
moisture_app_key = bytearray([
    0xB2, 0x26, 0xDE, 0x4B, 0xB5, 0x99, 0xF7, 0x7D, 0xDD, 0xE1, 0xCD, 0x0B,
    0x6C, 0x9D, 0xF2, 0x0E
])
# configure the moisture sensor for the things network
moisture_ttn_config = TTN(moisture_addr,