Skip to content

Commit 56ba645

Browse files
author
Alex Angeletos
committed
Adding Thingstream plan selection to captive portal (settings page)
Updating certs and ztp examples (shortrange and cellular) with thingstream plans (IP and IP+LBAND) Updating LBAND example to fetch and configure NEO-D9S module using Thingstream's frequencies topic
1 parent 0595612 commit 56ba645

File tree

32 files changed

+1115
-215
lines changed

32 files changed

+1115
-215
lines changed
0 Bytes
Binary file not shown.
36 KB
Binary file not shown.
0 Bytes
Binary file not shown.
35.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
35.5 KB
Binary file not shown.

XPLR-HPG-SW/components/hpglib/src/location_service/lband_service/xplr_lband.c

Lines changed: 115 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <stdlib.h>
2424
#include "string.h"
2525
#include "esp_task_wdt.h"
26+
#include "cJSON.h"
2627
#include "xplr_lband.h"
2728
#include "./../../../components/hpglib/src/common/xplr_common.h"
2829

@@ -39,6 +40,9 @@
3940
#define XPLRLBAND_CONSOLE(message, ...) do{} while(0)
4041
#endif
4142

43+
#define XPLRLBAND_FREQ_REGION_EU "eu"
44+
#define XPLRLBAND_FREQ_REGION_US "us"
45+
4246
/* ----------------------------------------------------------------
4347
* STATIC TYPES
4448
* -------------------------------------------------------------- */
@@ -83,6 +87,11 @@ typedef struct xplrLband_type {
8387
* STATIC VARIABLES
8488
* -------------------------------------------------------------- */
8589

90+
static const char *freqRegions[] = {
91+
XPLRLBAND_FREQ_REGION_EU,
92+
XPLRLBAND_FREQ_REGION_US
93+
};
94+
8695
static xplrLband_t lbandDvcs[XPLRLBAND_NUMOF_DEVICES] = {NULL};
8796
static int32_t ubxRet;
8897
static int32_t espRet;
@@ -97,6 +106,10 @@ static esp_err_t xplrLbandPrivateConfigAllDefault(uint8_t dvcProfile, uint8_t i2
97106
static esp_err_t xplrLbandPrivateSetDeviceConfig(uint8_t dvcProfile, uDeviceCfg_t *deviceSettings);
98107
static esp_err_t xplrLbandPrivateSetNetworkConfig(uint8_t dvcProfile, uNetworkCfgGnss_t *deviceNetwork);
99108
static int32_t xplrLbandPrivateAsyncStopper(uint8_t dvcProfile, int32_t handler);
109+
static esp_err_t xplrLbandParseFrequencyFromMqtt(uint8_t dvcProfile,
110+
char *mqttPayload,
111+
xplrLbandRegion region,
112+
uint32_t *parsedFrequency);
100113

101114
/* ----------------------------------------------------------------
102115
* STATIC CALLBACK FUNCTION PROTOTYPES
@@ -122,8 +135,7 @@ esp_err_t xplrLbandUbxlibDeinit(void)
122135
}
123136

124137
esp_err_t xplrLbandStartDeviceDefaultSettings(uint8_t dvcProfile,
125-
uint8_t i2cAddress,
126-
uint32_t frequency,
138+
uint8_t i2cAddress,
127139
uDeviceHandle_t *destHandler)
128140
{
129141
if (!xplrHlprLocSrvcCheckDvcProfileValidity(dvcProfile, XPLRLBAND_NUMOF_DEVICES)) {
@@ -150,11 +162,6 @@ esp_err_t xplrLbandStartDeviceDefaultSettings(uint8_t dvcProfile,
150162
return espRet;
151163
}
152164

153-
espRet = xplrLbandSetFrequency(dvcProfile, frequency);
154-
if (espRet != ESP_OK) {
155-
return espRet;
156-
}
157-
158165
if (destHandler != NULL) {
159166
espRet = xplrLbandSendCorrectionDataAsyncStart(dvcProfile, destHandler);
160167
if (espRet != ESP_OK) {
@@ -166,8 +173,7 @@ esp_err_t xplrLbandStartDeviceDefaultSettings(uint8_t dvcProfile,
166173
}
167174

168175
esp_err_t xplrLbandStartDevice(uint8_t dvcProfile,
169-
xplrLbandDeviceCfg_t *dvcCfg,
170-
uint32_t frequency,
176+
xplrLbandDeviceCfg_t *dvcCfg,
171177
uDeviceHandle_t *destHandler)
172178
{
173179
if (!xplrHlprLocSrvcCheckDvcProfileValidity(dvcProfile, XPLRLBAND_NUMOF_DEVICES)) {
@@ -199,11 +205,6 @@ esp_err_t xplrLbandStartDevice(uint8_t dvcProfile,
199205
return espRet;
200206
}
201207

202-
espRet = xplrLbandSetFrequency(dvcProfile, frequency);
203-
if (espRet != ESP_OK) {
204-
return espRet;
205-
}
206-
207208
if (destHandler != NULL) {
208209
espRet = xplrLbandSendCorrectionDataAsyncStart(dvcProfile, destHandler);
209210
if (espRet != ESP_OK) {
@@ -314,9 +315,9 @@ esp_err_t xplrLbandSetFrequency(uint8_t dvcProfile, uint32_t frequency)
314315
return ESP_FAIL;
315316
}
316317

317-
espRet = xplrLbandOptionSingleValSet(dvcProfile,
318+
espRet = xplrLbandOptionSingleValSet(dvcProfile,
318319
U_GNSS_CFG_VAL_KEY_ID_PMP_CENTER_FREQUENCY_U4,
319-
frequency,
320+
frequency,
320321
U_GNSS_CFG_VAL_LAYER_RAM);
321322
if (espRet != ESP_OK) {
322323
return espRet;
@@ -325,6 +326,50 @@ esp_err_t xplrLbandSetFrequency(uint8_t dvcProfile, uint32_t frequency)
325326
return ESP_OK;
326327
}
327328

329+
esp_err_t xplrLbandSetFrequencyFromMqtt(uint8_t dvcProfile, char *mqttPayload, xplrLbandRegion region)
330+
{
331+
esp_err_t ret = ESP_OK;
332+
uint32_t frequency = 0;
333+
334+
ret = xplrLbandParseFrequencyFromMqtt(dvcProfile, mqttPayload, region, &frequency);
335+
336+
if (ret != ESP_OK || frequency == 0) {
337+
XPLRLBAND_CONSOLE(E, "Could not parse frequency!");
338+
ret = ESP_FAIL;
339+
} else {
340+
ret = xplrLbandSetFrequency(dvcProfile, frequency);
341+
if (ret == ESP_OK) {
342+
XPLRLBAND_CONSOLE(D,
343+
"Set LBAND location: %s frequency: %d Hz successfully!",
344+
freqRegions[region],
345+
frequency);
346+
} else {
347+
XPLRLBAND_CONSOLE(E, "Could not set LBAND location: %s frequency: %d Hz!", frequency);
348+
}
349+
}
350+
351+
return ret;
352+
}
353+
354+
uint32_t xplrLbandGetFrequency(uint8_t dvcProfile)
355+
{
356+
uint32_t ret = 0;
357+
esp_err_t espRet = ESP_OK;
358+
359+
espRet = xplrLbandOptionSingleValGet(dvcProfile,
360+
U_GNSS_CFG_VAL_KEY_ID_PMP_CENTER_FREQUENCY_U4,
361+
&ret,
362+
sizeof(ret),
363+
U_GNSS_CFG_VAL_LAYER_RAM);
364+
365+
if (espRet != ESP_OK) {
366+
XPLRLBAND_CONSOLE(E, "Could not read frequency from LBAND module!");
367+
ret = 0;
368+
}
369+
370+
return ret;
371+
}
372+
328373
int32_t xplrLbandSendFormattedCommand(uint8_t dvcProfile, const char *pBuffer, size_t size)
329374
{
330375
if (!xplrHlprLocSrvcCheckDvcProfileValidity(dvcProfile, XPLRLBAND_NUMOF_DEVICES)) {
@@ -358,7 +403,7 @@ esp_err_t xplrLbandSendCorrectionDataAsyncStart(uint8_t dvcProfile, uDeviceHandl
358403
return ESP_FAIL;
359404
}
360405

361-
XPLRLBAND_CONSOLE(I, "Started LBAND Send Correction Data async.");
406+
XPLRLBAND_CONSOLE(D, "Started LBAND Send Correction Data async.");
362407
return ESP_OK;
363408
}
364409

@@ -471,6 +516,59 @@ static int32_t xplrLbandPrivateAsyncStopper(uint8_t dvcProfile, int32_t handler)
471516
return ubxRet;
472517
}
473518

519+
static esp_err_t xplrLbandParseFrequencyFromMqtt(uint8_t dvcProfile,
520+
char *mqttPayload,
521+
xplrLbandRegion region,
522+
uint32_t *parsedFrequency)
523+
{
524+
esp_err_t ret = ESP_OK;
525+
cJSON *json, *freqs, *jregion, *current, *frequency;
526+
double tmpfreq = 0;
527+
528+
if (!xplrHlprLocSrvcCheckDvcProfileValidity(dvcProfile, XPLRLBAND_NUMOF_DEVICES)) {
529+
ret = ESP_FAIL;
530+
}
531+
532+
if (ret == ESP_OK) {
533+
json = cJSON_Parse(mqttPayload);
534+
535+
if (cJSON_HasObjectItem(json, "frequencies")){
536+
freqs = cJSON_GetObjectItem(json, "frequencies");
537+
if (cJSON_HasObjectItem(freqs, freqRegions[region])) {
538+
jregion = cJSON_GetObjectItem(freqs, freqRegions[region]);
539+
if (cJSON_HasObjectItem(jregion, "current")) {
540+
current = cJSON_GetObjectItem(jregion, "current");
541+
if (cJSON_HasObjectItem(current, "value")) {
542+
frequency = cJSON_GetObjectItem(current, "value");
543+
sscanf(cJSON_GetStringValue(frequency), "%lf", &tmpfreq);
544+
*parsedFrequency = (uint32_t)((1e+6) * tmpfreq);
545+
} else {
546+
XPLRLBAND_CONSOLE(E, "Theres no frequency \"value\" object.");
547+
*parsedFrequency = 0;
548+
ret = ESP_FAIL;
549+
}
550+
} else {
551+
XPLRLBAND_CONSOLE(E, "Theres no \"current\" object.");
552+
*parsedFrequency = 0;
553+
ret = ESP_FAIL;
554+
}
555+
} else {
556+
XPLRLBAND_CONSOLE(E, "Theres no \"%s\" location object.", freqRegions[region]);
557+
*parsedFrequency = 0;
558+
ret = ESP_FAIL;
559+
}
560+
} else {
561+
XPLRLBAND_CONSOLE(E, "Theres no \"frequencies\" object.");
562+
*parsedFrequency = 0;
563+
ret = ESP_FAIL;
564+
}
565+
566+
cJSON_Delete(json);
567+
}
568+
569+
return ESP_OK;
570+
}
571+
474572
/* ----------------------------------------------------------------
475573
* STATIC CALLBACK FUNCTION DEFINITIONS
476574
* -------------------------------------------------------------- */

XPLR-HPG-SW/components/hpglib/src/location_service/lband_service/xplr_lband.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,25 @@ uDeviceHandle_t *xplrLbandGetHandler(uint8_t dvcProfile);
8787
*
8888
* @param dvcProfile an integer number denoting the device profile/index.
8989
* @param i2cAddress I2C address of the LBAND device.
90-
* @param frequency LBAND data channel frequency. Select on of the available frequencies
91-
* available according to your region:
92-
* XPLR_LBAND_FREQUENCY_EU or XPLR_LBAND_FREQUENCY_US
9390
* @param destHandler GNSS destination device handler to push data to.
9491
* @return zero on success or negative error code on
9592
* failure.
9693
*/
9794
esp_err_t xplrLbandStartDeviceDefaultSettings(uint8_t dvcProfile,
98-
uint8_t i2cAddress,
99-
uint32_t frequency,
95+
uint8_t i2cAddress,
10096
uDeviceHandle_t *destHandler);
10197

10298
/**
10399
* @brief Starts an LBAND device with the provided settings in a form of a struct.
104100
*
105101
* @param dvcProfile an integer number denoting the device profile/index.
106102
* @param dvcCfg device configuration.
107-
* @param frequency LBAND data channel frequency. Select on of the available frequencies
108-
* available according to your region:
109-
* XPLR_LBAND_FREQUENCY_EU or XPLR_LBAND_FREQUENCY_US.
110103
* @param destHandler GNSS destination device handler to push data to.
111104
* @return zero on success or negative error code on
112105
* failure.
113106
*/
114107
esp_err_t xplrLbandStartDevice(uint8_t dvcProfile,
115108
xplrLbandDeviceCfg_t *dvcCfg,
116-
uint32_t frequency,
117109
uDeviceHandle_t *destHandler);
118110

119111
/**
@@ -221,14 +213,36 @@ esp_err_t xplrLbandOptionMultiValGet(uint8_t dvcProfile,
221213
* @brief Sets the frequency for correction data channel.
222214
*
223215
* @param dvcProfile an integer number denoting the device profile/index.
224-
* @param frequency LBAND data channel frequency. Select on of the available frequencies
225-
* available according to your region:
226-
* XPLR_LBAND_FREQUENCY_EU or XPLR_LBAND_FREQUENCY_US
216+
* @param frequency LBAND data channel frequency. Taken usually from MQTT
217+
* or can be manually passed if the values are known.
227218
* @return zero on success or negative error code on
228219
* failure.
229220
*/
230221
esp_err_t xplrLbandSetFrequency(uint8_t dvcProfile, uint32_t frequency);
231222

223+
/**
224+
* @brief Set frequency for LBAND directly from the received MQTT message
225+
* depending on current region
226+
*
227+
* @param dvcProfile an integer number denoting the device profile/index.
228+
* @param mqttPayload MQTT payload as received from the client.
229+
* @param region geographic region we are currently in.
230+
* @return zero on success or negative error code on
231+
* failure.
232+
*/
233+
esp_err_t xplrLbandSetFrequencyFromMqtt(uint8_t dvcProfile,
234+
char *mqttPayload,
235+
xplrLbandRegion region);
236+
237+
/**
238+
* @brief Reads configured frequency from LBAND
239+
*
240+
* @param dvcProfile an integer number denoting the device profile/index.
241+
* @return zero on success or negative error code on
242+
* failure.
243+
*/
244+
uint32_t xplrLbandGetFrequency(uint8_t dvcProfile);
245+
232246
/**
233247
* @brief
234248
*

XPLR-HPG-SW/components/hpglib/src/location_service/lband_service/xplr_lband_types.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030
* mostly lband device settings.
3131
*/
3232

33-
/**
34-
* Lband frequencies to receive correction data from
35-
*/
36-
#define XPLR_LBAND_FREQUENCY_EU 1545260000
37-
#define XPLR_LBAND_FREQUENCY_US 1556290000
38-
3933
/**
4034
* Device and network config
4135
*/
@@ -44,4 +38,9 @@ typedef struct xplrLbandDeviceCfg_type {
4438
uNetworkCfgGnss_t dvcNetwork; /**< Network config */
4539
} xplrLbandDeviceCfg_t;
4640

41+
typedef enum {
42+
XPLR_LBAND_FREQUENCY_EU = 0,
43+
XPLR_LBAND_FREQUENCY_US
44+
} xplrLbandRegion;
45+
4746
#endif

XPLR-HPG-SW/components/hpglib/src/location_service/location_service_helpers/xplr_location_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ esp_err_t xplrHlprLocSrvcOptionSingleValSet(xplrGnssDevBase_t *dvcBase,
288288
return ESP_FAIL;
289289
}
290290

291-
XPLRHELPERS_CONSOLE(I, "Set configuration value.");
291+
XPLRHELPERS_CONSOLE(D, "Set configuration value.");
292292
return ESP_OK;
293293
}
294294

0 commit comments

Comments
 (0)