Page 1 of 1

RFLink and nano together

Posted: Sunday 07 February 2016 12:47
by htca
I am running domoticz on a RPi. Since yesterday I added a RFLink to it. I recently made also a arduino nano with 5 sensors on it which I read out serial and which values are pushed using json. Since I added the RFlink the system becomes unstable. Initially I thought it had something to do with the power consumption, so I added everything to a powered hub, but it stayed unstable. So I think It has to do something with the serial connection I made with the nano. The python script I use for the serial connection is:

Code: Select all

#!/usr/bin/env python


import time
import serial
import sys
import urllib2


ser = serial.Serial(

        port='/dev/ttyUSB0',
        baudrate = 9600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
)
counter=0
humavg=0
tem1avg=0
tem2avg=0
tem3avg=0
lightavg=0

while 1:
        x=ser.readline()
        values = x.split(" ")
        if len(values) == 14:
                counter=counter+1
                humavg = float(values[1])/3 + humavg
                tem1avg = float(values[3])/3 + tem1avg
                tem2avg = float(values[6])/3 + tem2avg
                tem3avg = float(values[9])/3 + tem3avg
                lightavg = float(values[12])/3 + lightavg
        if counter ==3:
                f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command&param=udevice&idx=27&nvalue=0&svalue='+str(lightavg))
                f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command&param=udevice&idx=25&nvalue=0&svalue='+str(tem2avg))
                f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command&param=udevice&idx=26&nvalue=0&svalue='+str(tem3avg))
                f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command&param=udevice&idx=24&nvalue=0&svalue='+str(tem1avg)+';'+str(humavg)+';1')
                sys.exit()
The lines I get from arduino:

Code: Select all

Sensors at nano
Humidity: 35.70 %	Temperature: 20.10 *C	 T1: 33.56 *C	 T2: 18.06 *C	 Light: 87.30 %
Humidity: 35.60 %	Temperature: 20.20 *C	 T1: 33.63 *C	 T2: 18.06 *C	 Light: 85.16 %


Re: RFLink and nano together

Posted: Monday 08 February 2016 9:40
by htca
:roll: It helps if you close your serial connection in the script....

Re: RFLink and nano together

Posted: Monday 08 February 2016 10:21
by alfred_j_kwak
Are you sure your value indexing is correct?

Re: RFLink and nano together

Posted: Monday 08 February 2016 10:44
by htca
Corrected code. Indexing is ok (tested it thoroughly ;) )

Code: Select all

import time
import serial
import sys
import urllib2


ser = serial.Serial(

        port='/dev/ttyUSB0',
        baudrate = 9600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
)
counter=0
humavg=0
tem1avg=0
tem2avg=0
tem3avg=0
lightavg=0

while counter<=3:
        x=ser.readline()
        values = x.split(" ")
        if len(values) == 14:
                counter=counter+1
                humavg = float(values[1])/3 + humavg
                tem1avg = float(values[3])/3 + tem1avg
                tem2avg = float(values[6])/3 + tem2avg
                tem3avg = float(values[9])/3 + tem3avg
                lightavg = float(values[12])/3 + lightavg
        if counter ==3:
                f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command&param=udevice&idx=27&nvalue=0&svalue='+str(round(lightavg,2)))
                f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command&param=udevice&idx=25&nvalue=0&svalue='+str(round(tem2avg,2)))
                f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command&param=udevice&idx=26&nvalue=0&svalue='+str(round(tem3avg,2)))
                f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command&param=udevice&idx=24&nvalue=0&svalue='+str(round(tem1avg,2))+';'+str(round(humavg,2))+';1')
                counter=counter+1
ser.close()
sys.exit()