Input/Output from GPS


Silent-Hunter

Hardcore Member
Joined
May 29, 2010
Messages
3,477
Will it be possible to read the coordinates from the Pyra's GPS in a format like this?:
Code:
"40.748,-73.985"

I want to be able to get the weather where I currently am using this: https://github.com/schachmat/wego

I was thinking of creating a cron job that would run a script every 5 or 10 minutes that would take input from the GPS, and then run
Code:
wego -location "<input-from-GPS>" > ~/weather.fifo
and have a screen session running with
Code:
screen -d -m -S weather tail +1f ~/weather.fifo

That way whenever I wanna check the weather, I just need to run
Code:
screen -r weather
 

Grench

Forum Addict!
Joined
Oct 3, 2008
Messages
6,629
I can think of several things like that where I will want the Pyra to unsleep, do X,Y,Z, then re-sleep, using as little power as possible in the process.
 

WizardStan

Mega GP Mania
Joined
May 24, 2008
Messages
16,733
I am 99.999% certain that it gives NMEA sentences, so you should be able to read raw data off the tty and look for a GLL line, or connect gpsd to it and use the standard library. Parsing a GLL line and converting the coordinates from minutes to fractional degrees should be simple enough.
 

levi

Still fresh, damnit!
Joined
Oct 6, 2008
Messages
14,959
Location
Somewhere off the coast of the EU
I'm no expert, but as far as I can tell most bluetooth modules talk NMEA0183, but debian will likely have gpsd which takes those NMEA strings and presents them as JSON documents delivered over a network port. You'll probably need to write a little c to talk to that port and present the latest data as a printf'ed string as you desire.

Edit: Ninja'ed by stan.
 

levi

Still fresh, damnit!
Joined
Oct 6, 2008
Messages
14,959
Location
Somewhere off the coast of the EU
Or just download a helloworld.c demo for the basic source code structure, then replace the contents with bits copied out of stackoverflow answers about downloading from a port and printf. It's what the professionals do!
 

levi

Still fresh, damnit!
Joined
Oct 6, 2008
Messages
14,959
Location
Somewhere off the coast of the EU
I'd expect it to be esr's gpsd, or gpsd will be apt-gettable at least. You can download the entire source repo for it from his website and dig around in it if you like.
 

GizmoTheGreen

Active Member
Joined
Jul 27, 2009
Messages
835
Age
31
Location
Tokyo, Japan
rather than accessing a screen for the weather why not a conky script or something and display it on your desktop background? :p
 

Silent-Hunter

Hardcore Member
Joined
May 29, 2010
Messages
3,477
rather than accessing a screen for the weather why not a conky script or something and display it on your desktop background? :p
I can try that. It may not fit. Maybe I could do both. Have Conky display just the current conditions, or the current day's forecast, and use screen for a full 7 day forecast.

Can Conky monitor a named pipe?
[doublepost=1536772032,1536765634][/doublepost]Unfortunately conky is not suitable for this. It can't seem to tail a named pipe, as trying to do that causes conky to try to display as a tiny 5x5 pixel square on the desktop. And even if I have conky execute wego directly, the display is garbled because conky doesn't display normal terminal color codes.

What I plan to do is have a terminal open all the time on the last workspace, with the weather displaying in that.
 

faeredia

Still Fresh
Joined
Sep 10, 2018
Messages
7
This works ok with gpsfake (gpsd).
Need to test with real GPS hardware though.
Gpspipe is reading 10 sentences which is probably too many. Also, dividing the northing/westing by 10 is strictly not correct, but it's close enough for now.

Code:
latlon=$(gpspipe -r -n 10 | awk -F, '/GGA/ {printf("%.3f, %.3f\n", $3 / 10, $5 / 10); end;}')
wego $latlon
 

faeredia

Still Fresh
Joined
Sep 10, 2018
Messages
7
I can try that. It may not fit. Maybe I could do both. Have Conky display just the current conditions, or the current day's forecast, and use screen for a full 7 day forecast.

Can Conky monitor a named pipe?
[doublepost=1536772032,1536765634][/doublepost]Unfortunately conky is not suitable for this. It can't seem to tail a named pipe, as trying to do that causes conky to try to display as a tiny 5x5 pixel square on the desktop. And even if I have conky execute wego directly, the display is garbled because conky doesn't display normal terminal color codes.

What I plan to do is have a terminal open all the time on the last workspace, with the weather displaying in that.

google game is strong
Code:
wego $latlon -days 0 | sed 's/\x1B\[[0-9;]\+[A-Za-z]//g' > out.txt
found this to strip the colour codes. using the days = 0 option to remove the forecast, try that with conky.

