From b27bc945430cd8ebbf9e216da01fd7051c626b1b Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 14 Sep 2024 16:19:09 -0700 Subject: [PATCH] lr1110: added script to eval position using LoRaCloud --- .../LR11x0_Gnss_Scan/LR11x0_Gnss_Scan.ino | 47 ++++++-- examples/LR11x0/LR11x0_Gnss_Scan/README.md | 67 ++++++++---- .../LR11x0/LR11x0_Gnss_Scan/location-sample.h | 4 + .../LR11x0/LR11x0_Gnss_Scan/lora-cloud.sample | 4 + .../LR11x0/LR11x0_Gnss_Scan/lora-cloud.sh | 103 ++++++++++++++++++ src/modules/LR11x0/LR11x0.cpp | 3 +- 6 files changed, 198 insertions(+), 30 deletions(-) create mode 100644 examples/LR11x0/LR11x0_Gnss_Scan/location-sample.h create mode 100644 examples/LR11x0/LR11x0_Gnss_Scan/lora-cloud.sample create mode 100755 examples/LR11x0/LR11x0_Gnss_Scan/lora-cloud.sh diff --git a/examples/LR11x0/LR11x0_Gnss_Scan/LR11x0_Gnss_Scan.ino b/examples/LR11x0/LR11x0_Gnss_Scan/LR11x0_Gnss_Scan.ino index 45bbca1ed..91ddf364a 100644 --- a/examples/LR11x0/LR11x0_Gnss_Scan/LR11x0_Gnss_Scan.ino +++ b/examples/LR11x0/LR11x0_Gnss_Scan/LR11x0_Gnss_Scan.ino @@ -1,10 +1,7 @@ // Semtech LR11x0 GNSS scanner, by Thorsten von Eicken, derived from WiFi scanner example // The configuration is for a Seeed WIO Tracker 1110 dev board (red) #include - -// Real position of GPS in order to calculate real error (assumes stationary GPS) -#define REAL_LAT (34.499360) -#define REAL_LON (-119.818190) +#include "location.h" // From https://github.com/jgromes/RadioLib/discussions/1101#discussioncomment-9576099 // cs, irq, rst busy @@ -139,7 +136,6 @@ void printPowerInfo(uint32_t *timing, uint8_t constDemod) { // ===== Geographic distance float haversine(float lat1, float lon1, float lat2, float lon2) { // radians -> meters - constexpr float r = 6371; // km float avgLat = sin((lat1-lat2)/2); float avgLon = sin((lon1-lon2)/2); float a = avgLat*avgLat + cos(lat1)*cos(lat2)*avgLon*avgLon; @@ -150,6 +146,7 @@ float haversine(float lat1, float lon1, float lat2, float lon2) { // radians -> bool startScan; // time to start next scan volatile bool scanFlag = false; // scan completed flag +uint32_t scanStartAt = 0; // millis() when starting scan void configRadio() { Serial.println(F("\n[LR1110] Initializing ... ")); @@ -234,10 +231,10 @@ void loop() { return; } - // ===== Print various information about the scan - + // see whether we have the time uint8_t timeErr; uint32_t gpsTime, nbUs, timeAcc; + uint32_t gotTimeAt = millis(); state = radio.gnssReadTime(&timeErr, &gpsTime, &nbUs, &timeAcc); if (state == RADIOLIB_ERR_NONE) { if (timeErr == 0) { @@ -249,6 +246,41 @@ void loop() { } } + uint16_t rsize=0; + state = radio.gnssGetResultSize(&rsize); + if (state == RADIOLIB_ERR_NONE && rsize > 0) { + uint8_t *buf = (uint8_t *)calloc(rsize, 1); + state = radio.gnssReadResults(buf, rsize); // handles buf==nullptr + if (state == RADIOLIB_ERR_NONE) { + switch (buf[0]) { + case 1: + if (timeErr == 0 && timeAcc < 2000000) { + // we got reasonably accurate time info, include in printf + // adjust to start of scan with 1s fudget, LoRaCloud is not explicit when to measure + // and this seems to get very close to the time it ends up reporting + uint32_t adjTime = gpsTime - (gotTimeAt-scanStartAt)/1000 + 1; + printf("NAV @%d: ", adjTime); + } else { + printf("NAV: "); + } + for (int i=1; i