Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space after value ; check if zero #7

Closed
RaptorSDS opened this issue May 27, 2023 · 12 comments
Closed

Space after value ; check if zero #7

RaptorSDS opened this issue May 27, 2023 · 12 comments

Comments

@RaptorSDS
Copy link

RaptorSDS commented May 27, 2023

i use your script for my upload data script for VZ-DB
i also add nowaday the total value

i had some Problems with the value maybe that also some idea/problem for your script to take in account

for actual power i had a zero in front

#request value
ACTUAL=$(/usr/local/bin/mi600 $host_pv $user $password webdata_now_p)
#remove Zero in Front
ACTUAL_NUM=$(($ACTUAL))

and for Total Energy i had a Space at the End

#request value TOTAL
TOTAL=$(/usr/local/bin/mi600 $host_pv $user $password webdata_total_e)
#Remove end SPACE-Char
TOTAL_NUM=$(echo $TOTAL | sed 's/[[:space:]]*$//')

@RaptorSDS RaptorSDS changed the title zero infront and Space after zero infront power and Space after energy ; check if zero May 28, 2023
@dr-ni
Copy link
Owner

dr-ni commented May 29, 2023

can you show me an example?
I have no zero in front?

pi@rp4:~ $ mi600 ip admin pw webdata_now_p
472 
pi@rp4:~ $ mi600 ip admin pw webdata_total_e
718.5 
pi@rp4:~ $ mi600 ip admin pw webdata_today_e
2.10 

@RaptorSDS
Copy link
Author

RaptorSDS commented May 29, 2023

soory my mistake also Space at end for wedata_now_p

but more simple because no floating point
root@DietPi:~# bash auslesen
!211 !
!211!

#request value
ACTUAL=$(/usr/local/bin/mi600 $host_pv $user $password webdata_now_p)
#remove Space at End
echo "!"$ACTUAL"!"
ACTUAL_NUM=$(($ACTUAL))
echo "!"$ACTUAL_NUM"!"

webdatal_total_e
also Space at end but more comlicate because of floating point

@RaptorSDS
Copy link
Author

RaptorSDS commented May 29, 2023

I also check if Webdata_total_e is 0.0 than Inverter not ready but ist maybe not for you
because i know my inverter has more than 0.0
but new inverter i think is over comlicate to check if 0.0 is really the first value or inverter is not ready

@RaptorSDS RaptorSDS changed the title zero infront power and Space after energy ; check if zero Space after value ; check if zero May 29, 2023
@dr-ni
Copy link
Owner

dr-ni commented May 29, 2023

is my last commit ok now?

@RaptorSDS
Copy link
Author

RaptorSDS commented May 29, 2023

looks good but Space not solve

it also get worst

mi600 now webdata_now_p has a .0 part (floating point)

uninstall and rm-r

root@DietPi:~# git clone https://github.com/dr-ni/mi600.git Klone nach 'mi600' ... remote: Enumerating objects: 163, done. remote: Counting objects: 100% (163/163), done. remote: Compressing objects: 100% (119/119), done. remote: Total 163 (delta 84), reused 61 (delta 24), pack-reused 0 Empfange Objekte: 100% (163/163), 28.61 KiB | 1.43 MiB/s, fertig. Löse Unterschiede auf: 100% (84/84), fertig. root@DietPi:~# cd mi600 root@DietPi:~/mi600# make install install -d /usr/local/man/man1 install -m 0755 mi600 /usr/local/bin install -m 0644 README.md /usr/share/doc/mi600 install -m 0644 LICENSE /usr/share/doc/mi600 install -m 0644 man/man1/mi600.1 /usr/local/man/man1 root@DietPi:~/mi600# cd .. root@DietPi:~# bash auslesen !0 ! !0! space still there root@DietPi:~# bash auslesen !18.0 ! !18.0!

@dr-ni
Copy link
Owner

dr-ni commented May 30, 2023

should be ok now, can you check it again?

@RaptorSDS
Copy link
Author

sorry but still space at the end but floating point is now gone for wedata_now_p

root@DietPi:~# bash auslesen
!213 !
!213!

#request value
ACTUAL=$(/usr/local/bin/mi600 $host_pv $user $password webdata_now_p)
echo "!"$ACTUAL"!"
#remove space at end
#ACTUAL_NUM=$(($ACTUAL))
ACTUAL_NUM=$(echo $ACTUAL | sed 's/[[:space:]]*$//')
echo "!"$ACTUAL_NUM"!"

@dr-ni
Copy link
Owner

dr-ni commented May 30, 2023

I do not have any spaces?
can you please check this directly without your script and post the response:

#!/bin/bash
#
# mi600
# MIT License Copyright (c) 2022 dr-ni
# https://github.com/dr-ni/mi600
#
# A simple bash command-line tool for direct solar data requests
# to the inverter Bosswerk mi600.
# It can read the actual solar power and the cumulative daily earned energy.
#
# Requirements: curl must be installed.
#
#
host=$1
auth=$2:$3
dat=webdata_now_p
val=''

# option check
if [ $# -lt 3 ]
then
  echo "Usage: $0 <host> <username> <password> [<type>] [-u]"
  echo "Valid types can be found in man page: 'man mi600'"
  echo "Option '-u': show unit"
  exit 1
fi
if [ $# -gt 3 ]
then
  if [ "$4" == "-u" ]
  then
    dat=webdata_now_p
    val=W
  else
    dat=$4
    val=''
    if [ "$5" == "-u" ]
    then
      [ "$dat" = "webdata_today_e" ] && val=kWh
      [ "$dat" = "webdata_total_e" ] && val=kWh
      [ "$dat" = "webdata_now_p" ] && val=W
    fi
  fi
fi
for i in 1 2 3
do
  o=$(curl -s -u "$auth" "$host"/status.html | grep "$dat = " | awk -F '"' '{print $2}')
  if [ "$o" != "" ]
  then
    if [[ "$dat" == "webdata_total_e" || "$dat" == "webdata_today_e" ]]
    then
      p=$(echo "scale=1; $o/1.0" | bc | tr -d ' ')
    elif [ "$dat" == "webdata_now_p" ]
    then
      p=$(echo "$o" | tr -d ' ')
    else
      p=$(echo "$o")
    fi
    echo "+$p+ $val"
    exit 0
  fi
  sleep 3
done
ping -c3 $host > /dev/null 2>&1
if [ $? -eq 0 ]
then
  echo "mi600: could not read value"
else
  echo "Error: connection to $host failed"
fi
exit 1

@RaptorSDS
Copy link
Author

root@DietPi:~# mi600 192.168.xx admin xx webdata_now_p
196
correct no space
ACTUAL=$(/usr/local/bin/mi600 $host_pv $user $password webdata_now_p)
but thats simple parse/request why end space ?

@dr-ni
Copy link
Owner

dr-ni commented May 30, 2023

the response should be +196+
please use the code above

./mi600 192.168.xx admin xx webdata_now_p

@RaptorSDS
Copy link
Author

thanks

it is not your fault you could reverse the change because its some with parsing

@dr-ni
Copy link
Owner

dr-ni commented May 30, 2023

maybe this helps
https://stackoverflow.com/questions/2003536/bash-why-is-echo-adding-extra-space

if all is ok now - please close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants