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. |
Code:
a=1 Code:
for ((a=1; a<10; a++)); do |
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 :) |
https://gpsd.gitlab.io/gpsd/gpspipe.html
Quote:
Quote:
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) |
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 |
there is no null in bash, you need to check if the result is an empty string
Code:
[ $(gpspipe --nmea) = "" ] |
Is $GLGSV the only NMEA message you see in the output?
Untested again. Code:
sleep 5m |
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. |
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 |
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. |
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 |
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 |
Can you post relevant output from the mmcli command?
|
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 |
Please be sure you use "[code]..[/code]" tags when posting scripts, data, etc - it makes things much more readable.
Quote:
|
All times are GMT -5. The time now is 10:48 AM. |