#  Demo to show a simple MQTT subscriber to BayEOS Gateway bridge
#  Oliver Archner
#  29.07.2015

from bayeosgatewayclient import BayEOSWriter, BayEOSSender
import paho.mqtt.client as mqtt

# BayEOS sender
sender = BayEOSSender(
    url='http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat',
    user='******',
    password='******')
sender.start()

# BayEOS writer
writer = BayEOSWriter()


# MQTT connect and subscribe
def on_connect(client, userdata, rc):
    print("Connected with result code:{0}".format(rc))
    # Subscribe everything
    client.subscribe("#")


# MQTT receive and save message
def on_message(client, userdata, msg):
    # Expects a payload in csv format like '1.0,2.0,3.0,4.0'
    try:
        lst = msg.payload.split(',')
        writer.save(values=[float(i) for i in lst], origin=str(msg.topic))
"""Reads BayEOS options from a config file."""

from bayeosgatewayclient import BayEOSWriter, BayEOSSender, bayeos_confparser

config = bayeos_confparser('config')
print config

writer = BayEOSWriter(path=config['path'], max_chunk=config['max_chunk'])
sender = BayEOSSender(path=config['path'])
예제 #3
0
"""Creates an example writer and sender using threads."""
from time import sleep
from bayeosgatewayclient import BayEOSWriter, BayEOSSender
import logging
import tempfile
from os import path

PATH = path.join(tempfile.gettempdir(), 'bayeos-device')
BACKUP_PATH = path.join(tempfile.gettempdir(), 'bayeos-device-backup')
NAME = 'Python-Thread-WithLogging'

URL = 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat'

writer = BayEOSWriter(PATH, max_time=10, log_level=logging.DEBUG)
writer.save_msg('Writer was started.')

sender = BayEOSSender(PATH,
                      NAME,
                      URL,
                      backup_path=BACKUP_PATH,
                      log_level=logging.DEBUG)
sender.start()

nr = 0
while True:
    writer.save([nr, 3, 20.5])
    #writer.flush()
    nr += 1
    sleep(5)
예제 #4
0
from mcp3424 import MCP3424
from gpio import GPIO

# gpio pins
ADDR_PINS = [11, 12, 13, 15, 16, 18]  # GPIO 17, 18, 27, 22, 23, 24
DATA_PIN = 24  # GPIO 8
EN_PIN = 26  # GPIO 7

# configuration for BayEOSWriter and BayEOSSender
PATH = '/tmp/raspberrypi/'
NAME = 'RaspberryPi'
URL = 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat'

# instantiate objects of BayEOSWriter and BayEOSSender
writer = BayEOSWriter(PATH)
sender = BayEOSSender(PATH, NAME, URL)

# initialize GPIO Board on Raspberry Pi
gpio = GPIO(ADDR_PINS, EN_PIN, DATA_PIN)

# initialize I2C Bus with sensors
try:
    i2c = I2C()
    sht21 = SHT21(1)
    mcp3424 = MCP3424(i2c.get_smbus())
except IOError as err:
    sys.stderr.write(
        'I2C Connection Error: ' + str(err) +
        '. This must be run as root. Did you use the right device number?')

예제 #5
0
import tempfile
from os import path

logging.basicConfig(level=logging.INFO,
                    format="%(asctime)s %(levelname)s:%(message)s")

NAME = 'FramePump'
URL = 'http://localhost:5533/gateway/frame/saveFlat'
USER = '******'
PASSWORD = '******'
PATH = path.join(tempfile.gettempdir(), 'bayeos-device')
BACKUP_PATH = path.join(tempfile.gettempdir(), 'bayeos-device-backup')

writer = BayEOSWriter(PATH, max_time=10, log_level=logging.DEBUG)
writer.save_msg('Writer was started.')

sender = BayEOSSender(PATH,
                      NAME,
                      URL,
                      backup_path=BACKUP_PATH,
                      log_level=logging.DEBUG,
                      user=USER,
                      password=PASSWORD)
sender.start()

nr = 0
while True:
    writer.save([nr, 3, 20.5])
    writer.flush()
    nr += 1
    sleep(1)
from time import sleep
from bayeosgatewayclient import BayEOSWriter, BayEOSSender, BayEOSFrame
import logging
import tempfile
from os import path

PATH = path.join(tempfile.gettempdir(),'bayeos-device')
BACKUP_PATH =  path.join(tempfile.gettempdir(),'bayeos-device-backup')
NAME = 'Python-SampleFrames'

URL = 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat'

writer = BayEOSWriter(PATH,max_time=10,log_level=logging.DEBUG)
writer.save_msg('Writer was started.')

sender = BayEOSSender(PATH, NAME, URL,backup_path=BACKUP_PATH)
sender.start()

while True:
    data_frame_simple = BayEOSFrame.factory(0x1)
    data_frame_simple.create(values=(1, 5, 4), value_type=0x22)  # Data Type Integer
    writer.save_frame(data_frame_simple.frame)
    routed_origin_frame = BayEOSFrame.factory(0xd)
    routed_origin_frame.create(origin="RoutedOrigin", nested_frame=data_frame_simple.frame)
    writer.save_frame(routed_origin_frame.frame)
    sleep(2)
    
    # in the second try - checksum frames are send
    # first direct - second nested in routed origin frame
    data_frame_simple = BayEOSFrame.factory(0x1)
    data_frame_simple.create(values=(2, 5, 4), value_type=0x22)  # Data Type Integer
예제 #7
0
import logging
import tempfile
import logging
import os

from bayeosdevice.device import DeviceController
from bayeosdevice.item import ItemDict
from bayeosgatewayclient import BayEOSWriter, BayEOSSender

NAME = 'MyDevice'
PATH = os.path.join(tempfile.gettempdir(), NAME)
GW = 'http://localhost/gateway/frame/saveFlat'

# Transport
writer = BayEOSWriter(PATH)
sender = BayEOSSender(PATH, NAME, GW)
sender.start()

# Web Interface
values = ItemDict({"cpu1": None, "cpu2": None})
units = {"^cpu": '%', "\w+time$": 'secs'}
actions = ItemDict({"sleep_time": 10, "run": True})
con = DeviceController(values, actions, units, template="custom.html")
con.start()


# Stop handler
def sigterm_handler(_signo, _stack_frame):
    logging.info("Stopping device")
    if con is not None:
        con.stop()
from bayeosgatewayclient import BayEOSWriter, BayEOSSender, bayeos_argparser

# Fetch input arguments
args = bayeos_argparser('This is the text to appear on the command line.')

WRITER_SLEEP = float(args.writer_sleep)
MAX_CHUNK = float(args.max_chunk)

NAME = args.name + '-WS' + str(WRITER_SLEEP) + '-M' + str(MAX_CHUNK)
PATH = args.path + '/' + NAME + '/'
if args.url:
    URL = args.url
else:
    URL = 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat'

print 'name to appear in Gateway is', NAME
print 'max-chunk is', MAX_CHUNK, 'byte'
print 'writer sleep time is', WRITER_SLEEP, 'sec'
print 'path to store writer files is', PATH

# init writer and sender
writer = BayEOSWriter(PATH, MAX_CHUNK)
writer.save_msg('Writer was started.')

sender = BayEOSSender(PATH, NAME, URL, 'import', 'import')
sender.start()

# start measurement
while True:
    writer.save([time()], value_type=0x21)
    sleep(WRITER_SLEEP)