-1

We are trying to insert values from a TCP stream into an RRDTool database. Even though the first value is accepted by the RRDTool, the next one is not. We get the error: convert to float not complete: tail Our client code is:

#!/usr/bin/env python
import socket
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.ADC as ADC
import time
import datetime

TCP_IP = '192.168.1.138'
TCP_PORT = 5005
BUFFER_SIZE = 1024
sensor_pin='P9_40'
light_pin='p8_10'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
ADC.setup()
GPIO.setup(light_pin, GPIO.OUT)

while True:
    reading = ADC.read(sensor_pin)
    millivolts = reading * 1800
    data = (millivolts-500)/10
    data = round(data,2)
    MESSAGE = str(data)
    s.send(MESSAGE)
    time.sleep(10)
s.close()

The Server side is like this(only the tcp connection part)

while True:
    input=conn.recv(BUFFER_SIZE)
    if input:
            input = input.replace('\r\n','')
            input = input.rstrip('\r|\n')
            temp1=float(input)
            x=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
            y=input
            stream.write(dict(x=x, y=y))
            rrdtool.update('database/temp.rrd','N:input')
            print temp1
conn.close()
stream.close()

We also tried converting the input value into a float (temp1) and entering that into the database but that didn't work as well. (same error)

We suspect it has something to do with a carriage return or line feed, but weren't able to find the answer so far.

Any tips are more then welcome !

1 Answers1

0

Found the answer: Enterring the data into the database with the following line of code: rrdtool.update('database/temp.rrd','N:%s' % input)