Wego makes json as well, should be easy to make something pretty with that:
Code:
$ wego $latlon -days 1 -f json > out.txt

{

   "Current": {
       "Time": "2018-09-13T14:26:10+02:00",
       "Code": 13,
       "Desc": "Mostly Cloudy",
       "TempC": 15.84,
       "FeelsLikeC": 15.84,
       "ChanceOfRainPercent": 22,
       "PrecipM": 0.0001829,
       "VisibleDistM": 13330,
       "WindspeedKmph": 12.09,
       "WindGustKmph": null,
       "WinddirDegree": 47,
       "Humidity": 76
   },
   "Forecast": [
       {
           "Date": "2018-09-13T14:00:00+02:00",
           "Slots": [
               {
                   "Time": "2018-09-13T00:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 16,
                   "FeelsLikeC": 16,
                   "ChanceOfRainPercent": 0,
                   "PrecipM": 0,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 11.41,
                   "WindGustKmph": null,
                   "WinddirDegree": 37,
                   "Humidity": 77
               },
               {
                   "Time": "2018-09-13T01:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 16,
                   "FeelsLikeC": 16,
                   "ChanceOfRainPercent": 0,
                   "PrecipM": 0,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 10.44,
                   "WindGustKmph": null,
                   "WinddirDegree": 12,
                   "Humidity": 75
               },
               {
                   "Time": "2018-09-13T02:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 15.58,
                   "FeelsLikeC": 15.58,
                   "ChanceOfRainPercent": 0,
                   "PrecipM": 0,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 7.32,
                   "WindGustKmph": null,
                   "WinddirDegree": 6,
                   "Humidity": 74
               },
               {
                   "Time": "2018-09-13T03:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 15.58,
                   "FeelsLikeC": 15.58,
                   "ChanceOfRainPercent": 0,
                   "PrecipM": 0,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 6.29,
                   "WindGustKmph": null,
                   "WinddirDegree": 0,
                   "Humidity": 74
               },
               {
                   "Time": "2018-09-13T04:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 15,
                   "FeelsLikeC": 15,
                   "ChanceOfRainPercent": 2,
                   "PrecipM": 0.0000051,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 8.11,
                   "WindGustKmph": null,
                   "WinddirDegree": 26,
                   "Humidity": 77
               },
               {
                   "Time": "2018-09-13T05:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 15,
                   "FeelsLikeC": 15,
                   "ChanceOfRainPercent": 3,
                   "PrecipM": 0.0000178,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 10.11,
                   "WindGustKmph": null,
                   "WinddirDegree": 41,
                   "Humidity": 77
               },
               {
                   "Time": "2018-09-13T06:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 14,
                   "FeelsLikeC": 14,
                   "ChanceOfRainPercent": 6,
                   "PrecipM": 0.000061000002,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 11.1,
                   "WindGustKmph": null,
                   "WinddirDegree": 36,
                   "Humidity": 82
               },
               {
                   "Time": "2018-09-13T07:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 13.59,
                   "FeelsLikeC": 13.59,
                   "ChanceOfRainPercent": 16,
                   "PrecipM": 0.00016760001,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 11.41,
                   "WindGustKmph": null,
                   "WinddirDegree": 26,
                   "Humidity": 84
               },
               {
                   "Time": "2018-09-13T08:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 13.59,
                   "FeelsLikeC": 13.59,
                   "ChanceOfRainPercent": 21,
                   "PrecipM": 0.0002845,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 13.28,
                   "WindGustKmph": null,
                   "WinddirDegree": 30,
                   "Humidity": 84
               },
               {
                   "Time": "2018-09-13T09:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 13.59,
                   "FeelsLikeC": 13.59,
                   "ChanceOfRainPercent": 36,
                   "PrecipM": 0.0003734,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 13.53,
                   "WindGustKmph": null,
                   "WinddirDegree": 37,
                   "Humidity": 82
               },
               {
                   "Time": "2018-09-13T10:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 13.59,
                   "FeelsLikeC": 13.59,
                   "ChanceOfRainPercent": 46,
                   "PrecipM": 0.0004674,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 14.26,
                   "WindGustKmph": null,
                   "WinddirDegree": 37,
                   "Humidity": 81
               },
               {
                   "Time": "2018-09-13T11:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 14.17,
                   "FeelsLikeC": 14.17,
                   "ChanceOfRainPercent": 51,
                   "PrecipM": 0.0005309,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 11.64,
                   "WindGustKmph": null,
                   "WinddirDegree": 46,
                   "Humidity": 81
               },
               {
                   "Time": "2018-09-13T12:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 14.58,
                   "FeelsLikeC": 14.58,
                   "ChanceOfRainPercent": 46,
                   "PrecipM": 0.0004775,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 11.73,
                   "WindGustKmph": null,
                   "WinddirDegree": 52,
                   "Humidity": 81
               },
               {
                   "Time": "2018-09-13T13:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 15,
                   "FeelsLikeC": 15,
                   "ChanceOfRainPercent": 39,
                   "PrecipM": 0.0003581,
                   "VisibleDistM": 10010,
                   "WindspeedKmph": 13.53,
                   "WindGustKmph": null,
                   "WinddirDegree": 47,
                   "Humidity": 79
               },
               {
                   "Time": "2018-09-13T14:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 15.61,
                   "FeelsLikeC": 15.61,
                   "ChanceOfRainPercent": 27,
                   "PrecipM": 0.00023620001,
                   "VisibleDistM": 11670,
                   "WindspeedKmph": 12.57,
                   "WindGustKmph": null,
                   "WinddirDegree": 47,
                   "Humidity": 77
               },
               {
                   "Time": "2018-09-13T15:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 16.14,
                   "FeelsLikeC": 16.14,
                   "ChanceOfRainPercent": 15,
                   "PrecipM": 0.0001118,
                   "VisibleDistM": 15470,
                   "WindspeedKmph": 11.47,
                   "WindGustKmph": null,
                   "WinddirDegree": 47,
                   "Humidity": 75
               },
               {
                   "Time": "2018-09-13T16:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 16.73,
                   "FeelsLikeC": 16.73,
                   "ChanceOfRainPercent": 7,
                   "PrecipM": 0.0000279,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 10.36,
                   "WindGustKmph": null,
                   "WinddirDegree": 46,
                   "Humidity": 72
               },
               {
                   "Time": "2018-09-13T17:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 17.09,
                   "FeelsLikeC": 17.09,
                   "ChanceOfRainPercent": 3,
                   "PrecipM": 0.0000051,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 9.53,
                   "WindGustKmph": null,
                   "WinddirDegree": 43,
                   "Humidity": 71
               },
               {
                   "Time": "2018-09-13T18:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 17.12,
                   "FeelsLikeC": 17.12,
                   "ChanceOfRainPercent": 4,
                   "PrecipM": 0.0000127,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 8.67,
                   "WindGustKmph": null,
                   "WinddirDegree": 35,
                   "Humidity": 70
               },
               {
                   "Time": "2018-09-13T19:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 16.37,
                   "FeelsLikeC": 16.37,
                   "ChanceOfRainPercent": 5,
                   "PrecipM": 0.0000356,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 7.6,
                   "WindGustKmph": null,
                   "WinddirDegree": 25,
                   "Humidity": 74
               },
               {
                   "Time": "2018-09-13T20:00:00+02:00",
                   "Code": 13,
                   "Desc": "Mostly Cloudy",
                   "TempC": 15.37,
                   "FeelsLikeC": 15.37,
                   "ChanceOfRainPercent": 7,
                   "PrecipM": 0.000053300002,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 6.71,
                   "WindGustKmph": null,
                   "WinddirDegree": 17,
                   "Humidity": 79
               },
               {
                   "Time": "2018-09-13T21:00:00+02:00",
                   "Code": 1,
                   "Desc": "Overcast",
                   "TempC": 14.75,
                   "FeelsLikeC": 14.75,
                   "ChanceOfRainPercent": 5,
                   "PrecipM": 0.0000356,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 6.23,
                   "WindGustKmph": null,
                   "WinddirDegree": 11,
                   "Humidity": 82
               },
               {
                   "Time": "2018-09-13T22:00:00+02:00",
                   "Code": 1,
                   "Desc": "Overcast",
                   "TempC": 14.29,
                   "FeelsLikeC": 14.29,
                   "ChanceOfRainPercent": 3,
                   "PrecipM": 0.0000127,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 5.91,
                   "WindGustKmph": null,
                   "WinddirDegree": 6,
                   "Humidity": 85
               },
               {
                   "Time": "2018-09-13T23:00:00+02:00",
                   "Code": 1,
                   "Desc": "Overcast",
                   "TempC": 13.82,
                   "FeelsLikeC": 13.82,
                   "ChanceOfRainPercent": 0,
                   "PrecipM": 0,
                   "VisibleDistM": 16090,
                   "WindspeedKmph": 5.73,
                   "WindGustKmph": null,
                   "WinddirDegree": 1,
                   "Humidity": 87
               }
           ],
           "Astronomy": {
               "Moonrise": "0001-01-01T00:00:00Z",
               "Moonset": "0001-01-01T00:00:00Z",
               "Sunrise": "2018-09-13T06:39:33+02:00",
               "Sunset": "2018-09-13T19:29:18+02:00"
           }
       }
   ],
   "Location": "52.308998,13.233000",
   "GeoLoc": {
       "Latitude": 52.309,
       "Longitude": 13.233
   }
}
 

hns

Well-Known Member
Joined
Dec 4, 2011
Messages
576
Location
Oberhaching
Yes the GPS receiver reports raw NMEA like this:

$GPGSV,3,1,12,02,05,320,17,03,52,091,20,06,45,299,18,09,58,230,22*7F
$GPGSV,3,2,12,17,17,237,26,19,25,262,20,22,30,102,17,23,84,094,18*7D
$GPGSV,3,3,12,31,09,033,19,01,14,156,,07,05,181,,26,02,070,*74
$GLGSV,3,1,09,86,46,240,28,87,31,320,25,71,66,323,23,72,23,272,17*65
$GLGSV,3,2,09,70,40,059,,73,15,130,,80,32,071,,79,08,011,*69
$GLGSV,3,3,09,85,10,191,*59
$GPGGA,174045.0,4800.870320,N,01135.288585,E,1,06,1.2,595.8,M,47.0,M,,*56
$GNGNS,174045.0,4800.870320,N,01135.288585,E,AA,10,1.2,595.8,47.0,,*65
$GPVTG,165.1,T,165.1,M,0.0,N,0.0,K,A*23
$GPRMC,174045.0,A,4800.870320,N,01135.288585,E,0.0,165.1,240818,0.0,E,A*0C
$GPGSA,A,2,03,06,09,17,19,31,,,,,,,1.4,1.2,0.8*3D
$GNGSA,A,2,03,06,09,17,19,31,,,,,,,1.4,1.2,0.8*23
$GNGSA,A,2,71,72,86,87,,,,,,,,,1.4,1.2,0.8*21

