ttn temperature

Temperature to The Things Network

This examples reads temperature data from SW01 (BME280) and sends it to The Things Network via LoRaWAN.
LoraWan implementation using CR02, CW02 and SW01
This example sends temperature data to ttn dashboard.

CR02 LED functionality

BLUE    : blinks once when keys are received
RED     : flashes once every send cycle (60sec hardcoded in .bin file)
GREEN   : Will remain steady once connection to ttn is established

A 10 second delay is utilized prior to any communication over
the i2c bus or uart. Do not remove the delay or the CW02 will lock
up when the console is opened.

If the console is needed, open it up within the 10 second interval.
Alternatively, use a terminal that can set DTR and RTS on. We
recommend CoolTerm. Do not open up zerynth console during runtime.

import streams
from xinabox.cr02_lorawan import cr02_lorawan
from xinabox.sw01 import sw01


sleep(10000) # do not remove!

# enter ttn keys generated by the ttn console. simply copy and paste.
appeui = "" # < enter appeui between quotes
deveui = "" # < eneter deveui between quotes
appkey = "" # < enter appkey between quotes

# SW01 instance
SW01 = sw01.SW01(I2C0, 0x76, 100000)

# CR02 instance
CR02 = cr02_lorawan.CR02_TTN(I2C0)

# send ttn keys to CR02 to establish a connection to ttn
CR02.init(appeui, deveui, appkey)

while True:
    temp = SW01.getTempC()  # retrieve tempearture
    CR02.sendNumber(temp)   # send tempearure to CR02. CR02 will then send the temperature to TTN every 60 seconds.