Skip to content

Commit

Permalink
Correction to lat and long calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
djaus2 committed Aug 23, 2023
1 parent 9ceef38 commit c2c298d
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 39 deletions.
21 changes: 13 additions & 8 deletions Azure_IoT_Hub_GPS/Azure_IoT_Hub_GPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ void split(String string)
}
}

// NMEA latt,long values ar 100x so just shift decimal point left 2 in the string
// Could convert to double then divide by 100 but want as string
// THE FOLLOWING HAS BEEN UPDATED (CORRECTED):
//See https://davidjones.sportronics.com.au/web/GPS-NMEA_101-web.html
String ShiftLeft2(String num)
{
for (int i = 0; i < num.length(); ++i)
Expand All @@ -522,10 +522,15 @@ String ShiftLeft2(String num)

if (c == '.')
{
num[i] = num[i-1];
num[i-1] =num[i-2];
num[i-2] = '.';
return num;
String degrees = num.substring(0,i-2);
double deg = degrees.toDouble();
String part = num.substring(i-2);
double dPart = part.toDouble();
double sixty = 60.0;
dPart = dPart /sixty;
deg += dPart;
String degrees2 = String(deg,7);
return degrees2;
}
}
return "Error";
Expand Down Expand Up @@ -618,7 +623,7 @@ void GetGPS()
{
// Telemetry
split(nmea);
json = "{\"geolocation\":{";
json = "{";
json += "\"lat\":";
if(strings[lattIndex+1]=="S")
{
Expand All @@ -636,7 +641,7 @@ void GetGPS()
json += "\"alt\":";
json += strings[heightIndex];
//json += strings[heightIndex+1];
json += "}}";
json += "}";
result = json;
}
}
Expand Down
12 changes: 6 additions & 6 deletions Azure_IoT_Hub_GPS/iot_configs.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT

#define IOT_CONFIG_WIFI_SSID "APQLZM"
#define IOT_CONFIG_WIFI_PASSWORD "silly1371"
#define IOT_CONFIG_WIFI_SSID "<SSID>"
#define IOT_CONFIG_WIFI_PASSWORD "<SSIDPWD>"

// Azure IoT
#define IOT_CONFIG_IOTHUB_FQDN "AzPicoGPDHub1.azure-devices.net"
#define IOT_CONFIG_DEVICE_ID "azpicogpsdev1"
#define IOT_CONFIG_DEVICE_KEY "sS6VTMfqcoyePD2ohYOItPJTfvs3RCKaLQIWsNEwCcE="
#define IOT_CONFIG_IOTHUB_FQDN <"HUB PATH>"
#define IOT_CONFIG_DEVICE_ID "<DEVICEID>>"
#define IOT_CONFIG_DEVICE_KEY "<DEVICE KEY>"


// Publish 1 message every 2 seconds
#define TELEMETRY_FREQUENCY_MILLISECS 2000
#define TELEMETRY_FREQUENCY_MILLISECS 10000
18 changes: 11 additions & 7 deletions BluetoothGPS/BluetoothGPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ void split(String string)
}
}

// NMEA latt,long values ar 100x so just shift decimal point left 2 in the string
// Could convert to double then divide by 100 but want as string
// THE FOLLOWING HAS BEEN UPDATED (CORRECTED):
//See https://davidjones.sportronics.com.au/web/GPS-NMEA_101-web.html
String ShiftLeft2(String num)
{
for (int i = 0; i < num.length(); ++i)
Expand All @@ -105,16 +105,20 @@ String ShiftLeft2(String num)

if (c == '.')
{
num[i] = num[i-1];
num[i-1] =num[i-2];
num[i-2] = '.';
return num;
String degrees = num.substring(0,i-2);
double deg = degrees.toDouble();
String part = num.substring(i-2);
double dPart = part.toDouble();
double sixty = 60.0;
dPart = dPart /sixty;
deg += dPart;
String degrees2 = String(deg,7);
return degrees2;
}
}
return "Error";
}


void loop() {

if (SerialBT.available())
Expand Down
23 changes: 16 additions & 7 deletions LocationGPS/LocationGPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ void setup() {
Serial2.setTX(TXD2);
Serial2.begin(9600);
Serial.begin(9600);
while(!Serial);
delay(1000);
while(!Serial2);
}

#define bufferIndexMax 12
Expand Down Expand Up @@ -85,8 +87,8 @@ void split(String string)
}
}

// NMEA latt,long values ar 100x so just shift decimal point left 2 in the string
// Could convert to double then divide by 100 but want as string
// THE FOLLOWING HAS BEEN UPDATED (CORRECTED):
//See https://davidjones.sportronics.com.au/web/GPS-NMEA_101-web.html
String ShiftLeft2(String num)
{
for (int i = 0; i < num.length(); ++i)
Expand All @@ -95,10 +97,15 @@ String ShiftLeft2(String num)

if (c == '.')
{
num[i] = num[i-1];
num[i-1] =num[i-2];
num[i-2] = '.';
return num;
String degrees = num.substring(0,i-2);
double deg = degrees.toDouble();
String part = num.substring(i-2);
double dPart = part.toDouble();
double sixty = 60.0;
dPart = dPart /sixty;
deg += dPart;
String degrees2 = String(deg,7);
return degrees2;
}
}
return "Error";
Expand Down Expand Up @@ -281,9 +288,11 @@ void loop() {

if(run)
{
GetNMEASentence();
GetNMEASentence();;
if (result.length() >0)
{
Serial.println(result);
}
}
}

Expand Down
25 changes: 22 additions & 3 deletions USART1Echo/USART1Echo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,39 @@ void setup() {
Serial2.begin(9600);
Serial.begin(9600);
delay(1000);
while(!Serial){};
Serial.println("Started 1");
while(!Serial2){};
Serial.println("Started 2");
}

void loop() {
if (Serial.available())
{
Serial2.write(Serial.read();


Serial2.write(Serial.read());
/*
if (!Serial2.available())
{
}
while(Serial2.available())
{
char c1 = Serial2.read();
Serial.write(c1);
};
};*/
}
if (Serial2.available())
{

Serial.write(Serial2.read());
/*
if (!Serial2.available())
{
}
while(Serial2.available())
{
char c1 = Serial2.read();
Serial.write(c1);
};*/
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = ".NET Core 3.1")]
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("read-d2c-messages")]
[assembly: System.Reflection.AssemblyCompanyAttribute("read-d2c-Messages-Net6")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("read-d2c-messages")]
[assembly: System.Reflection.AssemblyTitleAttribute("read-d2c-messages")]
[assembly: System.Reflection.AssemblyProductAttribute("read-d2c-Messages-Net6")]
[assembly: System.Reflection.AssemblyTitleAttribute("read-d2c-Messages-Net6")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fa45f9b7ee6e127a2de2ecb0ec05441354260657
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = read-d2c-Messages-Net6
build_property.ProjectDir = c:\Users\david\Documents\Arduino\RPIPicoWGPSandBT\read-d2c-messages-Net6\
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

0 comments on commit c2c298d

Please sign in to comment.