Writing script for UsbDisplay

Btw, regexbuddy works with regular expressions. Why U say I should forget about regex?
Or U mean I'l better learn completely regular expression by myself to find solution for my case?
And finally should I use grep command? Or sed?
 
hrust_ray schrieb:
Btw, regexbuddy works with regular expressions. Why U say I should forget about regex?
If there were easy and obvious patterns you could have done with little knowledge on "normal regex"
hrust_ray schrieb:
Or U mean I'l better learn completely regular expression by myself to find solution for my case?
Yes, I am pointing you to regexbuddy as a hint to look, what is possible and what not ... especially the interpreter is very usefull.
hrust_ray schrieb:
And finally should I use grep command? Or sed?
1) grep: e.g. to filter out only those lines, that are of interest to you
2) sed: e.g. to do your required regex string manipulations on the lines, pre-selected by grep
 
Hello hrust_ray,
... simply all lines of file are printed out ...
(I also have some problems to find the right syntax for sed...). To print out only found lines use "sed -n "s/.../.../p".
hrust_ray schrieb:
And finally should I use grep command? Or sed?
It's the same for your problem. Your problem is, the needed lines of your file are equal instead of the searched value. So there is no glue to found only one of them. But you can first find all needed lines and then remove line end, so all values are in one line:
Code:
cat filename |sed -n "s/^.*alt=\"\([a-zA-Z]*\)\".*$/\1/p" | tr '\n' ' '
cat filename |sed -n "s/^.*>\([-0-9]*\)\&deg.*$/\1°C/p" | tr '\n' ' '
->
bedeckt bedeckt wolkig bewlkt
1°C  1°C  0°C  -2°C
After this you can separate each value with a second sed command (| sed ..., example from dynamic).

Best regards, Reiner
 
Zuletzt bearbeitet:
rusmueller, thanks - this script works.
I put result to variables using
Var1=$(cat...)
Var2=$(cat...)
It seems that bash in FB doesnt support arrays. Or I'm wrong?
Without arrays I have no idea how to form final result as following:
[bedeckt] 1°C _ [bedeckt] 1°C _ [wolkig] 0°C _ [bewlkt] -2°C
I need to mix 2 vars.

And one more thing. What if there will be 3 patterns, not 4?
 
I just made some mix -added one more sed command to select values on index.
cat temp.tmp |sed -n "s/^.*alt=\"\([a-zA-Zц]*\)\".*$/\1/p" | tr '\n' ' '| sed "s ,^\(.[a-zA-Z]*\) \(.[a-z]*\) \(.[a-z]*\) \(.[a-z]*\),\1,"
It works in generally, only one problem. I defined in last sed command 4 patterns. If in file there is another number of patterns (3 or 5) - thne this command gives wrong result.
 
I found one more way to extract data I need:
# cat ./temp.tmp |grep 5282C6 |sed 's/.*center">//' | sed 's/<\/td>//'
Mittag
Nachmittag
Abend
Nacht
So I have 4 lines for day time. In same way I can get 4 lines for temperature and weather type.
To mix this 3 results, I try to use "read line" cycle. The idea is to make this cycle through first result, inside main cycle to make 2 'read line' cycles for other 2 results. Something like this

i=1
while read line
do
j=1
while read line1
do
if [j=i] then
resline1=line1
fi
j++
done < "1gradC 2gradC 3gradC 4gradC"

j=1
while read line2
do
if [j=i] then
resline2=line2
fi
j++
done < "Fog Rain Rain Fog"

echo $line1 $resline1 $resline2
i++
done < "Morning Day Evening Night"

This script was not tested, this is idea to make.

One problem - this line
done < "Morning Day Evening Night"
How can I transfer result lines from "cat ... | grep ... | sed ..." to cycle "while read line ... done < ..." ?
 
With array it not really work. All 4 lines are stored in $1. I assumed there will be $1 $2 $3 $4 items.
Here is my try
# cat ./temp.tmp |grep 5282C6 |sed 's/.*center">//' | sed 's/<\/td>//'
Mittag
Nachmittag
Abend
Nacht
# set -- $(cat ./temp.tmp |grep 5282C6 |sed 's/.*center">//' | sed 's/<\/td>//')
# echo "$0"
-sh
# echo "$1"
Mittag
Nachmittag
Abend
Nacht
# echo "$2"

#
 
At me, it is running...
Code:
# cat cmdrust
#!/bin/sh
set -- $(cat hrust | sed -n "s/^.*alt=\"\([a-zA-Z]*\)\".*$/\1/p" | tr '\n' ' ')
echo Par1=$1
echo Par2=$2
echo Par3=$3
echo Par4=$4

