コード例 #1
0
def main():
    # Create the temperature sensor object using AIO pin 0
    temp = upm.Temperature(0)
    print(temp.name())

    # Read the temperature ten times, printing both the Celsius and
    # equivalent Fahrenheit temperature, waiting one second between readings
    for i in range(0, 10):
        celsius = temp.value()
        fahrenheit = celsius * 9.0 / 5.0 + 32.0
        print("%d degrees Celsius, or %d degrees Fahrenheit" \
            % (celsius, fahrenheit))
        time.sleep(1)

    # Delete the temperature sensor object
    del temp
コード例 #2
0
def leitura_temperatura():
	temperatura = upm.Temperature(pino_sensor_temperatura)
	celsius = temperatura.value()
	return celsius
コード例 #3
0
ファイル: SensTemp.py プロジェクト: Atzingen/curso-IoT
# -*- coding: latin-1 -*-
'''
Baseado no exemplo disponibilizado pela biblioteca upm/mraa da intel
para leitura do sensor de temperatura.
O sensor de temperatura é analógico.

Gustavo Voltani von Atzingen 15/04/2017
Updated: 28/09/2017

Curso IoT 2017 - IFSP Piracicaba
'''

import time
from upm import pyupm_temperature as upm

temp = upm.Temperature(0)

for i in range(0, 10):
    celsius = temp.value()
    print "{} graus Celsius".format(celsius)
    time.sleep(1)
コード例 #4
0
ファイル: sensores.py プロジェクト: TangerinoGT/IoT_2017
# -*- coding: latin-1 -*-
'''
Curso IoT 2017 - IFSP Piracicaba
Professor: Gustavo Voltani von Atzingen
alterações: Giovana Tangerino
'''
from wiringx86 import GPIOGalileo as GPIO
from upm import pyupm_temperature as upm

# numeracao dos pinos conectados aos sensores de acordo com a bibliteca usada
pino_pot = 14  #Gbiblioteca PIOGalileo: A0=14, A1=15
pino_sensor_temperatura = 1  #biblioteca pyupm_temperature: A0=0, A1=1

pinos = GPIO(debug=False)
pinos.pinMode(pino_pot, pinos.ANALOG_INPUT)
temperatura = upm.Temperature(pino_sensor_temperatura)


def get_temp():
    return temperatura.value()


def get_pot():
    resultado_adc = pinos.analogRead(pino_pot)
    voltagem = resultado_adc * 5.0 / 1023.0
    return voltagem, resultado_adc
