Fixes to basic functionality, debug added
This commit contains a lot of basic fixes (basic string stuff, that couldn't be tested without a working server before) and adds debug messages.
This commit is contained in:
parent
20159cb27c
commit
ef0845096e
|
|
@ -4,7 +4,7 @@
|
|||
#include <QMC5883LCompass.h>
|
||||
#include "wifi_save.h"
|
||||
#include <HTTPClient.h>
|
||||
#include <Arduino_JSON.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
|
||||
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE); // if you use Hardware I2C port, full framebuffer, size = 1024 bytes
|
||||
|
|
@ -19,7 +19,7 @@ QMC5883LCompass compass;
|
|||
|
||||
#define GPS_BAUD 9600
|
||||
|
||||
String webserviceAddress = "http://192.168.179.2:65133/updateGPS";
|
||||
String webserviceAddress = "https://festival-finder.noe-danke.de/updateGPS";
|
||||
bool connected = false;
|
||||
|
||||
HardwareSerial gpsSerial(2);
|
||||
|
|
@ -49,67 +49,63 @@ void setup(void) {
|
|||
|
||||
Serial.begin(115200);
|
||||
|
||||
if (wifi_set_main())
|
||||
{
|
||||
Serial.println("Connect WIFI SUCCESS");
|
||||
connected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Connect WIFI FAULT");
|
||||
if (wifi_set_main()) {
|
||||
Serial.println("Connect WIFI SUCCESS");
|
||||
connected = true;
|
||||
} else {
|
||||
Serial.println("Connect WIFI FAULT");
|
||||
}
|
||||
|
||||
compass.init();
|
||||
compass.init();
|
||||
|
||||
u8g2.begin(); // start a display.
|
||||
gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2);
|
||||
Serial.println("Serial 2 started at 9600 baud rate");
|
||||
|
||||
}
|
||||
|
||||
void drawTriangles(byte i, char* time, char* distanceString) {
|
||||
void drawTriangles(byte i, char *time, char *distanceString) {
|
||||
u8g2.clearBuffer();
|
||||
u8g2.drawTriangle(triangles[i][0], triangles[i][1], triangles[i][2], triangles[i][3], triangles[i][4], triangles[i][5]);
|
||||
u8g2.sendBuffer();
|
||||
u8g2.setFont(u8g2_font_helvR08_tr);
|
||||
u8g2.drawButtonUTF8(48, 64-40, U8G2_BTN_BW0, 0, 0, 0, "Last Update:");
|
||||
u8g2.drawButtonUTF8(48, 64-30, U8G2_BTN_BW0, 0, 0, 0, time);
|
||||
u8g2.drawButtonUTF8(48, 64-16, U8G2_BTN_BW0, 0, 0, 0, distanceString);
|
||||
u8g2.drawButtonUTF8(48, 64 - 40, U8G2_BTN_BW0, 0, 0, 0, "Last Update:");
|
||||
u8g2.drawButtonUTF8(48, 64 - 30, U8G2_BTN_BW0, 0, 0, 0, time);
|
||||
u8g2.drawButtonUTF8(48, 64 - 16, U8G2_BTN_BW0, 0, 0, 0, distanceString);
|
||||
u8g2.sendBuffer();
|
||||
delay(2000);
|
||||
|
||||
}
|
||||
|
||||
bool doHttpRequest(const char* payload, char* latitude, char* longitude, char* gpsTime) {
|
||||
HTTPClient http;
|
||||
// Change space to 0
|
||||
*(latitude + 6) = 0;
|
||||
bool doHttpRequest(char *payload, char *latitude, char *longitude, char *gpsTime) {
|
||||
HTTPClient http;
|
||||
// Change space to 0
|
||||
*(latitude + 6) = '0';
|
||||
|
||||
String serverPath = webserviceAddress + "?long=" + *longitude + "&lat=" + *latitude + "&id=" + OWN_ID + "&req_id=" + REQ_ID + "&gpsDateTime=" + *gpsTime;
|
||||
String serverPath = webserviceAddress + "?long=" + longitude + "&lat=" + latitude + "&id=" + OWN_ID + "&req_id=" + REQ_ID + "&gpsDateTime=" + gpsTime;
|
||||
|
||||
Serial.println(serverPath);
|
||||
Serial.println(serverPath);
|
||||
|
||||
// Your Domain name with URL path or IP address with path
|
||||
http.begin(serverPath.c_str());
|
||||
// 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");
|
||||
// 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();
|
||||
// Send HTTP GET request
|
||||
int httpResponseCode = http.GET();
|
||||
|
||||
if (httpResponseCode>0) {
|
||||
Serial.print("HTTP Response code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
payload = http.getString().c_str();
|
||||
Serial.println(payload);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
Serial.print("Error code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
return false;
|
||||
}
|
||||
Serial.print("HTTP Response code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
|
||||
if (httpResponseCode == 200 ) {
|
||||
const char* cpayload = http.getString().c_str();
|
||||
strcpy(payload, cpayload);
|
||||
Serial.println(payload);
|
||||
return true;
|
||||
} else {
|
||||
Serial.print("Error code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
byte calculateBearing(float bearing) {
|
||||
|
|
@ -117,27 +113,40 @@ byte calculateBearing(float bearing) {
|
|||
relativeAngle += 360;
|
||||
relativeAngle %= 360;
|
||||
return compass.getBearing(relativeAngle);
|
||||
|
||||
}
|
||||
void setDistanceBearingString(char *distance, byte *bearing, const char *payload) {
|
||||
JSONVar jsonPayload = JSON.parse(payload);
|
||||
*distance = jsonPayload["dist"];
|
||||
*bearing = calculateBearing(String(jsonPayload["bearing"]).toFloat());
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
DeserializationError error = deserializeJson(doc, payload);
|
||||
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
|
||||
const char* dist2 = doc["distance"];
|
||||
//Serial.println(dist2);
|
||||
Serial.println("JSON stuff:");
|
||||
Serial.println(dist2);
|
||||
|
||||
strcpy(distance, dist2);
|
||||
*bearing = calculateBearing(String(doc["bearing"]).toFloat());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop(void) {
|
||||
while (gpsSerial.available() > 0){
|
||||
while (gpsSerial.available() > 0) {
|
||||
// get the byte data from the GPS
|
||||
char gpsData = gpsSerial.read();
|
||||
|
||||
Serial.print(gpsData);
|
||||
if (gps.encode(gpsData)) {
|
||||
Serial.print(gpsData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
long unsigned date, time, age;
|
||||
char *longitude, *latitude, *dateTime;
|
||||
longitude = gps.get_longitude();
|
||||
|
|
@ -147,40 +156,54 @@ void loop(void) {
|
|||
Serial.println(latitude);
|
||||
Serial.println(longitude);
|
||||
|
||||
const char *myPayloadResponse;
|
||||
char myPayloadResponse[80];
|
||||
|
||||
char timeString[10], dateString[8], dateTimeString[18];
|
||||
char timeString[10], dateString[10], dateTimeString[24];
|
||||
ltoa(time, timeString, 10);
|
||||
ltoa(date, dateString, 8);
|
||||
for (int i = 0; i < 18 ;i++){
|
||||
if(i < 8)
|
||||
dateTimeString[i] = dateString[i];
|
||||
else
|
||||
dateTimeString[i] = timeString[i-8];
|
||||
}
|
||||
ltoa(date, dateString, 10);
|
||||
// for (int i = 0; i < 18; i++) {
|
||||
// if (i < 7) {
|
||||
// dateTimeString[i] = dateString[i];
|
||||
// } else {
|
||||
// dateTimeString[i] = timeString[i - 8];
|
||||
// }
|
||||
// }
|
||||
|
||||
byte triangleIndex = 0;
|
||||
char distanceArray[] = { 'N', 'o', ' ', 'S', 'e', 'r', 'v', 'e', 'r', '\0'};
|
||||
char *distanceString = &(distanceArray[0]);
|
||||
strcpy(dateTimeString, dateString);
|
||||
strcat(dateTimeString, timeString);
|
||||
|
||||
if(doHttpRequest(myPayloadResponse, latitude, longitude, dateTimeString))
|
||||
byte triangleIndex = 0;
|
||||
char distanceArray[] = { 'N', 'o', ' ', 'S', 'e', 'r', 'v', 'e', 'r', '\0' };
|
||||
char distanceString[16];
|
||||
strcpy(distanceString, distanceArray);
|
||||
|
||||
|
||||
|
||||
if (doHttpRequest(myPayloadResponse, latitude, longitude, dateTimeString))
|
||||
setDistanceBearingString(distanceString, &triangleIndex, myPayloadResponse);
|
||||
|
||||
Serial.println();
|
||||
Serial.println("Time: ");
|
||||
Serial.println(time);
|
||||
Serial.println("TimeString: ");
|
||||
Serial.println(timeString);
|
||||
Serial.println("DateString: ");
|
||||
Serial.println(dateString);
|
||||
Serial.println("Date: ");
|
||||
Serial.println(date);
|
||||
Serial.println(dateString);
|
||||
Serial.println("DateTime: ");
|
||||
Serial.println(dateTimeString);
|
||||
Serial.println("DistanceString: ");
|
||||
Serial.println(distanceString);
|
||||
|
||||
|
||||
drawTriangles(triangleIndex, timeString, distanceString);
|
||||
|
||||
Serial.println("-------------------------------");
|
||||
int a;
|
||||
int a;
|
||||
compass.read();
|
||||
|
||||
//Calculate heading
|
||||
a = compass.getAzimuth();
|
||||
float heading = compass.getBearing(a);
|
||||
float heading = compass.getBearing(a);
|
||||
char myArray[3];
|
||||
compass.getDirection(myArray, a);
|
||||
|
||||
|
|
@ -193,5 +216,5 @@ void loop(void) {
|
|||
Serial.println();
|
||||
Serial.println("-------------------------------");
|
||||
|
||||
delay(1000);
|
||||
delay(5000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user