-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Can I connect to Polaris NTRIP using UrlHttpConnection from Java/Kotlin? #62
Comments
@Ba0Nguyen - the import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.Base64;
public class NtripClient {
public static void main(String[] args) {
// Read environmental variables
String ntripCasterHost = System.getenv("NTRIP_CASTER_HOST");
String ntripCasterPort = System.getenv("NTRIP_CASTER_PORT");
String ntripMountPoint = System.getenv("NTRIP_MOUNT_POINT");
String username = System.getenv("NTRIP_USERNAME");
String password = System.getenv("NTRIP_PASSWORD");
String latitudeStr = System.getenv("LATITUDE");
String longitudeStr = System.getenv("LONGITUDE");
if (ntripCasterHost == null || ntripCasterPort == null || ntripMountPoint == null || username == null || password == null || latitudeStr == null || longitudeStr == null) {
System.err.println("Environmental variables NTRIP_CASTER_HOST, NTRIP_CASTER_PORT, NTRIP_MOUNT_POINT, NTRIP_USERNAME, NTRIP_PASSWORD, LATITUDE, and LONGITUDE must be set.");
return;
}
int port = Integer.parseInt(ntripCasterPort);
double latitude = Double.parseDouble(latitudeStr);
double longitude = Double.parseDouble(longitudeStr);
try {
// Create a socket connection to the NTRIP caster
Socket socket = new Socket(ntripCasterHost, port);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
// Send NTRIP request
String auth = username + ":" + password;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
writer.write("GET /" + ntripMountPoint + " HTTP/1.1\r\n");
writer.write("Host: " + ntripCasterHost + "\r\n");
writer.write("Ntrip-Version: Ntrip/2.0\r\n");
writer.write("User-Agent: NTRIP NtripClient\r\n");
writer.write("Authorization: Basic " + encodedAuth + "\r\n");
writer.write("\r\n");
writer.flush();
// Create and send GGA message
String ggaMessage = createGgaMessage(latitude, longitude);
System.out.println("Sending GGA message: " + ggaMessage.trim()); // Debug line
writer.write(ggaMessage);
writer.flush();
// Read response header
String responseLine;
while ((responseLine = reader.readLine()) != null && !responseLine.isEmpty()) {
System.out.println(responseLine);
}
// Read GNSS correction data
InputStream inputStream = socket.getInputStream();
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
// Output the binary data
for (int i = 0; i < bytesRead; i++) {
System.out.printf("%02x ", buffer[i]);
}
System.out.println();
}
// Close the streams
reader.close();
writer.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static String createGgaMessage(double latitude, double longitude) {
String latDirection = latitude >= 0 ? "N" : "S";
String lonDirection = longitude >= 0 ? "E" : "W";
latitude = Math.abs(latitude);
longitude = Math.abs(longitude);
int latDegrees = (int) latitude;
double latMinutes = (latitude - latDegrees) * 60.0;
int lonDegrees = (int) longitude;
double lonMinutes = (longitude - lonDegrees) * 60.0;
String gga = String.format(
"$GPGGA,123519,%02d%07.4f,%s,%03d%07.4f,%s,1,08,0.9,545.4,M,46.9,M,,",
latDegrees, latMinutes, latDirection, lonDegrees, lonMinutes, lonDirection
);
String checksum = calculateChecksum(gga);
return gga + "*" + checksum + "\r\n";
}
private static String calculateChecksum(String sentence) {
int checksum = 0;
for (int i = 1; i < sentence.length(); i++) {
checksum ^= sentence.charAt(i);
}
return String.format("%02X", checksum);
}
}
This will run on its own and print out the correction data as bytes. I tested this with the following ENV variables
Hope this helps! |
Thanks for the help @mkurdziel , |
I was able to forward RTCM data to my drone, can you direct me to how I can achieve 1cm accuracy? Do I have to update my position a certain way to achieve that? Does the mount point I am using support 1cm accuracy? I've tried mount point POLARIS_LOCAL and is getting 4cm accuracy. I also noticed that if I start to move to drone, accuracy can get worse. |
Hi, I wanted to follow up on my previous question. Do you have any suggestion how I can achieve 1cm accuracy? I was able to connect to POLARIS Network but my accuracy is about 10 cm. Thanks. |
How are you measuring accuracy? The values reported by the receiver are only estimates, you'd need a benchmark to single centimeters. What gps are you using?
**
*Aaron Nathan*
Founder & CEO
m: 201.914.1483
pointonenav.com ( http://pointonenav.com/ )
…On Fri, Sep 13 2024 at 7:04 PM, Ba0Nguyen < ***@***.*** > wrote:
Hi, I wanted to follow up on my previous question. Do you have any
suggestion how I can achieve 1cm accuracy? I was able to connect to
POLARIS Network but my accuracy is about 10 cm. Thanks.
—
Reply to this email directly, view it on GitHub (
#62 (comment) )
, or unsubscribe (
https://github.com/notifications/unsubscribe-auth/AAG652C3OL36VV3REMWPNZLZWMLK3AVCNFSM6AAAAABKZNPIWKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBZGQ3DANBSHE
).
You are receiving this because you are subscribed to this thread. Message
ID: <PointOneNav/polaris/issues/62/2349460429 @ github. com>
|
`
val urlString = "https://polaris.pointonenav.com:2101\n"
`
I used to code above to attempt to connect to Polaris NTRIP Server but failed to do so. Do I need any header or sending initial message to connect with Polaris NTRIP ?
The text was updated successfully, but these errors were encountered: