elpaul
Posts: 2
Joined: Thu Jul 11, 2019 3:50 am

Raspbian Buster rc.local problem

Thu Jul 11, 2019 4:21 am

Hi everyone.
My raspberry pi controls home automation. Until now, I used Stretch without any problems. Yesterday I went to Buster, and there was a problem with the autostart.
In the home / pi directory, I have a script in bash that runs BLE (chmod 711) iNode.sh

Code: Select all

#!/bin/bash
# iBeacon Scan by Radius Networks
# written by Michał Dobrzyński
# modified by iNode.pl 03.12.2017

declare -i cnt
declare -i dcnt
declare -i bcnt
declare -i tl
declare -i bl
declare -i bc
declare -i bt
declare -i DTYPE

if [[ $1 == "parse" ]]; then
  packet=""
  capturing=""
  count=0
  while read line
  do
    count=$[count + 1]
    if [ "$capturing" ]; then
      if [[ $line =~ ^[0-9a-fA-F]{2}\ [0-9a-fA-F] ]]; then
        packet="$packet $line"
      else
	#echo RAW: $packet
	cnt=0
	dcnt=0
	bl=0
	bt=0
        bc=0
	np=""
	mp=""

	DTYPE=0

        for i in $packet; do
            if [[ "$cnt" -eq "13" ]]; then
	      tl=`echo "ibase=16; $i"|bc`
	      #echo TL $tl
            fi
            if [[ "$cnt" -gt "13" ]]; then
	      np+=$i
	      if [[ "$bl" -eq "0" ]]; then
		if [[ "$DTYPE" -eq "130" ]]; then # iNode Energy Meter
		       #echo DTYPE

	               MAC=`echo $packet | awk '{print $13$12$11$10$9$8}'`
	               #echo $mp

		       #CONST
                       HEX=`echo $mp | awk '{ print $12$11 }'`
                       DEC=`echo "ibase=16; $HEX"|bc`
		       CONST=$DEC
		       #echo CONST $CONST

                       #WATY
                       HEX=`echo $mp | awk '{ print $6$5 }'`
                       DEC=`echo "ibase=16; $HEX"|bc`
		       #echo MINUTE POWER $DEC
                       CALC=`echo $DEC $CONST | awk '{ w=(($1*60.0)/$2*1000); printf"%0.2f\n",  w  }'`

                       #IMPULSY
                       HEXIM=`echo $mp  | awk '{ print $10$9$8$7 }'`
		       #echo TOTAL POWER $HEXIM
                       DECIM=`echo "ibase=16; $HEXIM"|bc`
		       #echo TOTAL POWER $DECIM
                       CALCIM=`echo $DECIM $CONST | awk '{ kWh=($1/$2); printf"%0.3f\n", kWh  }'`
		       #echo CALCIM $CALCIM
                       TODOMOTICZ=`echo $CALCIM | sed -r 's/\.//g'`

                       #domoticz
                       /usr/bin/curl -s -o /dev/null  "http://192.168.0.10:8080/json.htm?type=command&param=udevice&idx=109&nvalue=0&svalue=$CALC;$TODOMOTICZ"
                   
                       #emoncms
                       #/usr/bin/curl -s -o /dev/null  "http://emoncms.org/input/post.json?json={meterpower:$CALC}&apikey=XYZ"
                       #/usr/bin/curl -s -o /dev/null  "http://emoncms.org/input/post.json?json={meterkwh:$CALCIM}&apikey=XYZ"

                       #logowanie do lokalnego sysloga
                       logger POWER: $CALC W $CALCIM kWh -p local2.info
                       #print na ekranie
					   echo MAC: $MAC POWER: $CALC W TOTAL: $CALCIM kWh | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'     

		       DTYPE=0
	        fi

		if [[ "$dcnt" -lt "$tl" ]]; then
		  bl=`echo "ibase=16; $i"|bc`
	          bcnt=0
		  #echo BL $bl		  
  		  mp=$i" "
                fi		    
	      else
		if [[ "$bcnt" -eq "0" ]]; then
		  bc=`echo "ibase=16; $i"|bc`
		  #echo BC $bc
		fi
		if [[ "$bc" -eq "255" ]]; then
	          if [[ "$bcnt" -eq "2" ]]; then
		    DTYPE=`echo "ibase=16; $i"|bc`

		    #echo DTYPE $DTYPE
		  fi
		fi

		bcnt=$bcnt+1

		bl=$bl-1

		mp+=$i" "
	      fi
	      dcnt=$dcnt+1
            fi
	    cnt=$cnt+1
	done

        capturing=""
        packet=""
      fi
    fi

    if [ ! "$capturing" ]; then
      if [[ $line =~ ^\> ]]; then
        packet=`echo $line | sed 's/^>.\(.*$\)/\1/'`
        capturing=1
      fi
    fi
  done
else
  hcitool lescan --duplicates --passive 1>/dev/null &
  if [ "$(pidof hcitool)" ]; then
    hcidump --raw | ./$0 parse $1
  fi
fi
I add to rc.local:

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
sudo /home/pi/iNode.sh
exit 0
and everything works fine on raspnian Strech!

I did the same on Raspbian Buster but the script does not start! When will I issue the command: sudo systemctl status rc-local.service I get what is in the picture below
Image

Can anyone help me?
(The iNode.sh script running manually in the console is working correctly.)

epoch1970
Posts: 3320
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Raspbian Buster rc.local problem

Thu Jul 11, 2019 9:16 am

Remove sudo.
- sudo is an interactive command (unless you changed that) so it does not work in batch mode.
- rc.local is executed by root so sudo is not needed.

If that is still not enough replace the simple command statements "hcitool ...." in your script
with fully-qualified command calls "/usr/sbin-or-whatever/hcitool ..."
User root is likely to have its $PATH environment variable set differently than a regular user.
Using the fully qualified path is generally considered safer.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
thagrol
Posts: 1686
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Raspbian Buster rc.local problem

Thu Jul 11, 2019 12:03 pm

The error message in that screen grab "could not opendevice: no such device" suggests to me that something in /dev is missing or has changed between stretch and buster though it could be a timing issue in that you script is running too early in the boot sequence.

Can you run your script with sudo?

Comparing the contents of /dev on stretch and buster may shed some light on the cause of the problem.

Check your config.txt to ensure nothing has disabled bluetooth.
This space unintentionally left blank.

klricks
Posts: 6495
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Raspbian Buster rc.local problem

Thu Jul 11, 2019 12:48 pm

Note: If if booting to Desktop headless:
Use sudo raspi-config to set a screen resolution to something other than default.

With Buster if no monitor is connected, and the display is set to default, then no display is configured so the GUI does not start. So any program that requires GUI won't work.

Before Buster if no HDMI monitor was connected then the system would fall back to composite video so one way or another the GUI would always start.

When you use sudo raspi-config to choose a different resolution, other than default, then that will force HDMI to configure even without a monitor connected.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

elpaul
Posts: 2
Joined: Thu Jul 11, 2019 3:50 am

Re: Raspbian Buster rc.local problem

Thu Jul 11, 2019 2:31 pm

:P

Code: Select all

sleep 10
/home/pi/iNode.sh
solved the problem!

Return to “Troubleshooting”