Пример #1
0
def setup():
  global Network, lora
  global sleep_time, STOP, myId
  global dust, meteo, thisGPS, useGPS

  display("MySense V %s" % __version__[:6], (0,0), clear=True)
  display("s/n " + myID)
  display("PM   : " + Dust[dust])
  display("meteo: " + Meteo[meteo])
  if useGPS:
    display('G:%.4f/%.4f' % (thisGPS[LAT],thisGPS[LON]))
  sleep(15)

  if Network == 'TTN':
    # Connect to LoRaWAN
    display("Try  LoRaWan", (0,0), clear=True)
    display("LoRa App EUI:")
    display(str(app_eui))
    lora = LORA()
    if lora.connect(dev_eui,app_eui,app_key, ports=2, callback=CallBack):
       display("Joined LoRaWan")
       SendInfo()
    else:
       display("NOT joined LoRa!")
       lora = None
       Network = 'None'
    sleep(10)
  if Network == 'None':
    display("No network!", (0,0), clear=True)
    LED.blink(10,0.3,0xff00ff,True)
    # raise OSError("No connectivity")
  display("Setup done")
Пример #2
0
def setup():
    global n, sensor_davis, sensor_bme280, sleep_time

    # Initial sleep time
    sleep_time = 30

    # Connect to LoRaWAN
    n = LORA()
    n.connect(dev_eui, app_eui, app_key)

    # Connect Sensors
    try:
        i2c = I2C(0)
        sensor_bme280 = BME280(i2c=i2c)
        sensor_davis = DAVIS7911()
    except Exception as e:
        print("Error: ", e)
    print("Setup... done")
Пример #3
0
def setup():
  global n, sensor_davis, sensor_temp, packet, sleep_time, state

  # Initial state and sleeptime
  state = 7
  sleep_time = 10
  
  # Init packet object
  packet = Packet()

  # Connect to LoRaWAN
  n = LORA()
  n.connect(dev_eui, app_eui, app_key)

  # Connect Sensors
  try:
    sensor_temp = SI7021()
    sensor_davis = DAVIS7911()
  except Exception as e:
    print('Error: ', e)
Пример #4
0
from lora import LORA
from config import dev_eui, app_eui, app_key
from time import sleep
from pysense import Pysense
from machine import ADC


# Formula is calculated using calibration fluids
def magicFormula(val):
    return 20.2489 - (0.00452489 * val)


try:
    adc = ADC()
    pin = adc.channel(pin='P13', attn=ADC.ATTN_11DB)
except Exception:
    pass

# Connect to LoRaWAN
n = LORA()
n.connect(dev_eui, app_eui, app_key)

# Send value
val = pin()
tmp = "%.2f" % magicFormula(val)
n.send(tmp)

py = Pysense()
py.setup_sleep(1200)  # 20 min
py.go_to_sleep()
Пример #5
0
# Turn off hearbeat LED
import pycom
pycom.heartbeat(False)

info = None
n = None
def SendInfo(port,data):
  print("info requested")
  if not data: return
  if (not info) or (not n): return
  print("Sent info")
  sleep(30)
  n.send(info,port=3)

n = LORA()
if not n.connect(dev_eui, app_eui, app_key,ports=2):
  print("Failed to connect to LoRaWan TTN")
  sys.exit(0)

# send first some info
# dust (None,Shiney,Nova,Plantower, ...) 4 low bits
# meteo (None,DHT11,DHT22,BME280,BME680, ...) 4 high bits
# GPS (longitude,latitude, altitude) float
# send 17 bytes

Dust = ['unknown','PPD42NS','SDS011','PMS7003']
Meteo = ['unknown','DHT11','DHT22','BME280','BME680']
try:
  from Config import meteo
except:
  meteo = 0
Пример #6
0
        method['OTAA'] = (dev_eui, app_eui, app_key)
        MyConfig.dump('LoRa', 'OTAA')
    except:
        pass
    # ABP keys
    try:
        from Config import dev_addr, nwk_swkey, app_swkey
        method['ABP'] = (nwk_swkey, nwk_swkey, app_swkey)
        MyConfig.dump('LoRa', 'ABP')
    except:
        pass
    if not len(method):
        raise ValueError("No LoRa keys configured or LoRa config error")
    print("Using %s LoRa methods from Config." % ', '.join(method.keys()))

if not myLoRa.connect(method, ports=2, myLED=LED, debug=True):
    print("Failed to connect to LoRaWan TTN")
    if LED: LED.blink(5, 0.3, 0xff0000, False)
    sys.exit(0)


################### LoRa
def SendInfo(port, data):
    print("info requested")
    if not data: return
    if (not info) or (not n): return
    print("Sent info")
    sleep(30)
    myLoRa.send(info, port=3)