summaryrefslogtreecommitdiff
path: root/bin/ebus_app
blob: d3812543c20e881e3e407c0e0123f9abaa84944e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding:utf8 -*-
# xapek.org, 2010
import asyncore
from pymongo import Connection
from ebus import EbusReader
from time import time

connection = Connection("10.2.2.13", 27017)
db = connection["ebus"]
db.authenticate("ebus", "ebus")
collection = db["data"]

def insert(ebus_packet):
    try:
        if ebus_packet.values() != dict():
            data={'name':ebus_packet.name(), 'values':ebus_packet.values(), 'time':time()}
            collection.insert(data)
            print "Inserted: %s" % data
    except Exception,e:
        try:
            print "Failed to insert %s -- %s" % (ebus_packet.name(), e)
        except Exception,e:
            print e

reader = EbusReader()
reader.handle_ebus = insert
reader.debug = False

asyncore.loop()