Advertisement / Annons:
7: Setup GPSD
As told earlier, correct time and observatory location is important to get star positioning working correct. When having the astro equipment as a portable unit you get new coordinates whenever you change your location. The time is not correct either because there is no battery backup of the clock in the Raspberry. When on a stationary place and have access to internet there is no need for a GPS device, Astroberry will find correct time and location from internet. There are two ways to fix this when there is no internet connection, either through the GPS in the smartphone or with a GPS dongle connected to the Raspberry.
He is how to setup with a GPS dongle connected to the Raspberry with the driver GPSD. This the most difficult to setup but when it works it's very useful. I have got a lot of help of my friend and from INDI forum.
There are ten very important steps to get it to work:
I already have a GPS dongle and would like to use it for this purpose. Here are others instructions how to setup GPSD:
I never got this setup to work that easy with the instruction above. Maybe my GPS dongle is too old. In Raspberry / Astroberry this is handled by the GPSD driver.
1, Find the port that the GPS is connected to:
Open the commando window, from here you can type in commands, it looks like an old DOS system. The commando windows icon is on the top list. I have collected the most common commands on a page here: Good to know commands.
There is no need to have the KStars and Ekos up and running during this setup other when doing test.
Give this command:
Maybe it ask for the password, it's 'astroberry' if you didn't change anything in the setup.
In the command window of Raspberry it list all tty devices ports. I expect the GPS dongle to show up in this list later, but it's not connected yet:
I connect the USB dongle to a USB port on the HUB that is connected to Raspberry. It's important to always use the same port, I have set a label on the HUB to not mix these devices.
I gave the same command once again:
Now a new port has appeared, the port with "/dev/ttyUSB1" as its device name on the last line. Now I know where my GPS dongle is connected. Make a note of it, you need it later.
2, A first test with GPSD INDI Control Panel:
Before doing any changes it's vice to do a test, maybe it configured itself, but don't expect that :-)
Start KStars and Ekos, go to the Indi Control Panel. Example of how it could look at the setup of GPSD. When clicking on the GPS refresh button it looks that it receive information from the GPS dongle, but it work as well even when the GPS dongle is indoors with no reception. If it has real contact with the GPS dongle it will change the location with small amounts sometimes when you click the Refresh button. Here it take the information from a local site on internet or locally what's stored on the Raspberry. The default Geographic Location setup I did at the installation of Astroberry, look at point 6 on this page. This is because it's setup to Virtual GPS mode as default and that must be disabled in the GPSD setup properly.
One more test, open the commando windows once again if it isn't already open.
From the terminal window give this command:
Quit with: "Ctrl C".
Even here it could look as if it's connected to the GPS dongle. If it's receiving a satellite signal you will see them in the column to the right, here it's empty because it use Virtual GPS and it's connected to a LAN network.
3, Disable Virtual GPS:
This is important. When using a GPS device you must stop the Virtual GPS. If not, the Virtual GPS take over and it doesn't listen to the real GPS signal. The Virtual GPS take the information through internet and will not work without an internet connection.
These two commands disable and stop Virtual GPS:
Now the GPSD driver must be stopped and restarted.
The GPSD service must be stopped and restarted. Give the following commands:
This command should work also:
Open the GPS window in the commando window.
Give the command:
Now there are no location from Virtual GPS anymore, it's empty. The GPS dongle is active now but normally no data coming yet.
You quit the GPS window with: "Ctrl C".
4, Set GPS device to NMEA protocol:
There were no satellite data in the window above because the GPS dongle is not setup correctly, it must be in NMEA mode, not binary.
When I used this GPS dongle in my earlier Windows system there was a software to run to setup the GPS, one of the setups was if it should send data with the NMEA standard, sort of ASCII text. My friend found how to do the same in Linux, these two commands are needed:
There is a way to listen to the data traffic on the port but you need to install a tool for it, screen.
You don't need to do this test normally, I just show you how it looks.
With this command you can listen on the USB port:
If the GPS dongle is in the NMEA mode text strings shall be received and show up on the screen like this.
You quit the data stream with: "Ctrl a" k y.
Execute the command once again:
Now all GPS satellite data show up in the right column and you get the correct location for your place.
You quit the GPS window with: "Ctrl C".
5a, Direct ID to a given port:
It could be a problem that the GPS doesn't always connect to the same port, there is a way to lock it. With the information I got earlier I can now setup this.
Give this command:
Now I have to change the information in this file with my device name. With "Ctrl K" it's possible to edit the information in the window above. You can't use the mouse, use the arrows on the key board. Set the parameters to the port you found in the beginning of this page. In my case it was: ttyUSB1.
GPSD_OPTIONS="-n", this is important later when setup Chrony, normally it's already correct.
When you stop the process with "Ctrl X" it will ask if you want to save it (y=yes).
A check that everything went okay.
Quit with "Ctrl X".
5b, Direct Path to a given port:
The above procedure wasn't without problems, here is an alternative.
Open the map: /dev/serial/by-path, where the file is that has the path ttyUSB1 (in this case it has changed to ttyUSB0). Right click on the files one by one until you find the correct file and choose properties. The information in the yellow circle is what we shall use, copy it, be careful to get the whole string, it's longer than the window's length.
In commando window, give the command:
Replace the DEVICES="" with the path name from above. Edit with: "Ctrl K". You can't use the mouse, use the arrows on the key board. The idea is to have it always found correct port even if the device numbers are changed. If it works ? Who knows ? It's complicated !
Quit with "Ctrl X" and save.
6, Change Geographic Location:
If the GPS receiver fails it's good if the Raspberry's base setting is correct set for your location as a backup.
You find it at: Preferences > Geographic Location.
I set the location with no decimals, then it's easy for me to see what source the position use, when receiving GPS signal it always gives decimals.
7, Setup how to use GPS data in INDI:
In INDI it can be setup from which source the location and clock updates from. In this case it's setup to use the GPS as a source. But with latest changes with Chrony maybe the first alternative is better "KStars updates all devices" because Chrony set the system clock with GPS data.
8, Setup Chrony:
From Astroberry version 2.0.1 it use the Chrony to sync the system clock with GPS data. Much easier now to get it to work. Earlier if the system clock was wrong and only KStars is set with correct time it uses an offset to the system clock. That's fine for the most thing you do. But when doing Polar Alignment I got a lot of problem, I think it use the system clock direct and don't correct with the offset. I setup up Chrony to set the system clock to get rid of this problem. I found that I have to use a driver called Chrony, but then I got stuck and needed help from my friend.
My friend are working on this and have an idea, the following command get the GPS to set the date and time.
Be sure to have Astroberry updated to latest version.
- Install gpsd and chrony with:
Most times nothing will be done because your system is already up to date.
- Modify GPSD_OPTIONS in the file /etc/default/gpsd to be:
Use the sudo nano to start the text editor in commando window:
The "-n" set it to send data repeatedly, chrony need it to work and it's very important.
Edit the file /etc/chrony/chrony.conf according to this:
Remove the # at the beginning of the line.
How to do it: In commando window, give the command:
Sudo nano start a text editor. Copy and past the command above, right click and past. You can't use the mouse, use the arrows on the key board.
Quit with "Ctrl X" and save.
Test if synched:
Test if it's synced, in the commando window:
This is what I got, but not finished yet, more testing to do. After a while I got this:
Only the first line is important, the other four lines comes from internet because it's connected to internet. If the GPS work it should have some figures for the time, if 0 something is wrong.
9, Restart GPSD and KStars/Ekos:
Sometimes when starting up the system the GPSD driver doesn't start as it should. To fix that, shut down EKOS and KStars. Open the commando window and type in this command:
Commands that are used often can be setup as a script, look here how to do it: Good to know commands, at bottom of page.
After the GPSD has been restarted it's time to start KStars and activate Ekos with its drivers.
Click on the Refresh GPS button, if it's connected to the GPS dongle it sometimes changes the decimals of the Location Lat/Lon. You must have a free view to the sky for the GPS receiver and it could take some minutes the first time for it to lock to the satellites. At the KStars lower left corner you will see that it take the location from GPS.
10, Set time and date manually:
Out on the field, I tested it many times now and it works like a charm most times. If it fail the time and date must be set manually with a sudo command:
Set date and time: (example: "2023-04-06 20:10:00", April 6th)
After this, refresh the GPS and the time will be exactly correct. I normally do like this, before I go out in the night I start my system at home with a connected LAN cable and internet access, then it update date, time and location. It will remember the last date it was up and running and you don't have to update the date out on the field.