示例#1
0
def readMotionSensor(gpioNum):
    motionSensor_url = srmlib.url_builder(
        url=DEVICE_URL, path='/phy/gpio/{}/value'.format(gpioNum))
    motion_object = srmlib.SRMClient(url=motionSensor_url,
                                     https_check=https_check,
                                     verbose=verbose)
    return motion_object
示例#2
0
def readRegister(portNumber, slaveAddress):
    value_url = srmlib.url_builder(url=DEVICE_URL,
                                   path='/phy/i2c/{}/slaves/{}/value'.format(
                                       portNumber, slaveAddress))
    value = srmlib.SRMClient(url=value_url,
                             https_check=https_check,
                             verbose=verbose)
    return value
from flask import Flask
from flask_ask import Ask, statement, convert_errors
import logging
import srmlib_ublox as srmlib

url = "https://193.2.179.243:46300"
https_check = srmlib.HTTPS_BASIC
verbose = True
client = srmlib.SRMClient(url=url, https_check=https_check, verbose=verbose)

rewards = [(-1, "did not do well"), (1, "is ok"), (2, "did well")]
algoreward = [0]

leds = []
for i in range(3):
    led_url = srmlib.url_builder(url=url,
                                 path='/log/integer/{}/value'.format(i))
    led = srmlib.SRMClient(url=led_url,
                           https_check=https_check,
                           verbose=verbose)
    leds.append(led)

app = Flask(__name__)
ask = Ask(app, '/')

logging.getLogger("flask_ask").setLevel(logging.DEBUG)


@app.route('/')
def home_page():
    return '<h1>Welcome to my site!</h1>'
示例#4
0
DEVICE_ID = '1'

flag = 0
MOTION_SENSOR_PIN = 23

humidity_value = 20
temperature_value = 20
motion_value = 0

# Reset configuration just in case
print("\nRebooting...")
#client.reboot(wait=True)

client = srmlib.SRMClient(url=DEVICE_URL,
                          https_check=https_check,
                          verbose=verbose)

#communication I2C
#initI2c(I2C_PORT)
#initI2cSlave(I2C_PORT, HDC_ADDRESS)
#setDatasize(I2C_PORT, HDC_ADDRESS, 2)

#communication Motion sensor
#allocatePin(MOTION_SENSOR_PIN)
#configPin(MOTION_SENSOR_PIN)

while 1:
    try:
        temperature_value = refreshTemperature(I2C_PORT, HDC_ADDRESS,
                                               HDC_TEMP_REGISTER)
示例#5
0
	return humidity

def readLum(client):
	client.put('/phy/i2c/1/slaves/41/value', data='"B4"')
	data = client.get('/phy/i2c/1/slaves/41/value').content

def readCo(client):
	data = client.get('/phy/i2c/1/slaves/72/value').content
	return int(data[2:5],16)

def avgCo(arr):
	return sum(arr) / len(arr)



m3 = srmlib.SRMClient(url="https://m3.srm.bajtahack.si:46300", https_check=https_check, verbose=verbose)
m3ceoSamp = []

a = srmlib.SRMClient(url="https://193.2.178.251", https_check=https_check, verbose=verbose)

print("\nWorking...")

ti = datetime.datetime.now()
c = conn.cursor()
#read seansor a#print("Read A!")#print(readTemp(a))#print(readHumi(a))#print(readCo(a))
print("Read M3!")
temp = readTemp(m3)
hum = readHumi(m3)
m3ceoSamp.append(readCo(m3))

if(len(m3ceoSamp) > 10):
def izhod():
    GPIO.cleanup()
    client.delete('/phy/gpio/{}/alloc'.format(led_gpio))


atexit.register(izhod)

# Parameters
url = "https://localhost:46100"
https_check = srmlib.HTTPS_BASIC
verbose = True
led_gpio = 18

# Create SRM manager
client = srmlib.SRMClient(url=url, https_check=https_check, verbose=verbose)

# Reset configuration just in case
#print("\nRebooting...")
#client.reboot(wait=True)

# Initialize LED light controller
print("\nInitialize LED light controller...")
client.post('/phy/gpio/alloc', data=led_gpio)
data = {"dir": "out", "mode": "floating", "irq": "none", "debouncing": 0}
client.put('/phy/gpio/{}/cfg/value'.format(led_gpio), data=data)

led = srmlib.SRMClient(
    url="https://localhost:46100/phy/gpio/{}/value".format(led_gpio),
    https_check=https_check,
    verbose=verbose)