LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2022, 03:13 PM   #1
Mobianuser
LQ Newbie
 
Registered: Oct 2022
Posts: 8

Rep: Reputation: 0
Condition field Ina bash script


Hi
I need. Shell script to open a program, in this case foxtrotgps when the gpsd receives a gps signal what happen in minutes. To automate it I need the right condition written and I do not know how
Here what I need
While [condition]
do
Done
Foxtrotgps
----
The condition is
When gpspipe --nmea got data , open foxtrotgps otherwise keep looking for data
It is something like
[($gpspipe --nmea) is null]
Or
[($gpspipe --nmea= "0"]

But do not know.
 
Old 10-05-2022, 05:51 PM   #2
teckk
Senior Member
 
Registered: Oct 2004
Distribution: Arch
Posts: 4,448
Blog Entries: 5

Rep: Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548
Code:
a=1

while [ "$a" -lt 10 ]; do
    echo ""$a" is less than 10"
    a=$((a + 1))
    sleep .2
done

echo ""$a" is equal to 10"
Code:
for ((a=1; a<10; a++)); do
    echo ""$a" is less than 10"
    sleep .2
done

echo ""$a" is equal to 10"
 
1 members found this post helpful.
Old 10-05-2022, 09:56 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,958

Rep: Reputation: 3173Reputation: 3173Reputation: 3173Reputation: 3173Reputation: 3173Reputation: 3173Reputation: 3173Reputation: 3173Reputation: 3173Reputation: 3173Reputation: 3173
I tried to look at the man page for gpspipe and can't see the switch you have used (--nmea), syou would need to tell us what is
the expected output(s) from running that command?

Also, as shown by teckk, please use [code][/code] tags around your code to make it more easily readable
 
Old 10-05-2022, 10:51 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 23,677

Rep: Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184
https://gpsd.gitlab.io/gpsd/gpspipe.html
Quote:
-r, --nmea

Cause NMEA sentences to be output. This may be NMEA, pseudo NMEA built from binary data, or some combination of both.
Quote:
gpsd receives a gps signal what happen in minutes
Can you describe in more detail what you mean? What make/model GPS receiver are you using? I have not played with my receiver in awhile but as soon as it is powered up it will output NEMA messages regardless if it is locked yet. I am not familiar with foxtrotgps but do you need a GPS fix before you can start the application?

I have not played with gpspipe but there could be some options that might be useful like output n number of messages, delay x seconds or sleep for 10 seconds.
untested ...
Code:
ready=$(gpspipe -l -n 10)
until [ ! -z $ready ]; do
  ready=$(gpspipe -l -n 10)
done
If you are looking for a valid fix then you need to examine $GPGGA or $GPGSV to verify.

Last edited by michaelk; 10-06-2022 at 05:46 AM.
 
1 members found this post helpful.
Old 10-06-2022, 02:13 AM   #5
Mobianuser
LQ Newbie
 
Registered: Oct 2022
Posts: 8

Original Poster
Rep: Reputation: 0
Iam using gps with PinephonePro

Please, read

https://wiki.mobian-project.org/doku.php?id=location

This is the output once you get a fix

$GLGSV,3,1,09,78,42,220,32,86,14,132,15,77,65,331,17,76,18,012,26,1*7F

What I do
I start gpspipe --nmea in my terminal and what I get a fix I start the map program foxtrotgps
But I want to automate the process instead of waiting for a fix. And this can be done with a while loop or I think it can be done, but I need the right condition as the fix comes in 3 to 7 minutes more or less in my mobile phone. Before the fix I do not know the gpspipe value but must be 0 or empty. I am not a good programmer but intend to do it

Last edited by Mobianuser; 10-06-2022 at 02:22 AM.
 
Old 10-06-2022, 02:24 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 19,250

Rep: Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525
there is no null in bash, you need to check if the result is an empty string
Code:
[ $(gpspipe --nmea) = "" ]
But your sample code contains a lot of syntax errors, so most probably this change will not solve all of your issues.
 
1 members found this post helpful.
Old 10-06-2022, 05:46 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 23,677

Rep: Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184
Is $GLGSV the only NMEA message you see in the output?
Untested again.
Code:
sleep 5m
ready=$(gpspipe -n 10)
until [ ! -z $ready ]; do
  ready=$(gpspipe -n 10)
done
 
1 members found this post helpful.
Old 10-06-2022, 10:21 AM   #8
Mobianuser
LQ Newbie
 
Registered: Oct 2022
Posts: 8

Original Poster
Rep: Reputation: 0
O. According to the wiki these are the possible outputs
$GLGSV,3,1,09,78,42,220,32,86,14,132,15,77,65,331,17,76,18,012,26,1*7F
$GLGSV,3,2,09,88,45,277,25,87,66,198,17,71,11,119,28,72,04,073,16,1*7A
$GLGSV,3,3,09,70,03,165,,1*47
$GPGSV,3,1,11,02,67,125,30,05,18,022,18,06,30,133,28,11,,,28,1*51
$GPGSV,3,2,11,12,85,039,16,24,14,337,18,25,53,230,30,29,27,261,17,1*65
$GPGSV,3,3,11,19,04,101,,20,34,039,,31,03,210,,1*55
$GPGGA,120529.00,XXX,S,YYY,E,1,03,3.8,4.9,M,-9.0,M,,*60
$GNGNS,120529.00,XXX,S,YYY,E,AAN,05,3.8,4.9,-9.0,,,V*66
$GPVTG,0.0,T,349.3,M,0.0,N,0.0,K,A*2E
$GPRMC,120529.00,A,XXX,S,YYY,E,0.0,0.0,040721,10.7,E,A,V*64
$GPGSA,A,3,02,06,25,,,,,,,,,,4.0,3.8,1.0,1*22
$GNGSA,A,3,02,06,25,,,,,,,,,,4.0,3.8,1.0,1*3C
$GNGSA,A,3,71,78,,,,,,,,,,,4.0,3.8,1.0,2*35
XXX and YYY is your exact latitude and longitude, respectively. Once, you got that GPS fix, start xgps app in Phosh, as it will give you a much better overview, of how many and which satellites are currently used.
 
Old 10-06-2022, 10:27 AM   #9
Mobianuser
LQ Newbie
 
Registered: Oct 2022
Posts: 8

Original Poster
Rep: Reputation: 0
Pan64, next week ( I cannot do it before) I will check the empty string and see what happen. Thanks to all of you for your answers. I will check it and let you know. My operating system is Mobian, a Debían adapted to pinephone mobiles
Michaelk, I do not understand the code. Could you explain s bit in plain text? I formerly used to code in visual basic but not in shell but I do my best to understand it

Last edited by Mobianuser; 10-06-2022 at 10:35 AM.
 
Old 10-06-2022, 11:56 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 23,677

Rep: Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184
I've modified my script a bit but since I don't have anyway of actually testing it I have no idea if it works.
Code:
sleep 5m # Wait 5 minutes, I picked something in between your 3-7 minutes to acquire a fix.
ready=$(gpspipe -n 20)  # just grab 20 messages. 
while true; do
  ready=$(echo $line | grep '$GPGSA'| awk -F "," '{print $3}') #strip the mode from the GPGSA string.
  if [[ "$ready" == "3" ]]; then # if it equals 3 you have a 3D fix.
     echo "3D fix"
     break
  fi
  ready=$(gpspipe -n 20)
done
http://aprs.gids.nl/nmea/
 
1 members found this post helpful.
Old 10-06-2022, 02:35 PM   #11
Mobianuser
LQ Newbie
 
Registered: Oct 2022
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks MichaelK. I will check it but I am inside city for the weekend an I need to go country side to better get a gps fix
Instead to write sleep as I do not know how long it takes gpsd to get data where country side or inside town, could we check the moment it receives data as

While [ $gpspipe --nmea = " " ]
read gpspipe --nmea
do

done

But first I will write in the perminal

Sudo start gpsd.service
gpspipe --nmea

and see how long it takes to get the first line of data
And I'll let you kwow. Maybe this loop it is not necessary
And, sorry, my name is Emilio

I could check I today. It is different that I expected
It makes a kind of presentation and then almost 245 lines in a second. So I decided to do
sudo systemctl start gpsd.device
And then click on the foxtrotgps icon
To wait for a fix on the map
mobian@mobian:~$ gpspipe --nmea
{"class":"VERSION","release":"3.22","rev":"3.22","proto_major":3,"proto_minor":14}
{"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyUSB1","driver":"NMEA0183","activated":"2022-10-09T17:31:34.224Z","flags":1,"native":0,"bps":9600,"parity":"N","stopbits":1,"cycle":1.00}]}
{"class":"WATCH","enable":true,"json":false,"nmea":true,"raw":0,"scaled":false,"timing":false,"split 24":false,"pps":false}
$GLGSV,2,1,08,74,16,042,22,76,42,244,17,72,26,156,25,66,35,324,,1*75
$GLGSV,2,2,08,75,67,005,,65,76,198,,84,03,059,,83,02,004,,1*7A
$GPGSV,3,1,11,05,22,196,25,12,14,208,25,13,61,109,32,14,28,047,28,1*6B
$GPGSV,3,2,11,17,23,085,32,19,17,120,30,23,26,305,20,30,07,075,18,1*6E
$GPGSV,3,3,11,10,05,327,,15,80,274,,24,42,281,,1*50
$GPGGA,173135.00,4123.413447,N,00209.344126,E,1,06,0.9,89.0,M,51.0,M,,*5C
$GNGNS,173135.00,4123.413447,N,00209.344126,E,AAN,09,0.9,89.0,51.0,,,V*53
$GPVTG,189.2,T,190.8,M,0.0,N,0.0,K,A*21
$GPRMC,173135.00,A,4123.413447,N,00209.344126,E,0.0,189.2,091022,1.5,W,A,V*59
$GPGSA,A,3,13,14,17,19,23,30,,,,,,,1.3,0.9,0.9,1*26
$GNGSA,A,3,13,14,17,19,23,30,,,,,,,1.3,0.9,0.9,1*38
$GNGSA,A,3,72,74,76,,,,,,,,,,1.3,0.9,0.9,2*37
$GLGSV,2,1,08,74,16,042,22,76,42,244,19,72,26,156,25,66,35,324,,1*7B
$GLGSV,2,2,08,75,67,005,,65,76,198,,84,03,059,,83,02,004,,1*7A
$GPGSV,3,1,11,05,22,196,21,12,14,208,21,13,61,109,27,14,28,047,22,1*65
$GPGSV,3,2,11,17,23,085,22,19,17,120,22,23,26,305,20,30,07,075,18,1*6C
$GPGSV,3,3,11,10,05,327,,15,80,274,,24,42,281,,1*50
$GPGGA,173136.00,4123.413446,N,00209.344127,E,1,06,0.9,89.0,M,51.0,M,,*5F
$GNGNS,173136.00,4123.413446,N,00209.344127,E,AAN,09,0.9,89.0,51.0,,,V*50
$GPVTG,189.2,T,190.8,M,0.0,N,0.0,K,A*21
$GPRMC,173136.00,A,4123.413446,N,00209.344127,E,0.0,189.2,091022,1.5,W,A,V*5A

