RFLink and nano together

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
htca
Posts: 21
Joined: Thursday 28 January 2016 10:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

RFLink and nano together

Post 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 %

htca
Posts: 21
Joined: Thursday 28 January 2016 10:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: RFLink and nano together

Post by htca »

:roll: It helps if you close your serial connection in the script....
alfred_j_kwak
Posts: 110
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Location: Finland
Contact:

Re: RFLink and nano together

Post by alfred_j_kwak »

Are you sure your value indexing is correct?
htca
Posts: 21
Joined: Thursday 28 January 2016 10:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: RFLink and nano together

Post 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()
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest