james-fry / hassio-addons

Repository for hass.io add ons
99 stars 96 forks source link

Seems like a memory leak or long run time crash? #19

Open alanmimms opened 5 years ago

alanmimms commented 5 years ago

This is a cool add-on. I use it for remote controls and for monitoring temperature sensors.

After a week or two of uptime, I find the add-on stops working. All I have to do to fix it is to hit restart in the add-on details page, but it's slightly annoying. Do others see this behavior?

The length of time it works with no issue makes me think it's a very infrequent driver hang or maybe a memory leak. I have not yet looked into the memory leak theory by paying attention to size of the process, etc., but that's the next step to debugging this I suppose. What exactly does the restart button do? Does it completely rmmod the driver? Or does it simply restart the userland process(es)?

seayworld commented 5 years ago

I am having the same issue. Sometimes is runs for days, sometimes just hours. Each time I can clear with a restart. Tried looking for logs, but nothing is there.

messismore commented 5 years ago

See here Does that fix the issue for you?

alanmimms commented 5 years ago

That seems like a crude work around. I want a real fix. When I get some time I'll try debugging it.

messismore commented 5 years ago

I was experiencing the issue described here. There's references to other issues that might also help to debug it.

alanmimms commented 5 years ago

I ordered a heatsinked R820T USB dongle to replace the one I have now in hopes that overheating is the source of the problem. For anyone interested:

​NooElec NESDR Nano 3 - Premium Tiny RTL-SDR w/Aluminum Enclosure, 0.5PPM TCXO, SMA & MCX Input & Custom Heatsink. RTL2832U & R820T2-Based Software Defined Radio by Nooelec Learn more: https://smile.amazon.com/dp/B073JZ8CC2/ref=cm_sw_em_r_mt_dp_U_t2P6CbW2JDS3G

messismore commented 5 years ago

Have you had better luck with the Nano? Would you recommend it?

alanmimms commented 5 years ago

So far no time to implement it. I'm buried at work.

robertopiumatti commented 4 years ago

i'm solved! In sh:

MQTT_PATH=$MQTT_TOPIC
/usr/local/bin/rtl_433 -F json -R $PROTOCOL -f $FREQUENCY -g $GAIN -p $OFFSET | /usr/bin/mosquitto_pub -h $MQTT_HOST -u $MQTT_USER -P $MQTT_PASS -i RTL_433 -l -t $MQTT_PATH

instead:

/usr/local/bin/rtl_433 -F json -R $PROTOCOL -f $FREQUENCY -g $GAIN -p $OFFSET | while read line
do
  DEVICE="$(echo $line | jq --raw-output '.model' | tr -s ' ' '_')" # replace ' ' with '_'
  DEVICEID="$(echo $line | jq --raw-output '.id' | tr -s ' ' '_')"

  MQTT_PATH=$MQTT_TOPIC

  if [ ${#DEVICE} > 0 ]; then
    MQTT_PATH=$MQTT_PATH/"$DEVICE"
  fi
  if [ ${#DEVICEID} > 0 ]; then
    MQTT_PATH=$MQTT_PATH/"$DEVICEID"
  fi

  # Create file with touch /tmp/rtl_433.log if logging is needed
  [ -w /tmp/rtl_433.log ] && echo $line >> rtl_433.log
  echo $line | /usr/bin/mosquitto_pub -h $MQTT_HOST -u $MQTT_USER -P $MQTT_PASS -i RTL_433 -r -l -t $MQTT_PATH
done

As repository https://github.com/merbanan/rtl_433 I used its mqtt function directly. Now it has been running for a month, now without interruption

alanmimms commented 4 years ago

In case anyone is interested, my usage pattern is a little different, but I have about the same functionality as @robertopiumatti's solution. Yet I still have the hang after a period of time, requiring reboot of the Raspberry Pi3 to resolve.

This script isn't all that clean and I admit it. But there are some good ideas in it as well.

# Remove hash on next line for debugging                    
#set -x                                                    

export LANG=C                                              
export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
LOG=/tmp/rtl_433.log                                                      

touch $LOG                                                                

#                                                                         
# Start the listener and enter an endless loop
#                                             
rtl_433 -F json |  while read json            
do                                            
# Log to file if file exists.                 
  [ -w $LOG ] && echo $json >> $LOG           

  T=$( echo $json | \              
        jq -r '.model + "-" + (.id // 0 | tostring) + "-" + (.channel // 0 | tostring) | gsub("[^a-zA-Z0-9_-]"; "_")' )

  # Raw message to MQTT                                                                                                
  echo $json | /usr/bin/mosquitto_pub -h 192.168.0.109 -u x -P yyy -i RTL_433 -l -t "homeassistant/rtl433/raw"       

  echo $json | \                                                                                                       
    case $T in                                                                                                  
      Acurite*Sensor* | Nexus_Temperature*)                                                                     
        jq -c '{temperature: (.temperature_C * 9/5 + 32), battery: .battery, time: .time, model: .model}' | \   
          /usr/bin/mosquitto_pub -h 192.168.0.109 -u xx -P yyy -i RTL_433 -l -t "homeassistant/sensor/"$T   
        ;;                                                                                                   

      Generic_Remote*)                                                                                       
        echo $json | \                                                                                       
         jq -r '.cmd' | \                                                                                 
         /usr/bin/mosquitto_pub -h 192.168.0.109 -u xx -P yyy -i RTL_433 -l -t "homeassistant/remote/"$T
        ;;                                                                                               

      *)                                                                                                 
        ;;                                                                                               
    esac                                                                                                 
done
yvesle commented 4 years ago

@alanmimms you may want to check out my solution. It turns out rtl_433 can send its output to a mqtt broker natively !