And it works. So I close it. Thanks a lot to all of you

Last edited by Mobianuser; 10-09-2022 at 04:09 PM.
 
Old 10-24-2022, 08:47 AM   #12
Mobianuser
LQ Newbie
 
Registered: Oct 2022
Posts: 8

Original Poster
Rep: Reputation: 0
Find stings and get data in bash

In these series of data
"class":"VERSION","release":"3.22","rev":"3.22","proto_major":3,"proto_minor":14}
{"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyUSB1","driver":"NMEA0183","activated":"2022-10-09T17:31:34.224Z","flags":1,"native":0,"bps":9600,"parity":"N","stopbits":1,"cycle":1.00}]}
{"class":"WATCH","enable":true,"json":false,"nmea":true,"raw":0,"scaled":false,"timing":false,"sp lit 24":false,"pps":false}
$GLGSV,2,1,08,74,16,042,22,76,42,244,17,72,26,156,25,66,35,324,,1*75
$GLGSV,2,2,08,75,67,005,,65,76,198,,84,03,059,,83,02,004,,1*7A
$GPGSV,3,1,11,05,22,196,25,12,14,208,25,13,61,109,32,14,28,047,28,1*6B
$GPGSV,3,2,11,17,23,085,32,19,17,120,30,23,26,305,20,30,07,075,18,1*6E
$GPGSV,3,3,11,10,05,327,,15,80,274,,24,42,281,,1*50
$GPGGA,173135.00,4123.413447,N,00209.344126,E,1,06,0.9,89.0,M,51.0,M,,*5C
$GNGNS,173135.00,4123.413447,N,00209.344126,E,AAN,09,0.9,89.0,51.0,,,V*53
$GPVTG,189.2,T,190.8,M,0.0,N,0.0,K,A*21
$GPRMC,173135.00,A,4123.413447,N,00209.344126,E,0.0,189.2,091022,1.5,W,A,V*59
$GPGSA,A,3,13,14,17,19,23,30,,,,,,,1.3,0.9,0.9,1*26
$GNGSA,A,3,13,14,17,19,23,30,,,,,,,1.3,0.9,0.9,1*38
$GNGSA,A,3,72,74,76,,,,,,,,,,1.3,0.9,0.9,2*37
$GLGSV,2,1,08,74,16,042,22,76,42,244,19,72,26,156,25,66,35,324,,1*7B
$GLGSV,2,2,08,75,67,005,,65,76,198,,84,03,059,,83,02,004,,1*7A
$GPGSV,3,1,11,05,22,196,21,12,14,208,21,13,61,109,27,14,28,047,22,1*65
$GPGSV,3,2,11,17,23,085,22,19,17,120,22,23,26,305,20,30,07,075,18,1*6C
$GPGSV,3,3,11,10,05,327,,15,80,274,,24,42,281,,1*50
$GPGGA,173136.00,4123.413446,N,00209.344127,E,1,06,0.9,89.0,M,51.0,M,,*5F
$GNGNS,173136.00,4123.413446,N,00209.344127,E,AAN,09,0.9,89.0,51.0,,,V*50
$GPVTG,189.2,T,190.8,M,0.0,N,0.0,K,A*21
$GPRMC,173136.00,A,4123.413446,N,00209.344127,E,0.0,189.2,091022,1.5,W,A,hl
UTC:12222
longitude:2.......
latitude:41.....
I would like to read a loop reading data
Sudo mmcli -m any --location-get
Until the word longitude can be read and then get longitude dats and latitude data in atwo variables to be displayed via notify-send
Can you help, please
 
