Send azimuth + configurable bearing correction
From this change on, the client adds its azimuth measurement to the get paramters, so the server can do the correction. Also the response parameter for locally correcting bearing according to azimuth measurements is respected. Some comments from copy paste stuff were deleted.
This commit is contained in:
parent
f37bae70e9
commit
488ad08e38
|
|
@ -17,8 +17,11 @@ QMC5883LCompass compass;
|
|||
#define GPS_BAUD 9600
|
||||
|
||||
String webserviceAddress = "https://festival-finder.noe-danke.de/updateGPS";
|
||||
String serverAvailableAddress = "https://festival-finder.noe-danke.de/";
|
||||
bool connected = false;
|
||||
|
||||
bool use_bearing_correction = true;
|
||||
|
||||
HardwareSerial gpsSerial(2);
|
||||
TinyGPSMinus gps;
|
||||
|
||||
|
|
@ -81,30 +84,21 @@ void drawTriangles(byte i, char *time, char *distanceString) {
|
|||
delay(2000);
|
||||
}
|
||||
|
||||
bool doHttpRequest(char *payload, char *latitude, char *longitude, char *gpsTime) {
|
||||
bool doHttpRequest(char *payload, char *latitude, char *longitude, char *gpsTime, char *az) {
|
||||
HTTPClient http;
|
||||
|
||||
// Change space to 0
|
||||
|
||||
|
||||
if(*(latitude + 6) < '0' || *(latitude + 6) > '9')
|
||||
if(*(latitude + 6) == ' ')
|
||||
*(latitude + 6) = '0';
|
||||
|
||||
String serverPath = webserviceAddress + "?long=" + longitude + "&lat=" + latitude + "&id=" + OWN_ID + "&req_id=" + REQ_ID + "&gpsDateTime=" + gpsTime + "&passkey=" + SERVER_PASSKEY;
|
||||
String serverPath = webserviceAddress + "?long=" + longitude + "&lat=" + latitude + "&id=" + OWN_ID + "&req_id=" + REQ_ID + "&gpsDateTime=" + gpsTime + "&passkey=" + SERVER_PASSKEY + "&az=" + az;
|
||||
|
||||
Serial.println(serverPath);
|
||||
|
||||
// Your Domain name with URL path or IP address with path
|
||||
http.begin(serverPath.c_str());
|
||||
|
||||
// If you need Node-RED/server authentication, insert user and password below
|
||||
//http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");
|
||||
|
||||
// Send HTTP GET request
|
||||
int httpResponseCode = http.GET();
|
||||
|
||||
Serial.print("HTTP Response code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
|
||||
if (httpResponseCode == 200 ) {
|
||||
const char* cpayload = http.getString().c_str();
|
||||
strcpy(payload, cpayload);
|
||||
|
|
@ -117,13 +111,35 @@ bool doHttpRequest(char *payload, char *latitude, char *longitude, char *gpsTime
|
|||
}
|
||||
}
|
||||
|
||||
void checkWifiConnection() {
|
||||
HTTPClient http;
|
||||
http.begin(serverAvailableAddress);
|
||||
int httpResponseCode = http.GET();
|
||||
|
||||
Serial.print("Server availablity test response code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
|
||||
if (httpResponseCode == 200) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
byte calculateBearing(float bearing) {
|
||||
if(!use_bearing_correction) {
|
||||
int iBearing = bearing;
|
||||
return compass.getBearing(iBearing);
|
||||
}
|
||||
|
||||
compass.read();
|
||||
int relativeAngle = (int)(bearing - compass.getAzimuth());
|
||||
relativeAngle += 360;
|
||||
relativeAngle %= 360;
|
||||
return (compass.getBearing(relativeAngle) + BEARING_CORRECTION + 16) % 16;
|
||||
}
|
||||
|
||||
|
||||
void setDistanceBearingString(char *time, char *distance, byte *bearing, const char *payload) {
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
|
|
@ -137,21 +153,18 @@ void setDistanceBearingString(char *time, char *distance, byte *bearing, const c
|
|||
|
||||
const char* dist2 = doc["distance"];
|
||||
const char* time2 = doc["lastUpdateTZ"];
|
||||
use_bearing_correction = doc["bear_correction"];
|
||||
|
||||
strcpy(distance, dist2);
|
||||
strcpy(time, time2);
|
||||
|
||||
*bearing = calculateBearing(String(doc["bearing"]).toFloat());
|
||||
*bearing = calculateBearing(String(doc["azimuth"]).toFloat());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop(void) {
|
||||
if(connected) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
}
|
||||
checkWifiConnection();
|
||||
while (gpsSerial.available() > 0) {
|
||||
// get the byte data from the GPS
|
||||
char gpsData = gpsSerial.read();
|
||||
|
|
@ -171,9 +184,9 @@ void loop(void) {
|
|||
Serial.println(latitude);
|
||||
Serial.println(longitude);
|
||||
|
||||
char myPayloadResponse[80];
|
||||
char myPayloadResponse[128];
|
||||
|
||||
char timeString[10], dateString[10], dateTimeString[24];
|
||||
char timeString[10], dateString[10], dateTimeString[24], azString[11];
|
||||
ltoa(time, timeString, 10);
|
||||
ltoa(date, dateString, 10);
|
||||
// for (int i = 0; i < 18; i++) {
|
||||
|
|
@ -187,6 +200,7 @@ void loop(void) {
|
|||
strcpy(dateTimeString, dateString);
|
||||
strcat(dateTimeString, timeString);
|
||||
|
||||
|
||||
byte triangleIndex = 0;
|
||||
char distanceArray[] = { 'N', 'o', ' ', 'S', 'e', 'r', 'v', 'e', 'r', '\0' };
|
||||
char distanceString[16];
|
||||
|
|
@ -195,14 +209,18 @@ void loop(void) {
|
|||
char remoteTimeString[16];
|
||||
strcpy(remoteTimeString, timeString);
|
||||
|
||||
if (doHttpRequest(myPayloadResponse, latitude, longitude, dateTimeString))
|
||||
compass.read();
|
||||
int az = compass.getAzimuth();
|
||||
sprintf(azString, "%ld", az);
|
||||
|
||||
if (doHttpRequest(myPayloadResponse, latitude, longitude, dateTimeString, azString))
|
||||
setDistanceBearingString(remoteTimeString, distanceString, &triangleIndex, myPayloadResponse);
|
||||
|
||||
drawTriangles(triangleIndex, remoteTimeString, distanceString);
|
||||
|
||||
Serial.println("-------------------------------");
|
||||
|
||||
delay(3000);
|
||||
delay(1000);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user