# ./cmdrust
Par1=bedeckt
Par2=bedeckt
Par3=wolkig
Par4=bewlkt
I think there is no blank between your words.
 
Zuletzt bearbeitet:
Sorry, I made test directly typing this code in terminal - thats why it works wrong.
From script it works correctly. Great!
One step closer to dream :)
 
Hm. Me again :)
I made step forward and create a script. It is not optimal, but seems it should work with different numbers of patterns. But there is one problem.
strR - is my result string, where finally should be weather for all day.
To apend new info to this string I used command
strR=$(echo "$strR $str1")
In terminal this works, but when I use it script, result is crazy (last line of input).
Can somebody point to my mistake?

Code:
#!/bin/sh

cd /var/media/ftp/ROOT/Bin

CURRENTTEMPSOURCE="http://www.donnerwetter.de/region/suchort.mv?x=0/&y=0&search=roding"
wget -O weather.tmp $CURRENTTEMPSOURCE ./weather.tmp


#set -- $(cat ./weather.tmp |grep "\"#5282C6\" class" |sed 's/.*center">//' | sed 's/<\/td>//')
#echo Par1=$1
#echo Par2=$2
#echo Par3=$3
#echo Par4=$4



i=0
strR="Weather today:"
for str1 in $(cat ./weather.tmp |grep "\"#5282C6\" class" |sed 's/.*center">//' | sed 's/<\/td>//'); do
	strR=$(echo "$strR $str1")
	echo "str1:$str1"	
	#Get Weather type for Id i
	j=0
	for str2 in $(cat ./weather.tmp |grep "\/wetsym_" |sed 's/.*alt="//' | sed 's/" width="[0-9]." height="[0-9]."><\/td>//'); do
		if [ "$i" = "$j" ]; then
			echo "Yess!!!str2:$str2"
			strR=$(echo "$strR $str2")
			echo "$strR"
		else
			echo "str2:$str2"
		fi	
		let "j += 1"
	done
	k=0	

	for str3 in $(cat ./weather.tmp |grep "\"#FFF384\" class" |sed 's/.*center">//' | sed 's/\&deg;C<\/td>//'); do
		if [ "$i" = "$k" ]; then
			echo "Yess!!!str3:$str3"
			strR=$(echo "$strR $str3 C")
			echo "$strR"
		else
			echo "str3:$str3"
		fi	
		let "k += 1"
	done	
	let "i += 1"
done

echo $strR

result of script:

Code:
# ./weather.sh
Connecting to [url]www.donnerwetter.de[/url][217.160.186.164]:80
weather.tmp          100% |*******************************| 26228       --:-- ETA
str1:Mittag
Yess!!!str2:bedeckt
 bedeckttoday: Mittag
str2:wolkig
str2:bedeckt
str2:wolkig
Yess!!!str3:5
 Cedeckttoday: Mittag
str3:7
str3:2
str3:-3
str1:Nachmittag
str2:bedeckt
Yess!!!str2:wolkig
 wolkigmittag: Mittag
str2:bedeckt
str2:wolkig
str3:5
Yess!!!str3:7
 Colkigmittag: Mittag
str3:2
str3:-3
str1:Abend
str2:bedeckt
str2:wolkig
Yess!!!str2:bedeckt
 bedecktittag: Mittag
str2:wolkig
str3:5
str3:7
Yess!!!str3:2
 Cedecktittag: Mittag
str3:-3
str1:Nacht
str2:bedeckt
str2:wolkig
str2:bedeckt
Yess!!!str2:wolkig
 wolkigtittag: Mittag
str3:5
str3:7
str3:2
Yess!!!str3:-3
 C3lkigtittag: Mittag
 C3lkigtittag: Mittag
 
Zuletzt bearbeitet von einem Moderator:
There must be special-character (^M, LF, CR ?) in your str1,2,3. This says: Write string at beginning, and that's what happens.
 
Sorry, I cannot catch your idea.
Can U give some example please?
 