Old 10-24-2022, 10:54 AM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 23,677

Rep: Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184Reputation: 5184
Can you post relevant output from the mmcli command?
 
Old 10-24-2022, 11:52 AM   #14
Mobianuser
LQ Newbie
 
Registered: Oct 2022
Posts: 8

Original Poster
Rep: Reputation: 0
I do not understand the question but let me explain: I want to write a program to present a gps position on the screen with the ModemManager
The program is as follows
#!/bin/bash
sudo mmcli -e -m any
sudo mmcli -m any --location-enable-gps-nmea --location-enable-gps-raw
sleep 5m
sudo mmcli any --location-get

In 5 minutes more or less I get the position as above,after several $lines at the end it gives me the position as
Time
Longitud
Latitude
In the Terminal window ( but I want it in the window set by notify-send during 5 seconds by default)As you can see above
I want to replace sleep 5m with a loop where the word longitude is captured and then the value
I would like to read line by line as they are coming from sudo mmcli any --location-get instead of taking 20 lines or so
until finding the string longitude. Something like
If [[$value ==*"longitude"* ]]
longitude=2.245 etc
latitude=42.654
fi
and then
notify-send $longitude $latitude

But I do not know if a line by line can be read,(captured) while the code to get position is on

Last edited by Mobianuser; 10-24-2022 at 12:12 PM.
 
Old 10-24-2022, 12:09 PM   #15
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 2,985

Rep: Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120

Please be sure you use "[code]..[/code]" tags when posting scripts, data, etc - it makes things much more readable.

Quote:
I want to replace sleep 5m with a loop where the word longitude is captured and then the value
Try grep with --max-count option?

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace string ina file with specific condition pradeepspa Linux - Newbie 4 01-30-2017 04:09 PM
check Negative egrep condition in an if condition novicunix Programming 5 02-02-2013 01:52 AM
.htaccess how to require authn for all files ina folder, besids certain file extentns pxshock Linux - Server 0 04-27-2008 07:40 PM
using OR condition in if condition Fond_of_Opensource Linux - Newbie 2 10-20-2006 01:34 AM
How to display multiple bmps one after the other ina window frmhero2zero Programming 2 10-04-2002 11:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration