Skip to content
Snippets Groups Projects
Commit 66907926 authored by jkerdreu's avatar jkerdreu
Browse files

bye

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1528 b32b6428-25c9-4566-ad07-03861ab6144f
parent 70954830
Branches
No related tags found
No related merge requests found
from setuptools import setup
with open('README.rst') as f:
long_description = f.read()
VERSION = "0.1"
setup(
name='xaal.bugone',
version=VERSION,
license='GPL License',
author='Jerome Kerdreux',
author_email='Jerome.Kerdreux@imt-atlantique.fr',
#url='',
description=('xAAL devices for bugNet wireless sensors' ),
long_description=long_description,
classifiers=[
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
],
keywords=['xaal', 'bugone','RFM12','Wireless','Sensor'],
platforms='any',
packages=["xaal.bugone",],
namespace_packages=["xaal"],
include_package_data=True,
install_requires=[
'xaal.lib',
'bugone',
'gevent'
]
)
[config]
type = tcpmux
host = localhost
addr = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
[nodes]
[[10]]
# bugOne-mini salon
type = mini-shield1
addr0 = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
addr1 = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
addr2 = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
[[11]]
# capteur t° dans la chambre
type = temp1
addr0 = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
addr1 = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
# this is a namespace package
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
from . import gw
gw.main()
from __future__ import print_function
from gevent import monkey; monkey.patch_all()
import gevent
import platform
from xaal.lib import tools,Engine,Device
from bugone import bugnet,connector
from .nodes import *
PACKAGE_NAME = "xaal.bugone"
logger = tools.get_logger(PACKAGE_NAME,'DEBUG')
class BugNetGW(gevent.Greenlet):
def __init__(self,engine):
gevent.Greenlet.__init__(self)
self.engine = engine
self.cfg = tools.load_cfg_or_die(PACKAGE_NAME)
self.setup_connector()
self.setup_nodes()
self.setup_gw()
def setup_connector(self):
""" create the bugnet connector"""
cn = None
cfg = self.cfg['config']
if cfg['type'] == 'tcpmux':
cn = connector.TCPMux(cfg['host'])
if cfg['type'] == 'serial':
cn = connector.Serial(cfg['port'])
if cn:
self.bugnet = bugnet.BugNet(cn)
else:
logger.warn("Error in config section")
def setup_nodes(self):
""" load nodes from config file"""
self.nodes = {}
cfg = self.cfg['nodes']
# creating nodes from config
for k in cfg:
node = None
if cfg[k]['type'] == 'temp1':
node = temp1.Node(k,cfg[k])
if cfg[k]['type'] == 'mini-shield1':
node = minishield1.Node(k,cfg[k])
if node:
self.nodes.update({int(k):node})
self.engine.add_devices(node.get_devices())
def setup_gw(self):
# last step build the GW device
gw = Device("gateway.basic")
gw.address = self.cfg['config']['addr']
gw.vendor_id = "DIY Wireless Bug"
gw.product_id = "bugOne Gateway"
gw.version = 0.2
gw.url = "http://dwb.ilhost.fr/"
gw.info = "bugOne@%s" % platform.node()
emb = gw.new_attribute('embedded',[])
for node in self.nodes.values():
for dev in node.get_devices():
emb.value.append(dev.address)
self.engine.add_device(gw)
def _run(self):
""" receive pkt and foward it to right node"""
while 1:
pkt = self.bugnet.receive()
print(pkt)
if pkt and pkt.src in self.nodes.keys():
self.nodes[pkt.src].parse(pkt)
def run():
eng = Engine()
net = BugNetGW.spawn(eng)
eng.run()
def main():
try:
run()
except KeyboardInterrupt:
print("Bye Bye...")
if __name__ == '__main__':
main()
from . import temp1
from . import minishield1
from xaal.lib import Device
def build_dev(addr,devtype):
dev = Device(devtype)
dev.address = addr
dev.vendor_id = "DIY Wireless Bug"
dev.url = "http://dwb.ilhost.fr/"
return dev
from xaal.lib import Device, Attribute
from .default import build_dev
class Node(object):
def __init__(self,ID,cfg):
# first device = bangap
bg = build_dev(cfg["addr0"],"voltage.basic")
bg.info = "bandgap"
bg.hw_id = "%s.1" % ID
bg.new_attribute("voltage")
# temp sensor
temp = build_dev(cfg["addr1"],"thermometer.basic")
temp.info = "SHT21/temp"
temp.hw_id = "%s.2" % ID
temp.new_attribute("temperature")
# hum sensor
hum = build_dev(cfg["addr2"],"hygrometer.basic")
hum.info = "SHT21/rh"
hum.hw_id = "%s.3" % ID
hum.new_attribute("humidity")
self.devs = [bg,temp,hum]
for d in self.devs:
d.product_id = 'minishield1'
def parse(self,pkt):
try:
self.devs[0].attributes[0].value = pkt.values[0][2]/100.0
self.devs[1].attributes[0].value = pkt.values[1][2]/10.0
self.devs[2].attributes[0].value = pkt.values[2][2]/10.0
except IndexError:
pass
def get_devices(self):
return self.devs
from xaal.lib import Device, Attribute
from .default import build_dev
class Node(object):
def __init__(self,ID,cfg):
# first device = bangap
bg = build_dev(cfg["addr0"],"voltage.basic")
bg.info = "bandgap"
bg.hw_id = "%s.1" % ID
bg.new_attribute("voltage")
# temp sensor
temp = build_dev(cfg["addr1"],"thermometer.basic")
temp.info = "DS18B20"
temp.hw_id = "%s.2" % ID
temp.new_attribute("temperature")
self.devs = [bg,temp]
for d in self.devs:
d.product_id = 'temp1'
def parse(self,pkt):
try:
self.devs[0].attributes[0].value = pkt.values[0][2]/100.0
self.devs[1].attributes[0].value = pkt.values[1][2]/10.0
except IndexError:
pass
def get_devices(self):
return self.devs
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment