{"id":16518,"date":"2017-01-27T10:33:40","date_gmt":"2017-01-27T16:33:40","guid":{"rendered":"http:\/\/www.multitech.net\/developer\/?page_id=16518"},"modified":"2022-05-09T12:12:38","modified_gmt":"2022-05-09T17:12:38","slug":"gpsd","status":"publish","type":"page","link":"https:\/\/www.multitech.net\/developer\/software\/mlinux\/using-mlinux\/gpsd\/","title":{"rendered":"GPSD"},"content":{"rendered":"<p>This feature is only available on certain products and models (not available with all devices).<\/p>\n<p><strong>NOTE:\u00a0<\/strong>Prior to mLinux<sup>\u2122<\/sup>\/AEP 5.0.0 gpsd usage of the GPS was not compatible with lora-packet-forwarder. It was not possible to use the Multitech supplied Lora-Packet-Forwarder with the GNSS port, and GPSD at the same time. This was fixed in the 5.0.0 releases.<\/p>\n<h3>GPSD Overview<\/h3>\n<p>GPSD is the server that monitors the GNSS\/GPS (if included with your device) and makes time and position information available to client programs, such as gpsmon and NTPD.\u00a0 GPSD communicates with NTPD via shared memory to provide the GPS time. \u00a0The server allows multiple programs to use the GNSS\/GPS. \u00a0It also detects leap second and tells NTPD of an upcoming leap second and its direction on the day of the leap second.<\/p>\n<p>The script\u00a0<strong>\/usr\/sbin\/gpsd_fixed<\/strong>\u00a0has no parameters, but uses the file\u00a0<strong>\/etc\/default\/gpsd <\/strong>which\u00a0contains\u00a0the\u00a0parameter,<strong>\u00a0GPSFIX,<\/strong>\u00a0as a criteria to determine if the GNSS\/GPS currently has a fix (lock) on the satellites. If there is a fix, it creates a file\u00a0<strong>\/var\/run\/gpsfix<\/strong>, with the contents equal to the actual GPS fix value found. Otherwise the file is deleted.\u00a0The script\u00a0<strong>\/usr\/sbin\/gpsd_settime<\/strong>\u00a0checks for a GPS fix. If so, it sets the system clock to the GPS time, first using the GNSS\/GPS, in case there is a huge change, then using\u00a0<strong>ntpd -gq<\/strong>\u00a0to get it much closer.<\/p>\n<p>NTP\/NTPD ultimately manages the time based reliability and availability of time sources (with top priority going to the GPS time).\u00a0For more information on NTPD and how it manages time, see the\u00a0<a href=\"https:\/\/www.multitech.net\/developer\/software\/mlinux\/using-mlinux\/ntpd\/%20\">NTPD<\/a>\u00a0page.<\/p>\n<p>Here are the key files for setup of the GPSD on the device:<\/p>\n<ul>\n<li><b>GPSD configuration file<\/b> is located in <b>\/etc\/default\/gpsd<\/b>. This file is set up for u-Blox, the\u00a0proprietary communications protocol for the u-Blox chip used on the device.<\/li>\n<li><b>GPSD init script <\/b>is located in \/<b>etc\/init.d\/gpsd<\/b>. This file can be used to start GPSD manually.<\/li>\n<li><b>mtsio configuration file<\/b> is located in <b>\/etc\/default\/mts-io<\/b>. This determines whether or not the GNSS\/GPS is reset during boot. After a reset, the GPS takes some time to acquire the satellite information.<\/li>\n<li><b>gpsfix file<\/b> is created after the GPS has a fix on the satellites indicating that the GPS now has valid data.<\/li>\n<\/ul>\n<p><span style=\"font-size: medium;\"><b>GPSD configuration file<\/b><\/span><\/p>\n<p>Here is the default configuration file, \/etc\/default\/gpsd:<\/p>\n<pre class=\"brush:shell\">ENABLED=\"yes\"\r\nGPSD_SOCKET=\"\/var\/run\/gpsd.sock\"\r\nGPSD_OPTIONS=\"-n -D 1\"\r\n\r\n# Conduit 0.1 GPS devices\r\nGPS_LINE=\/dev\/ttyXRUSB2\r\n\r\n# Highest speed permitted by uBlox.\r\nGPS_BAUD=115200\r\nGPS_DEVICES=\"$GPS_LINE \/dev\/pps0\"\r\n\r\nGPS_FIXFILE=\/var\/run\/gpsfix\r\n\r\n# GPSD\/UBlox Lock requirement\r\n# Create GPS_FIXFILE when reached.# UBlox NAV SOL (0x01 0x06) at gpsFix value\r\n# and above\r\n# 00 No Fix\r\n# 01 Dead reckoning only\r\n# 02 2D fix\r\n# 03 3D fix\r\n# 04 GPS + dead reckoning combined\r\n# 05 Time only fix\r\nGPSFIX=\"03 05\"<\/pre>\n<p>The GPSD program uses the uBlox proprietary binary message mode to communicate with the GPS as the most efficient method.<\/p>\n<p>Here are the major elements of the <b>GPSD<\/b> configuration file:.<\/p>\n<ul>\n<li><b>GPSD_SOCKET <\/b>can be used to communicate with <b>GPSD. <\/b><\/li>\n<li><b>GPSD_OPTIONS<\/b> for the program include:\n<ul>\n<li><b>-D<\/b> specifies the debug level. We use 1 in the example file above.<\/li>\n<li><b>-n<\/b> causes the <b>GPSD daemon<\/b> to immediately start communicating with the GPS.<\/li>\n<li><b>GPS_LINE<\/b> indicates the Serial driver name for the GPS.<\/li>\n<li><b>GPS_BAUD<\/b> shows baud rate set to 115200. At a baud rate of 9600, the device does not get the GPS messages quickly enough.<\/li>\n<li><b>GPS_FIXFILE<\/b> contains GPSFIX level as contents. This file indicates the GPS is ready to use.<\/li>\n<li><b>GPSFIX<\/b> assigns the valid <b>FIX values<\/b> that should be found in the <b>NAV SOL<\/b> <b>message<\/b> from the GPS. The values indicate the GPS is ready to use.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><span style=\"font-size: medium;\"><b>gpsmon utility<\/b><\/span><\/p>\n<p>The GNSS\/GPS output may be observed using the <b>gpsmon utility<\/b>. <b>gpsmon <\/b>works best using ssh and ethernet with the device.<\/p>\n<p>To run the utility, enter the following command:<\/p>\n<pre class=\"brush:shell\">mtcdt: gpsmon<\/pre>\n<p>The resulting output displays:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"https:\/\/www.multitech.net\/developer\/wp-content\/uploads\/2017\/01\/gpsmon-utility-output.png\" width=\"888\" height=\"708\" \/><\/p>\n<p>Notice the box with the label <b>NAV_SOL<\/b><i> <\/i>at the bottom. In this box, the bottom line is <b>Fix 0x03<\/b>. This is one of the acceptable values mentioned in \/etc\/default\/gpsd for GPSFIX.<\/p>\n<p>With the value of GPSFIX set to <b>03 05<\/b> in the configuration file, either <b>0x03<\/b> or <b>0x05<\/b> is acceptable in the <b>gpsmon<\/b> output.<\/p>\n<p><span style=\"font-size: medium;\"><b>Bash script to check GNSS\/GPS status<\/b><\/span><\/p>\n<p>This <b>bash script<\/b> is located in\u00a0 <b>\/usr\/sbin\/gpsd_fixed <\/b>on the device. It uses the utility, <b>gpsmon,<\/b> to determine when the <b>GPS fix field<\/b> in the <b>UBX NAV SOL message<\/b> indicates a fix matching one of the fixes of the <b>GPSFIX variables<\/b> specified in the configuration file (<b>\/etc\/default\/gpsd<\/b>). The fix choices in the <b>GPSFIX variable<\/b> are space separated and the values are in hex, but no value over<b> 05<\/b> is allowed.<\/p>\n<p>Here is how the <b>bash script<\/b> works:<\/p>\n<p style=\"padding-left: 30px;\">1. To execute the <strong>b<\/strong><b>ash script<\/b>, enter the command:<\/p>\n<pre class=\"brush:shell\">mtcdt: \/usr\/sbin\/gpsd_fixed<\/pre>\n<p style=\"padding-left: 30px;\">2. The script returns an exit status of <b>0 <\/b>if one of the fixes specified is achieved.<\/p>\n<p style=\"padding-left: 30px;\">3. One of the following occurs next:<\/p>\n<p style=\"padding-left: 60px;\">a. If the script executes and one of the <b>GPSFIX values<\/b> is achieved, the <b>GPS fix field valu<\/b>e is placed in the file <b>GPS_FIXFILE<\/b>, as specified in <b>\/etc\/default\/gpsd<\/b>.<\/p>\n<p style=\"padding-left: 60px;\"><strong>OR<\/strong><\/p>\n<p style=\"padding-left: 60px;\">b. If the <b>fix value<\/b> is not one of the values specified in <b>GPSFIX<\/b>, the file <b>GPS_FIXFILE<\/b> is removed. The GPS is not ready yet. Wait and try again.<\/p>\n<p style=\"padding-left: 30px;\">4. From powerup, it takes six to ten minutes before the <b>GPS fix<\/b> reaches <b>0x03<\/b>, which is a <b>3D fix<\/b>.<\/p>\n<p><span style=\"font-size: medium;\"><b>Bash script to set the system clock <\/b><\/span><\/p>\n<p>This bash script sets the system clock using <b>gpsmon output <\/b>if <b>\/usr\/sbin\/gpsd_fixed<\/b> indicates the <b>GPS fix<\/b>.<\/p>\n<p>To execute this script, enter the following:<\/p>\n<pre class=\"brush:shell\">mtcdt:\/usr\/sbin\/gpsd_settime<\/pre>\n<p>This is needed prior to starting <b>NTPD<\/b> to prevent the <b>GPS<\/b> from being marked as a falseticker.<\/p>\n<p><span style=\"font-size: medium;\"><b>Using gpsd with the gpsd python library<\/b><\/span><\/p>\n<p>The gpsd python library is contained in the following package:<\/p>\n<p>python-pygps<\/p>\n<p>This library is provided on the mLinux image, and from the Downloads page, the item named Pre-built Packages.<\/p>\n<p>Using the library in a python script will require the following import statement:<\/p>\n<p>from gps import *<\/p>\n<p>You can download an example here:<\/p>\n<p><a href=\"https:\/\/www.multitech.net\/developer\/wp-content\/uploads\/2022\/05\/testgps.txt\">testgps.txt<\/a><\/p>\n<p><strong>Note:<\/strong>\u00a0You need to rename\u00a0 the file as testgps.py.<\/p>\n<p>Output of testgps.py:<\/p>\n<pre class=\"brush:shell\">$ testgps.py\r\nfix\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a03\r\nlongitude\u00a0\u00a0\u00a0\u00a0-93.196113443\r\nlatitude\u00a0\u00a0\u00a0\u00a0 45.099362019\r\ntime utc\u00a0\u00a0\u00a0\u00a0 2017-11-28T20:41:00.000Z\r\naltitude\u00a0\u00a0\u00a0\u00a0 285.846\r\nepv\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a08.74\r\nept\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a00.005\r\nspeed\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a00.101\r\nclimb\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0-0.025\r\n\r\nSatellites (total of 14\u00a0\u00a0in view)\r\nPRN:\u00a0\u00a0 1\u00a0\u00a0E:\u00a0\u00a018\u00a0\u00a0Az: 319\u00a0\u00a0Ss:\u00a0\u00a037\u00a0\u00a0Used: y\r\nPRN:\u00a0\u00a010\u00a0\u00a0E:\u00a0\u00a067\u00a0\u00a0Az: 117\u00a0\u00a0Ss:\u00a0\u00a023\u00a0\u00a0Used: n\r\nPRN:\u00a0\u00a011\u00a0\u00a0E:\u00a0\u00a019\u00a0\u00a0Az: 303\u00a0\u00a0Ss:\u00a0\u00a036\u00a0\u00a0Used: y\r\nPRN:\u00a0\u00a012\u00a0\u00a0E:\u00a0\u00a018\u00a0\u00a0Az:\u00a0\u00a079\u00a0\u00a0Ss:\u00a0\u00a016\u00a0\u00a0Used: n\r\nPRN:\u00a0\u00a014\u00a0\u00a0E:\u00a0\u00a059\u00a0\u00a0Az: 268\u00a0\u00a0Ss:\u00a0\u00a045\u00a0\u00a0Used: y\r\nPRN:\u00a0\u00a018\u00a0\u00a0E:\u00a0\u00a035\u00a0\u00a0Az: 125\u00a0\u00a0Ss:\u00a0\u00a017\u00a0\u00a0Used: n\r\nPRN:\u00a0\u00a022\u00a0\u00a0E:\u00a0\u00a0 5\u00a0\u00a0Az: 303\u00a0\u00a0Ss:\u00a0\u00a026\u00a0\u00a0Used: n\r\nPRN:\u00a0\u00a024\u00a0\u00a0E:\u00a0\u00a020\u00a0\u00a0Az:\u00a0\u00a046\u00a0\u00a0Ss:\u00a0\u00a021\u00a0\u00a0Used: y\r\nPRN:\u00a0\u00a025\u00a0\u00a0E:\u00a0\u00a015\u00a0\u00a0Az: 117\u00a0\u00a0Ss:\u00a0\u00a021\u00a0\u00a0Used: n\r\nPRN:\u00a0\u00a031\u00a0\u00a0E:\u00a0\u00a025\u00a0\u00a0Az: 197\u00a0\u00a0Ss:\u00a0\u00a038\u00a0\u00a0Used: y\r\nPRN:\u00a0\u00a032\u00a0\u00a0E:\u00a0\u00a076\u00a0\u00a0Az: 305\u00a0\u00a0Ss:\u00a0\u00a041\u00a0\u00a0Used: y\r\nPRN: 131\u00a0\u00a0E:\u00a0\u00a033\u00a0\u00a0Az: 212\u00a0\u00a0Ss:\u00a0\u00a040\u00a0\u00a0Used: n\r\nPRN: 135\u00a0\u00a0E:\u00a0\u00a025\u00a0\u00a0Az: 230\u00a0\u00a0Ss:\u00a0\u00a037\u00a0\u00a0Used: y\r\nPRN: 138\u00a0\u00a0E:\u00a0\u00a036\u00a0\u00a0Az: 200\u00a0\u00a0Ss:\u00a0\u00a036\u00a0\u00a0Used: y<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"brush:shell\"><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px;\">\u00a0<\/span><\/pre>\n<p>There is a gpsd library for C++, C, Java, and perl.\u00a0 For more information see:<\/p>\n<p><a href=\"http:\/\/catb.org\/gpsd\/client-howto.html\" target=\"_blank\">http:\/\/catb.org\/gpsd\/client-howto.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This feature is only available on certain products and models (not available with all devices). NOTE:\u00a0Prior to mLinux\u2122\/AEP 5.0.0 gpsd usage of the GPS was not compatible with lora-packet-forwarder. It was not possible to use the Multitech supplied Lora-Packet-Forwarder with the GNSS port, and GPSD at the same time. This was fixed in the 5.0.0 [&hellip;]<\/p>\n","protected":false},"author":1478,"featured_media":0,"parent":9184,"menu_order":11,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-16518","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/16518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/users\/1478"}],"replies":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/comments?post=16518"}],"version-history":[{"count":64,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/16518\/revisions"}],"predecessor-version":[{"id":32738,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/16518\/revisions\/32738"}],"up":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/9184"}],"wp:attachment":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/media?parent=16518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}