Hello hrust_ray,
the result of your $(cat... line is not only a string, it contents special-character, p.a. ^M, CR or LF. When you put together two strings, this special-character are "executet" and ^M says: Start at beginning of line: "Hallo hrust_ray" + "^M123" -> "123lo hrust_ray". So eliminate special-charakter.
Another: I think it's better not to trow away not needed part of line. I would replacd the whole line with the wanted part (mark ist with \(...\) und replace with \1). Example:
Code:
for str1 in $(cat ./weather.tmp | sed -n "s/^.*#5282C6.*class.*center\">\([A-Za-z]*\)<.*$/\1/p"); do
for str2 in $(cat ./weather.tmp | sed -n "s/^.*wetsym_.*alt=\"\([a-z]*\)\".*$/\1/p"); do
for str3 in $(cat ./weather.tmp | sed -n "s/^.*#FFF384.*center\">\([-0-9]*\)&deg.*$/\1/p"); do
Try to understand this line, I'm not sure if it is a good ideas to use the color-number for finding the wanted data...

Best regard, Reiner
 
Hello hrust_ray,
the result of your $(cat... line is not only a string, it contents special-character, p.a. ^M, CR or LF. When you put together two strings, this special-character are "executet" and ^M says: Start at beginning of line: "Hallo hrust_ray" + "^M123" -> "123lo hrust_ray". So eliminate special-charakter.
Best regard, Reiner

Thank U for tipps. I'l try your variant of sed command this evening. Your variant will solve problem with special charakters? Or it is necessary to delete them in some special way? Or I should use another way to concatenate 2 strings?
 
I tried - it works. Not necessary even delete ^M symbol.

One more question.
f.e. I have following lines in file:
<td>Line1</td>
<td>Line2</td>
<td>Line2</td>
<td>Line2</td>
I want to substract Line1. It can be any symbols and cannot be defined as pattern.
Line2 can be defined as pattern. This mean regular expression should do following: Find first accurence of "Line2" and take previous line.

Thanks
 
So try to insert a "not existing" line:
<td>Line0</td>
<td>Line1</td>
<td>Line2</td>
<td>Line2</td>
<td>Line2</td>
and check out if your script will work now.
:noidea:

Joe
 
!!!! Yohoooooooooo !!!! :))))
So, script is working.
In upper line current time is displayed.
In second line is scrolling line with current weather. After some time this scrolling line shows weather for next day. In upper left conor is shown iD of currently scrolling line. In my display it is possible to use 8 preprogrammed lines. So, I have 6 lines more for some info (f.e. mails, webtransmission status...)
Here is my script, maybe somebody will be interested in it :)
#!/bin/sh


ChangeLines()
{
#echo -e "\033)11\064\06$nLineCount" > /var/ttyUSB0
#Print line number in protected mode
#echo -e "\033\046 " > /var/ttyUSB0
#echo -e "\033=01\035\046$nLineCount|\033\047\c" > /var/ttyUSB0

let "nActualLineCount = $nLineCount"

echo -e "\033)114\06$nLineCount" > /var/ttyUSB0
if [ "$nLineCount" = "$Lines" ]; then
echo "Lines Max"
nLineCount=1
else
echo "Lines Max++"
let "nLineCount += 1"
fi

}


