コード例 #1
0
except:
  meteo = 0
try:
  from Config import dust
except:
  dust = 0

try:
  from Config import useGPS, thisGPS
except:
  thisGPS = [0,0,0]

if useGPS:
  thisGPS = [50.12345,6.12345,12.34]

info = struct.pack('>BBlll',0,dust|(meteo<<4),int(thisGPS[0]*100000),int(thisGPS[1]*100000), int(thisGPS[2]*10))
print("Sending version 0, meteo %s index %d, dust %s index %d, GPS: " % (Meteo[meteo], meteo,Dust[dust],dust), thisGPS)

if not n.send(info,port=3): print("send error")
else: print('Sent info')

for cnt in range(5):
  data = struct.pack('>HHHHHHHHl', 10+cnt, 15+cnt, 20+cnt, 25+cnt, 30+cnt, 35+cnt, 40+cnt, 45+cnt, time())
  #data = base64.encodestring(data)
  # Send packet
  if not n.send(data):  # send to LoRa port 2
    print("send error")
  else: print('Sent data')
  sleep(60)
print('Done')
コード例 #2
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()
コード例 #3
0
        meteo = 'unknown'
    Dust = ['unknown', 'PPD42NS', 'SDS011', 'PMS7003']
    try:
        from Config import dust
    except:
        dust = 'unknown'

    sense = ((Meteo.index(meteo) & 0xf) << 4) | (Dust.index(dust) & 0x7)
    if useGPS: sense |= 0x8
    info = struct.pack('>BBlll', 0, sense, int(thisGPS[0] * 100000),
                       int(thisGPS[1] * 100000), int(thisGPS[2] * 10))
    print(
        "Sending version 0, meteo %s, dust %s, configured GPS: " %
        (meteo, dust), thisGPS)

    if not myLoRa.send(info, port=3):
        print("Info send error")
        if LED: LED.blink(5, 0.3, 0xff0000, False)
    else:
        print('Info is sent')
        if LED: LED.blink(5, 0.3, 0x00ff00, False)

# send some data
for cnt in range(3):
    if cnt:
        if LED:
            for i in range(1, 60, 4):
                LED.blink(6, 0.5, (0x111111 * i), False)
        else:
            sleep(60)
    # old style