コード例 #5
0
def main():
    dynamodb = boto3.resource('dynamodb',
    aws_access_key_id=yourkeyid,
    aws_secret_access_key=yoursecretkeyid,
    region_name='us-east-1')
    table = dynamodb.Table('iotcurrent')
    eastern = pytz.timezone('US/Eastern')
    # Instantiate a MHZ16 serial CO2 sensor on uart 0.
    # This example was tested on the Grove CO2 sensor module.
    myCO2 = upmMhz16.MHZ16(0)

    ip='192.168.1.1'
    
    ## Exit handlers ##
    # This stops python from printing a stacktrace when you hit control-C
    def SIGINTHandler(signum, frame):
        raise SystemExit

    # This function lets you run code on exit,
    # including functions from myCO2
    def exitHandler():
        print("Exiting")
        sys.exit(0)
    # Register exit handlers
    atexit.register(exitHandler)
    signal.signal(signal.SIGINT, SIGINTHandler)
    # make sure port is initialized properly.  9600 baud is the default.
    if (not myCO2.setupTty(upmMhz16.cvar.int_B9600)):
        print("Failed to setup tty port parameters")
        sys.exit(0)

    # Initiate the Temperature sensor object using A3
    temp = upmtemp.Temperature(3)
    
    # Attach microphone1 to analog port A0
    myMic1 = upmMicrophone.Microphone(0)
    threshContext1 = upmMicrophone.thresholdContext()
    threshContext1.averageReading = 0
    threshContext1.runningAverage = 0
    threshContext1.averagedOver = 2
    # Attach microphone2 to analog port A1
    myMic2 = upmMicrophone.Microphone(1)
    threshContext2 = upmMicrophone.thresholdContext()
    threshContext2.averageReading = 0
    threshContext2.runningAverage = 0
    threshContext2.averagedOver = 2
    # Attach microphone3 to analog port A2
    myMic3 = upmMicrophone.Microphone(2)
    threshContext3 = upmMicrophone.thresholdContext()
    threshContext3.averageReading = 0
    threshContext3.runningAverage = 0
    threshContext3.averagedOver = 2

    # Infinite loop, ends when script is cancelled
    # Repeatedly, take a sample every 2 microseconds;
    # find the average of 128 samples; and
    # print a running graph of dots as averages
    while(1):
        ######measure dealy#########
        delay=pp.verbose_ping(ip)

        ######## Get Temperature ########
        celsius = temp.value()
        ######## Get Co2 concentration ########
        if (not myCO2.getData()):
            print("Failed to retrieve data")
        else:
            outputStr = ("CO2 concentration: {0} PPM ".format(myCO2.getGas()))
            print(outputStr)
            co2 = myCO2.getGas()
        ####### microphone 1 #######
        buffer1 = upmMicrophone.uint16Array(128)
        len1 = myMic1.getSampledWindow(2, 128, buffer1)
        ####### microphone 2 #######
        buffer2 = upmMicrophone.uint16Array(128)
        len2 = myMic2.getSampledWindow(2, 128, buffer2)
        ####### microphone 3 #######
        buffer3 = upmMicrophone.uint16Array(128)
        len3 = myMic3.getSampledWindow(2, 128, buffer3)
        if len1:
            thresh1 = myMic1.findThreshold(threshContext1, 30, buffer1, len1)
            myMic1.printGraph(threshContext1)
            if(thresh1):
                print("Threshold mic1 is ", thresh1)
                #print("-----------------------------")
        if len2:
            thresh2 = myMic2.findThreshold(threshContext2, 30, buffer2, len2)
            myMic2.printGraph(threshContext2)
            if(thresh2):
                print("Threshold mic2 is ", thresh2)
                #print("-----------------------------")
        if len3:
            thresh3 = myMic3.findThreshold(threshContext3, 30, buffer3, len3)
            myMic3.printGraph(threshContext3)
            if(thresh3):
                print("Threshold mic3 is ", thresh3)
                #print("-----------------------------")
        print(int(datetime.datetime.now(eastern).strftime("%Y%m%d%H%M")))
        item=table.scan()['Items'][0]
		



        table.put_item(
                Item={
                    'time':int(datetime.datetime.now(eastern).strftime("%Y%m%d%H%M")),
                    'microphone1':thresh1,
                    'microphone2':thresh2,
                    'microphone3':thresh3,
                    'co2':int(co2),
                    'temp':celsius,
                    'delay':Decimal(delay),
                    'people':100
                }
            )
        table.delete_item(
			Key={
				'time':item['time']
			}
			)
        time.sleep(60)
コード例 #6
0
#import mraa
#we cant use mraa together with upm (we got a problem with ultrasonic sensor)

from upm import pyupm_light as lightObj
from upm import pyupm_gas as gasObj
from upm import pyupm_yg1006 as flameObj
from upm import pyupm_ultrasonic as ultrasonicObj
from upm import pyupm_temperature as tempObj

#analog
lumi = lightObj.Light(0)
gas = gasObj.MQ2(1)
temp = tempObj.Temperature(2)

#digital
flame = flameObj.YG1006(6)
ultrasonic = ultrasonicObj.UltraSonic(4)

# The name of sensors functions should be the same as in config.json


def luminositySensor():
    return lumi.value()


def gasSensor():  #we need to improve this
    return gas.getSample()


def flameSensor():
    return flame.flameDetected()
コード例 #7
0
import datetime
import time
import jwt
import paho.mqtt.client as mqtt

import mraa
from upm import pyupm_grove as grove
from upm import pyupm_temperature as upm
from upm import pyupm_mic as upmMicrophone

mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0")

temp = upm.Temperature(1 + 512)
light = grove.GroveLight(0 + 512)
sound = mraa.Aio(2 + 512)

cur_time = datetime.datetime.utcnow()


def create_jwt():
    token = {
        'iat': cur_time,
        'exp': cur_time + datetime.timedelta(minutes=60),
        'aud': 'intel-webinar'
    }

    with open('/home/nuc-user/intel_webinar_private.pem', 'r') as f:
        private_key = f.read()

    return jwt.encode(token, private_key, algorithm='RS256')