Beispiel #1
0
def save_rawdata(topic, payload):
    if not storage or cf.g('features', 'rawdata', False) == False:
        return

    try:
        rawdata = {
            'topic'  : topic,
            'tst'    : time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(time.time()))),
            'payload' : payload,
        }
        rd = RAWdata(**rawdata)
        rd.save()
    except Exception, e:
        log.error("Cannot store rawdata for topic {0}: {1}".format(topic, str(e)))
Beispiel #2
0
def save_rawdata(topic, payload):
    if not storage or cf.g('features', 'rawdata', False) == False:
        return

    try:
        rawdata = {
            'topic':
            topic,
            'tst':
            time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(time.time()))),
            'payload':
            payload,
        }
        rd = RAWdata(**rawdata)
        rd.save()
    except Exception, e:
        log.error("Cannot store rawdata for topic {0}: {1}".format(
            topic, str(e)))
Beispiel #3
0
def json_batt():

    result = []
    dbconn()
    query = (RAWdata.select(RAWdata.tst, RAWdata.payload).where(
        RAWdata.topic == 'owntracks/gw/356612028111492/voltage/batt'))

    query = query.order_by(RAWdata.tst.desc()).limit(190)

    time_format = "%Y-%m-%d %H:%M:%S"
    for q in query.naive():
        tstamp = q.tst.strftime(time_format)
        print tstamp, q.payload
        result.append({'tst': tstamp, 'batt': float(q.payload)})

    j = json.dumps(result)
    print j
    return j
Beispiel #4
0
def json_batt():

    result = []
    dbconn()
    query = (RAWdata.select(RAWdata.tst, RAWdata.payload)
            .where(
                RAWdata.topic == 'owntracks/gw/356612028111492/voltage/batt'
            )
            )

    query = query.order_by(RAWdata.tst.desc()).limit(190)

    time_format = "%Y-%m-%d %H:%M:%S"
    for q in query.naive():
        tstamp = q.tst.strftime(time_format)
        print tstamp, q.payload
        result.append( { 'tst' : tstamp, 'batt' : float(q.payload) } )

    j = json.dumps(result)
    print j
    return j