There is a demo-script to enable everything and report the tty device name:

http://git.goldelico.com/?p=letux-k...6998f7f4fd5ca3f89eaf0b67;hb=refs/heads/master

So you can filter the records and cut out coordinates (need some processing for E/W and N/S)

But by using gpsd you can do much more.
 

Silent-Hunter

Hardcore Member
Joined
May 29, 2010
Messages
3,477
I was planning to use gpsd, yeah. I'll just have to experiment when the Pyra arrives I think. Not sure why E/W and N/S need processing, shouldn't the coordinates just be latitude and longitude?
 

levi

Still fresh, damnit!
Joined
Oct 6, 2008
Messages
14,959
Location
Somewhere off the coast of the EU
There are at least two conventions for lat/long coordinates; one assume north and east are positive, and report anything south or west as negative in the respective column, or a more human readable format which is to state whether the coordinate system you're using is N and W or S and E or a combination of the two. The NMEA status lines use the latter, so if you want them in your format you'll need to convert them.

Edit: The negative coordinates are S and W, so the only entirely negative countries in Europe are Portugal and Ireland (and Wales and Scotland if you count them separately)
 
Last edited:

Silent-Hunter

Hardcore Member
Joined
May 29, 2010
Messages
3,477
There are at least two conventions for lat/long coordinates; one assume north and west are positive, and report anything south or east as negative in the respective column, or a more human readable format which is to state whether the coordinate system you're using is N and W or S and E or a combination of the two. The NMEA status lines use the latter, so if you want them in your format you'll need to convert them.
Oh I see. I'll have to figure out which type wego uses.
[doublepost=1536878699,1536877945][/doublepost]If anyone makes a weather widget for the Pyra, make sure it supports the darksky.net API. It's free for up to 1000 calls per day, and is free for anyone to sign up. So you could have the Pyra check every 5 minutes without paying. As long as each user uses their own API key. And it accepts latitude and longitude for the location, so it's easy to integrate with a GPS.
 

tarator

Very Active Member
Joined
Jun 4, 2016
Messages
153
Age
36
Location
Vienna
Oh I see. I'll have to figure out which type wego uses.
[doublepost=1536878699,1536877945][/doublepost]If anyone makes a weather widget for the Pyra, make sure it supports the darksky.net API.

Other Weather API's which are interesting:

* https://openweathermap.org/ (used the API already, it's fairly simple, they have free plans.).
* https://www.timeanddate.com/ (never used their API, I think they only have paid plans)
 
Top