Ejemplo n.º 1
0
    def __init__(self):
        self.iot = Startiot()
        self.iot.connect(False)
        self.py = Pysense()
        """
		self.gps = L76GNSS(py, timeout = 30)
		(self.lat, self.lng) = self.gps.coordinates()
		self.counter = 0
		"""
        self.state = STATE_IDLE

        self.rightpir = Pir("P11")
        self.centerpir = Pir("P2")
        self.leftpir = Pir("P9")
        self.led = Led("P10")
        self.i2c = I2C(1, I2C.MASTER, baudrate=100000, pins=("P4", "P8"))
        self.uv_sensor = VEML6070.VEML6070_UV(self.i2c)
        self.baseline = []
        pycom.heartbeat(False)  # disable the blue blinking
Ejemplo n.º 2
0
from startiot import Startiot
import pycom
import time
pycom.heartbeat(False)  # disable the blue blinking
iot = Startiot()

pycom.rgbled(0xFF0000)
iot.connect()
pycom.rgbled(0x0000FF)

count = 0
while True:
    print("Sending data...", count)
    data = "Hello from the LoPy: %s" % (count)
    count = count + 1

    # send some data
    iot.send(data)
    pycom.rgbled(0x00ff00)
    time.sleep(0.1)
    pycom.rgbled(0x000000)
    time.sleep(0.1)
    pycom.rgbled(0x00ff00)
    time.sleep(0.1)
    pycom.rgbled(0x000000)
    print("Sending data done...")

    # get any data received
    data = iot.recv(64)
    print("Received Data:", data)
Ejemplo n.º 3
0
class AnimalAlert():
    def __init__(self):
        self.iot = Startiot()
        self.iot.connect(False)
        self.py = Pysense()
        """
		self.gps = L76GNSS(py, timeout = 30)
		(self.lat, self.lng) = self.gps.coordinates()
		self.counter = 0
		"""
        self.state = STATE_IDLE

        self.rightpir = Pir("P11")
        self.centerpir = Pir("P2")
        self.leftpir = Pir("P9")
        self.led = Led("P10")
        self.i2c = I2C(1, I2C.MASTER, baudrate=100000, pins=("P4", "P8"))
        self.uv_sensor = VEML6070.VEML6070_UV(self.i2c)
        self.baseline = []
        pycom.heartbeat(False)  # disable the blue blinking

    """
	def get_gps(self):		
		if (self.lat, self.lng) == (None, None):
			(self.lat, self.lng) = self.gps.coordinates()
		else: 
			if self.counter < GPS_NUMCOPIES:
				(self.lat, self.lng) = (self.lat, self.lng)
				self.counter += 1
			else: 
				self.counter = 1
				(self.lat, self.lng) = self.gps.coordinates()

		return(self.lat, self.lng)
	"""

    def uv_baseline(self, uv):
        if len(self.baseline) == BASELINE_MAX:
            self.baseline.pop(0)
            self.baseline.append(uv)
        else:
            self.baseline.append(uv)

        average = sum(self.baseline) / len(self.baseline)
        return average

    def notify(self, left, center, right):
        data = "{},{},{}".format(left, center, right)
        if center == 1:
            self.state = STATE_WARNING
            self.led.blink(LED_DELAY, LED_DURATION)
            self.iot.send(data)
            print("sent to startIoT")

        elif left == 1 or right == 1:
            self.state = STATE_ALERT
            self.led.blink(LED_DELAY, LED_DURATION)
            self.iot.send(data)
            print("sent to startIoT")

        #(lat, lng) = self.get_gps()
        #data = "{},{},{},{},{},{}".format(left, center, right, lat, lng, uv)

    def run(self):
        # main loop
        while True:
            centerval = self.centerpir.check_sensor()
            rightval = self.rightpir.check_sensor()
            lefval = self.leftpir.check_sensor()
            uv = self.uv_sensor.read()

            average = self.uv_baseline(uv)
            print(lefval, centerval, rightval, uv, average)

            if centerval == 1 or lefval == 1 or rightval == 1:
                if uv > average + BASELINE_DIFF:
                    pass
                else:
                    self.notify(lefval, centerval, rightval)
                    self.state = STATE_IDLE

            self.led.stop
            sleep(SLEEPTIME_MAIN)
