Ejemplo n.º 1
0
import time
import binascii
import pycom
from network import LoRa
from CayenneLPP import CayenneLPP
from pysense import Pysense
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2, ALTITUDE, PRESSURE
from network import WLAN

wlan = WLAN()
wlan.deinit()

py = Pysense()
si = SI7006A20(py)
lt = LTR329ALS01(py)
li = LIS2HH12(py)

# Disable heartbeat LED
pycom.heartbeat(False)

# Initialize LoRa in LORAWAN mode.
lora = LoRa(mode=LoRa.LORAWAN)
lora.nvram_restore()

# create an OTAA authentication parameters
app_eui = binascii.unhexlify('')
app_key = binascii.unhexlify('')
Ejemplo n.º 2
0
            return False

    else:
        return True

pycom.heartbeat(False) # Disable the heartbeat LED

# Getting the LoRa MAC
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AS923)
print("Device LoRa MAC:", binascii.hexlify(lora.mac()))

flash_led_to(YELLOW)
# joining TTN
join_lora(True)

py = Pysense()
tempHum = SI7006A20(py)
ambientLight = LTR329ALS01(py)

# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

#    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 0)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, config.LORA_NODE_DR)

s.setblocking(False)

while True:


    temperature = tempHum.temp()
Ejemplo n.º 3
0
from network import LoRa
import socket
import time
import ubinascii

import struct

import pycom

from machine import Pin
from pysense import Pysense
from SI7006A20 import SI7006A20
py = Pysense()
si = SI7006A20(py)

# Disable Hearbeat
pycom.heartbeat(False)
pycom.rgbled(0x331000)  # red

# Initialise LoRa in LORAWAN mode.
# Please pick the region that matches where you are using the device:
# Asia = LoRa.AS923
# Australia = LoRa.AU915
# Europe = LoRa.EU868
# United States = LoRa.US915

# Setup Temeprature

lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868, bandwidth=LoRa.BW_250KHZ)

# create an OTAA authentication parameters, change them to the provided credentials
Ejemplo n.º 4
0
from network import LoRa
from pysense import Pysense
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2, ALTITUDE, PRESSURE
from CayenneLPP import CayenneLPP