Weather()
{
cd /var/media/ftp/ROOT/Bin

CURRENTTEMPSOURCE="http://www.donnerwetter.de/region/region.hts?plz=93422"
MORGENTEMPSOURCE="http://www.donnerwetter.de/region/morgen.hts?plz=93422"
tmp_file="/var/weather.tmp"

wget -O $tmp_file $CURRENTTEMPSOURCE


#set -- $(cat ./weather.tmp |grep "\"#5282C6\" class" |sed 's/.*center">//' | sed 's/<\/td>//')
#echo Par1=$1
#echo Par2=$2
#echo Par3=$3
#echo Par4=$4



i=0
strR="Weather today: "
strR=""


for str1 in $(cat $tmp_file | sed -n "s/^.*#5282C6.*class.*center\">\([A-Za-zьц]*\)<.*$/\1/p"); do
if [ "$i" -lt "4" ]; then
strR="$strR$str1"
#strR=$strR1
echo "str1:$str1"
#Get Weather type for Id i
j=0
for str2 in $(cat $tmp_file | sed -n "s/^.*wetsym_.*alt=\"\([a-zьц]*\)\".*$/\1/p"); do
if [ "$i" = "$j" ]; then
echo "Yess!!!str2: $str2"
strR=$(echo "$strR:$str2")
#strR=$strR1
echo "$strR"
else
echo "str2:$str2"
fi
let "j += 1"
done
k=0

for str3 in $(cat $tmp_file | sed -n "s/^.*#FFF384.*center\">\([-0-9]*\)&deg.*$/\1/p"); do
if [ "$i" = "$k" ]; then
echo "Yess!!!str3:$str3"
strR=$(echo "$strR $str3 ")
#strR=$strR1
echo "$strR"
else
echo "str3:$str3"
fi
let "k += 1"
done
fi
let "i += 1"
done

#Get current day
strD=$(cat $tmp_file |grep "<strong>[A-Za-z ,]*, [0-9]" | sed -n "s/^.*<strong>\([A-Za-z ,]*, [0-9].*\)<\/strong.*$/\1/p")
strR=$(echo "WETTER HEUTE($strD) $strR")
echo "$strR"
#strR=$(echo "$strR \n")
echo -e "\033(1 $strR" > /var/ttyUSB0




##############Get weather for morning
wget -O $tmp_file $MORGENTEMPSOURCE


#set -- $(cat $tmp_file |grep "\"#5282C6\" class" |sed 's/.*center">//' | sed 's/<\/td>//')
#echo Par1=$1
#echo Par2=$2
#echo Par3=$3
#echo Par4=$4



i=0
strR="Weather today: "
strR=""


for str1 in $(cat $tmp_file | sed -n "s/^.*#5282C6.*class.*center\">\([A-Za-zьц]*\)<.*$/\1/p"); do
if [ "$i" -lt "4" ]; then
strR="$strR$str1"
#strR=$strR1
echo "str1:$str1"
#Get Weather type for Id i
j=0
for str2 in $(cat $tmp_file | sed -n "s/^.*wetsym_.*alt=\"\([a-zьц]*\)\".*$/\1/p"); do
if [ "$i" = "$j" ]; then
echo "Yess!!!str2: $str2"
strR=$(echo "$strR:$str2")
#strR=$strR1
echo "$strR"
else
echo "str2:$str2"
fi
let "j += 1"
done
k=0

for str3 in $(cat $tmp_file | sed -n "s/^.*#FFF384.*center\">\([-0-9]*\)&deg.*$/\1/p"); do
if [ "$i" = "$k" ]; then
echo "Yess!!!str3:$str3"
strR=$(echo "$strR $str3 ")
#strR=$strR1
echo "$strR"
else
echo "str3:$str3"
fi
let "k += 1"
done
fi
let "i += 1"
done

#Get current day
strD=$(cat $tmp_file |grep "<strong>[A-Za-z ,]*, [0-9]" | sed -n "s/^.*<strong>\([A-Za-z ,]*, [0-9].*\)<\/strong.*$/\1/p")
strR=$(echo "WETTER MORGEN($strD)$strR")
echo "$strR"
#strR=$(echo "$strR \n")
echo -e "\033(2 $strR" > /var/ttyUSB0



#Turn cursor off
#echo -e "\033\140\001" > /var/ttyUSB0
#echo -e "\033=90" > /var/ttyUSB0
#echo -e "\033)11\064\061" > /var/ttyUSB0

#if [ "$bScrollStarted" = "0" ]; then
# bScrollStarted=1
# echo "Start Scrolling"
#echo -e "\033)11\064\061" > /var/ttyUSB0
#else
# echo "Scroll is already started"
#fi


}


Display()
{

while [ 1 ]; do

#Stop Scrolling
#echo -e "\033%1\c" > /var/ttyUSB0
#sleep 1

#echo -e "\033=00`date +%H:%M`" > /var/ttyUSB0
#date +"%H:%M\c" > /var/ttyUSB0

#start Scrolling
#echo -e "\033)11\064\061\c" > /var/ttyUSB0
let "nW += 1"
let "nL += 1"
echo "nW=$nW ; WeatherDelay=$WeatherDelay ; nL= $nL; nLineCount=$nLineCount"
if [ "$nW" = "$WeatherDelay" ]; then
echo "Call Weather"
nW=0
Weather
fi
if [ "$nL" = "$LinesDelay" ]; then
echo "ChangeLines"
nL=0
ChangeLines
fi
echo -e "\033=00$nActualLineCount| `date +%D_%H:%M`" > /var/ttyUSB0


sleep 30
done

}

cd /var/media/ftp/ROOT/Bin

sleep 1
#autoscroll off
echo -e "\033N" > /var/ttyUSB0
sleep 1

#brilliance
echo -e "\033G7" > /var/ttyUSB0
sleep 1

#cursor off
echo -e "\033\140\001" > /var/ttyUSB0
sleep 1

nW=0
nL=0
nActualLineCount=0
nLineCount=1
WeatherDelay=60
LinesDelay=2
Lines=2
bScrollStarted=0
Weather
ChangeLines
Display
 
Picture of your USB-Display and Link to Datasheet

Hi,

have you a picture of your USB-Display or and a Link to the manufacture please?

By.
 
Holen Sie sich 3CX - völlig kostenlos!
Verbinden Sie Ihr Team und Ihre Kunden Telefonie Livechat Videokonferenzen

Gehostet oder selbst-verwaltet. Für bis zu 10 Nutzer dauerhaft kostenlos. Keine Kreditkartendetails erforderlich. Ohne Risiko testen.

3CX
Für diese E-Mail-Adresse besteht bereits ein 3CX-Konto. Sie werden zum Kundenportal weitergeleitet, wo Sie sich anmelden oder Ihr Passwort zurücksetzen können, falls Sie dieses vergessen haben.