Ejemplo n.º 4
0
from startiot import Startiot
import pycom
from time import sleep
from machine import Pin
from onewire import DS18X20
from onewire import OneWire

pycom.heartbeat(False)
iot = Startiot()
iot.connect(False)

ow = OneWire(Pin('P9'))
temp = DS18X20(ow)

state = False

while True:
    tmp = temp.read_temp_async()
    print(tmp)
    sleep(1)
    temp.start_convertion()
    iot.send("TEMP,%f" % tmp)
    sleep(30)
Ejemplo n.º 5
0
# Initiation
print("Initializing")
pycom.heartbeat(False) # disable the blue blinking
pycom.rgbled(0x0000FF)
# Bus initializing
i2c = I2C(0, I2C.MASTER)
# Sensor initalizing
Mag = MAG_3110(nMeasurements, nSeconds, prs_deviate) # Used to read magnetic data
MPU = MPU_9265() # Used to read accellerometer data

print(i2c.scan())

if CONNECT_DEVICE:
    print("Device was set in lora mode.")
    iot = Startiot()
    pycom.rgbled(0xFF0000)
    print("Awaiting connection to lora network")
    iot.connect()
    print("Connection found. Continuing")
    pycom.rgbled(0x00FF00)


'''
This is the loop where the box will reside doing measurements. 
'''
while True:
    # Get accelerometer data
    MPUDATA = MPU.fetch_data()

    '''
Ejemplo n.º 6
0
    {'hr': 78, 'temp': 36.7, 'SpO2': 97.0, 'latlng': "69.68141, 18.97231"},
    {'hr': 79, 'temp': 37.0, 'SpO2': 96.7, 'latlng': "69.68141, 18.97231"},
    {'hr': 81, 'temp': 36.9, 'SpO2': 96.8, 'latlng': "69.68141, 18.97231"},
    {'hr': 78, 'temp': 36.8, 'SpO2': 96.7, 'latlng': "69.68141, 18.97231"},
    {'hr': 78, 'temp': 36.9, 'SpO2': 96.5, 'latlng': "69.68141, 18.97231"},
    {'hr': 77, 'temp': 36.9, 'SpO2': 97.0, 'latlng': "69.68141, 18.97231"},
    {'hr': 82, 'temp': 37.0, 'SpO2': 97.4, 'latlng': "69.68141, 18.97231"},
    {'hr': 81, 'temp': 37.2, 'SpO2': 97.5, 'latlng': "69.68141, 18.97231"},
    {'hr': 79, 'temp': 37.1, 'SpO2': 97.6, 'latlng': "69.68141, 18.97231"},
    {'hr': 77, 'temp': 37.0, 'SpO2': 97.6, 'latlng': "69.68141, 18.97231"},
]

# disable the blue blinking
pycom.heartbeat(False)

iot = Startiot()
pycom.rgbled(0xFF0000)
iot.connect()
pycom.rgbled(WHITE)

count = 1

colors = {
    'red': RED,
    'yellow': YELLOW,
    'green': GREEN
}

for data in readings:
    data['count'] = count
    count = count + 1
Ejemplo n.º 7
0
from startiot import Startiot
import pycom
from time import sleep
from machine import Pin

pycom.heartbeat(False)
iot = Startiot()
iot.connect(False)

pir = Pin('P23', mode=Pin.IN, pull=Pin.PULL_DOWN)

state = False

while True:
    val = pir()
    print('Value:', val)

    if state == False:
        if val == 1:
            state = True
            iot.send('MOTION,1')
            sleep(60)
    else:
        if val == 0:
            state = False

    sleep(0.1)