# Disable default blue LED blink
pycom.heartbeat(False)
# Pytrack GPS
time.sleep(2)
# enable garbage collector
gc.enable()
# Enable pytrack shield
py = Pysense()
print("Pysense firmware version: " + str(py.read_fw_version()))
counter = 0
# Init sensors
si = SI7006A20(py)
lt = LTR329ALS01(py)
li = LIS2HH12(py)
mpp = MPL3115A2(
    py, mode=PRESSURE
)  # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters
lpp = CayenneLPP()
"""
print("MPL3115A2 temperature: " + str(mp.temperature()))
print("Altitude: " + str(mp.altitude()))
print("Pressure: " + str(mpp.pressure()))
Ejemplo n.º 5
0
time.sleep(0.5)
pycom.rgbled(0x000000)
time.sleep(0.1)
pycom.rgbled(0x0000ff)
time.sleep(0.5)
pycom.rgbled(0x000000)

# Create a raw LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
# Set the LoRaWAN data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
# Make the socket non-blocking
s.setblocking(False)

# Init the libraries
pysense = Pysense()
mpl3115a2 = MPL3115A2()  # Barometric Pressure Sensor with Altimeter
ltr329als01 = LTR329ALS01()  # Digital Ambient Light Sensor
si7006a20 = SI7006A20()  # Humidity and Temperature sensor
lis2hh12 = LIS2HH12()  # 3-Axis Accelerometer

while True:

    # Read the values from the sensors
    voltage = pysense.read_battery_voltage()
    temperature = mpl3115a2.temperature()
    pressure = mpl3115a2.pressure()
    light = ltr329als01.light()[0]
    humidity = si7006a20.humidity()
    roll = lis2hh12.roll()
    pitch = lis2hh12.pitch()
Ejemplo n.º 6
0
# See https://docs.pycom.io for more information regarding library specifics

import time
import pycom
from pysense import Pysense
import machine

from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2, ALTITUDE, PRESSURE

pycom.heartbeat(False)
pycom.rgbled(0x0A0A08)  # white

py = Pysense()

mp = MPL3115A2(
    py, mode=ALTITUDE
)  # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
print("MPL3115A2 temperature: " + str(mp.temperature()))
print("Altitude: " + str(mp.altitude()))
mpp = MPL3115A2(
    py, mode=PRESSURE
)  # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters
print("Pressure: " + str(mpp.pressure()))

si = SI7006A20(py)
print("Temperature: " + str(si.temperature()) +
      " deg C and Relative Humidity: " + str(si.humidity()) + " %RH")
print("Dew point: " + str(si.dew_point()) + " deg C")
Ejemplo n.º 7
0
# Set time
print("Setting time")
rtc = machine.RTC()
rtc.ntp_sync("pool.ntp.org")
while not rtc.synced():
    machine.idle()
print("Time set to: {}".format(rtc.now()) + "\n")

# create Azure client
azure = AzureClient()

# create IBM Cloud client (MQTT) and connect
ibm = IBMClient()

py = Pysense()
# Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
mp = MPL3115A2(py, mode=ALTITUDE)
si = SI7006A20(py)
lt = LTR329ALS01(py)
li = LIS2HH12(py)

while True:
    try:
        #get new data
        temperature = mp.temperature()
        humidity = si.humidity()
        light = lt.light()
        voltage = py.read_battery_voltage()

        # micropython does not support writing compact, sorted json
Ejemplo n.º 8
0
meas_frequency = config["meas_frequency"]

pycom.heartbeat(False)  # disable periodic LED flashing

# setup wifi client
wlan = WLAN(mode=WLAN.STA)
wlan.connect(wifi_ssid, auth=(WLAN.WPA2, wifi_key), timeout=5000)
while not wlan.isconnected():
    machine.idle()  # clock gating to reduce power consumption
print("Connected to WiFi\n")
pycom.rgbled(0x00FF00)  # green LED to confirm wifi connection
time.sleep(1)
pycom.rgbled(0x000000)  #disable LED

# create our Pysense instance
py = Pysense()

# deep sleep mode of the board disables USB
# we use an interrupt on the button to stop code execution and retrieve USB control to upload new code
if py.get_wake_reason() == WAKE_REASON_PUSH_BUTTON:
    print("Stopping program")
    sys.exit()

# initialize light sensor
# 1X gain is 1lux to 64k lux range. Measurement over 500ms with samples every 100ms
lt = LTR329ALS01(py,
                 gain=LTR329ALS01.ALS_GAIN_1X,
                 integration=LTR329ALS01.ALS_INT_100,
                 rate=LTR329ALS01.ALS_RATE_500)
time.sleep(0.5)  # give time to sensor init
Ejemplo n.º 9
0
        pressure = (int(self.mp.pressure())-90000).to_bytes(2,'little')                     #Segundo Elemento Lista: Presión (entero)
        humidity = int(round(self.si.humidity(),2)*100).to_bytes(2,'little')                #Tercer Elemento Lista: Humedad (dos decimales)
        temperature = int(round(self.si.temperature(),2)*100).to_bytes(2,'little')          #Cuarto Elemento Lista: Temperatura (dos decimales)
        battery = int(round(self.py.read_battery_voltage(),4)*10000-33000).to_bytes(2,'little') #Quinto Elemento Lista: Voltaje (cuatro decimales)
        light = int(self.lt.light()[0]).to_bytes(2,'little')                                #Primer Elemento Lista: Luminosidad (entero)
        reading = light+pressure+humidity+temperature+battery                   #Union de tipos bytes
        return reading
#------------------------------------------------------------------------------#
#Codigo principal
                                                         #Desactiva el heartbeat
app_eui = binascii.unhexlify('70B3D57ED0009F73')                                #ID de la app. (Seleccionada por el usuario)
dev_eui = binascii.unhexlify('70B3D5499CE967FB')
app_key = binascii.unhexlify('054BFCAC2632EB70D56F4BCBB8D95F02')                #Clave de la app para realizar el handshake. Única para cada dispositivo.
ajuste = 5                                                                    #Numero de segundos para que el intervalo sea exacto en el Network Server
                                                                                #TODO: REAL TIME
py = Pysense()
#------------------------------------------------------------------------------#
#Según el modo de inicio, se realizan unas serie de acciones u otras.
if py.get_wake_reason() == WAKE_REASON_TIMER:                                   #Si despierta tras deepsleep
    print('Woke from a deep sleep R:%d'%(WAKE_REASON_TIMER))

    try:
        sleep_time = pycom.nvs_get('sleep_time')                                #Obtiene el valor de la variable sleep_time guardado en NVRAM
        data_rate = pycom.nvs_get('data_rate')
    except Exception:                                                                   #No se consigue obtener el valor (ERROR INFO: https://forum.pycom.io/topic/1869/efficiency-of-flash-vs-nvram-and-some-nvs-questions/3)
        print("Error: Sleep Time / Data Rate could not be recovered. Setting default value")
        sleep_time = 300                                                        #Se le da el valor por defecto
        data_rate = 5
        pycom.nvs_set('sleep_time', sleep_time)                                 #Guarda el valor por defecto de sleep_time en NVRAM
        pycom.nvs_set('data_rate', data_rate)
    print("SleepTime & Data Rate recovered")
Ejemplo n.º 10
0
        if self.raw is not self.last:
            self.last = self.raw
        else:
            pass


#------------------------------------------------------------------------------#

#Codigo principal
dev_eui = binascii.unhexlify('006A76B0778AEDA7')
app_eui = binascii.unhexlify(
    '70B3D57ED0009ABB')  #ID de la app. (Seleccionada por el usuario)
app_key = binascii.unhexlify(
    '08D62712D816F1C28B7E6EA39E711209'
)  #Clave de la app para realizar el handshake. Única para cada dispositivo.
py = Pysense()

#Según el modo de inicio, se realizan unas serie de acciones u otras.
if (py.get_wake_reason() == WAKE_REASON_ACCELEROMETER):
    print('Accelerometer Interrupt.')
    try:
        data_rate = pycom.nvs_get('data_rate')
    except (0):
        print("Error: Value could not be restore")
        data_rate = 5
        pycom.nvs_set('data_rate', data_rate)
        pass
    n = Node(data_rate, py)  #Crea una instancia de Node
    n.readsens()

elif (py.get_wake_reason() == WAKE_REASON_PUSH_BUTTON):
Ejemplo n.º 11
0
# See https://docs.pycom.io for more information regarding library specifics

from pysense import Pysense
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2, ALTITUDE, PRESSURE

try:
    py = Pysense()
    mp = MPL3115A2(
        py, mode=ALTITUDE
    )  # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
    si = SI7006A20(py)
    lt = LTR329ALS01(py)
    li = LIS2HH12(py)

    print("MPL3115A2 temperature: " + str(mp.temperature()))
    print("Altitude: " + str(mp.altitude()))
    mpp = MPL3115A2(
        py, mode=PRESSURE
    )  # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters
    print("Pressure: " + str(mpp.pressure()))

    print("Temperature: " + str(si.temperature()) +
          " deg C and Relative Humidity: " + str(si.humidity()) + " %RH")
    print("Dew point: " + str(si.dew_point()) + " deg C")
    t_ambient = 24.4
    print("Humidity Ambient for " + str(t_ambient) + " deg C is " +
          str(si.humid_ambient(t_ambient)) + "%RH")
Ejemplo n.º 12
0
from pysense import Pysense
from machine import SD

from comms import Comms
from datamanager import DataManager
from accelerometer import Accelerometer
from light import Light
from pressure import Pressure
from temphum import TempHum
from battery import Battery
from wifimanager import WiFiManager
import config

pycom.heartbeat(False)  # disable the blue blinking

py = Pysense()
sd = SD()
os.mount(sd, '/sd')
csv_file = open('/sd/data.csv', 'a')
log_file = open("/sd/log.txt", 'a')

logging.basicConfig(level=logging.DEBUG, filename=log_file)
logger = logging.getLogger("RoomMonitor")
logger.debug("Main loop starting")

comms = Comms()
wifi = WiFiManager()
comms.add_manager(0, wifi)

manager = DataManager(csv_file=csv_file)
acc = Accelerometer(
Ejemplo n.º 13
0
### Data
request = None
data = dict()
data["nFinished"] = 0
try:
    count = pycom.nvs_get('count')
except:
    count = 0

### LoRa
lora = LoRa(mode=LoRa.LORA, tx_power=14, sf=9, coding_rate=LoRa.CODING_4_6)
lora.power_mode(LoRa.TX_ONLY)

### Pysense
py = Pysense()
lt = LTR329ALS01()
################################################################################
###
### MAIN PROGRAM
###

### [0] Initialize threads
params = []
#params.append((lora_connection.loraConnection, lora, data, [], lock))
#params.append((accelerometer.get_data, (None, 2), data,
#               ("acceleration", "pitch", "roll"), lock))
params.append((thermometer.get_data, None, data, ("temperature_t", "humidity",
                                                  "dew_point"), lock))
params.append((barometer.get_data, None, data, ("altitude", "temperature_b",
                                                "pressure"), lock))
Ejemplo n.º 14
0
# See https://docs.pycom.io for more information regarding library specifics

from pysense import Pysense
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE

py = Pysense()
mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals
si = SI7006A20(py)
lt = LTR329ALS01(py)
li = LIS2HH12(py)

print(mp.temperature())
print(mp.altitude())
mpp = MPL3115A2(py,mode=PRESSURE) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters
print(mpp.pressure())
print(si.temperature())
print(si.humidity())
print(lt.light())
print(li.acceleration())
print(li.roll())
print(li.pitch())

print(py.read_battery_voltage())