Skip to content

Commit 6c3b7b4

Browse files
committed
Add SARA-R5_Example17_AssistNow_MQTT
1 parent 3734e91 commit 6c3b7b4

File tree

6 files changed

+1460
-0
lines changed

6 files changed

+1460
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright 2022 by Michael Ammann (@mazgch)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef __CONFIG_H__
18+
#define __CONFIG_H__
19+
20+
#include <vector>
21+
#include <mbedtls/base64.h>
22+
23+
#include "HW.h"
24+
#include "secrets.h"
25+
26+
// -----------------------------------------------------------------------
27+
// MQTT / PointPerfect settings
28+
// -----------------------------------------------------------------------
29+
30+
const unsigned short MQTT_BROKER_PORT = 8883; //!< MQTTS port
31+
const int MQTT_MAX_MSG_SIZE = 9*1024; //!< the max size of a MQTT pointperfect topic
32+
33+
#define MQTT_TOPIC_MGA "/pp/ubx/mga" //!< GNSS assistance topic
34+
35+
const char MQTT_TOPIC_MGA_GPS[] = MQTT_TOPIC_MGA "/gps"; //!< GPS (US)
36+
const char MQTT_TOPIC_MGA_GLO[] = MQTT_TOPIC_MGA "/glo"; //!< Glonass (RU)
37+
const char MQTT_TOPIC_MGA_GAL[] = MQTT_TOPIC_MGA "/gal"; //!< Galileo (EU)
38+
const char MQTT_TOPIC_MGA_BDS[] = MQTT_TOPIC_MGA "/bds"; //!< Beidou (CN)
39+
40+
// -----------------------------------------------------------------------
41+
// CONFIGURATION keys
42+
// -----------------------------------------------------------------------
43+
44+
#define CONFIG_DEVICE_TITLE "HPG solution" //!< a used friendly name
45+
#define CONFIG_DEVICE_NAMEPREFIX "hpg" //!< a hostname compatible prefix, only a-z, 0-9 and -
46+
47+
// PointPerfect configuration
48+
const char CONFIG_VALUE_BROKERHOST[] = "brokerHost"; //!< config key for brocker host
49+
const char CONFIG_VALUE_STREAM[] = "stream"; //!< config key for stream
50+
const char CONFIG_VALUE_ROOTCA[] = "rootCa"; //!< config key for root certificate
51+
const char CONFIG_VALUE_CLIENTCERT[] = "clientCert"; //!< config key for client certificate
52+
const char CONFIG_VALUE_CLIENTKEY[] = "clientKey"; //!< config key for client keys
53+
const char CONFIG_VALUE_CLIENTID[] = "clientId"; //!< config key for client id
54+
55+
/** This class encapsulates all WLAN functions.
56+
*/
57+
class CONFIG {
58+
59+
public:
60+
61+
/** constructor
62+
*/
63+
CONFIG() {
64+
// create a unique name from the mac
65+
uint64_t mac = ESP.getEfuseMac();
66+
const char* p = (const char*)&mac;
67+
char str[64];
68+
sprintf(str, CONFIG_DEVICE_TITLE " - %02x%02x%02x", p[3], p[4], p[5]);
69+
title = str;
70+
sprintf(str, CONFIG_DEVICE_NAMEPREFIX "-%02x%02x%02x", p[3], p[4], p[5]);
71+
name = str;
72+
}
73+
74+
/** get a name of the device
75+
* \return the device name
76+
*/
77+
String getDeviceName(void) {
78+
return name;
79+
}
80+
81+
/** get a friendly name of the device
82+
* \return the friendly device title
83+
*/
84+
String getDeviceTitle(void) {
85+
return title;
86+
}
87+
88+
/** get the topics to subscribe
89+
* \return a vector with all the topics
90+
*/
91+
std::vector<String> getTopics(void)
92+
{
93+
std::vector<String> topics;
94+
topics.push_back(MQTT_TOPIC_MGA);
95+
//topics.push_back(MQTT_TOPIC_MGA_GPS);
96+
//topics.push_back(MQTT_TOPIC_MGA_GLO);
97+
//topics.push_back(MQTT_TOPIC_MGA_GAL);
98+
//topics.push_back(MQTT_TOPIC_MGA_BDS);
99+
return topics;
100+
}
101+
102+
protected:
103+
104+
String title; //!< the title of the device
105+
String name; //!< the name of the device
106+
};
107+
108+
CONFIG Config; //!< The global CONFIG object
109+
110+
#endif // __CONFIG_H__
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright 2022 by Michael Ammann (@mazgch)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef __HW_H__
18+
#define __HW_H__
19+
20+
/** The target is used to enable conditional code thoughout this application
21+
*/
22+
23+
#define SPARKFUN_MICROMOD_ASSET_TRACKER 41 //!< Choose Sparkfun ESP32 Arduino / Sparkfun ESP32 MicroMod
24+
25+
#define SPARKFUN_RTK_EVERYWHERE 51 //!< Select ESP32 / ESP32 Wrover Module
26+
27+
#define HW_TARGET SPARKFUN_MICROMOD_ASSET_TRACKER
28+
29+
/** the pins are defined here for each hardware target
30+
*/
31+
enum HW_PINS {
32+
// Standard pins
33+
BOOT = 0,
34+
CDC_RX = RX, CDC_TX = TX,
35+
#if (HW_TARGET == SPARKFUN_RTK_EVERYWHERE)
36+
LED = 2,
37+
CAN_RX = -1, CAN_TX = -1,
38+
I2C_SDA = 21, I2C_SCL = 22,
39+
#elif (HW_TARGET == SPARKFUN_MICROMOD_ASSET_TRACKER)
40+
LED = 2,
41+
CAN_RX = -1, CAN_TX = -1,
42+
I2C_SDA = 21, I2C_SCL = 22,
43+
#else
44+
#error unknown board target
45+
#endif
46+
47+
#if (HW_TARGET == SPARKFUN_MICROMOD_ASSET_TRACKER)
48+
// LTE (DCE)
49+
LTE_RESET = -1, LTE_PWR_ON = G2, LTE_ON = G6, LTE_INT = G5,
50+
LTE_TXI = TX1, LTE_RXO = RX1, LTE_RTS = -1, LTE_CTS = -1,
51+
LTE_RI = G4, LTE_DSR = -1, LTE_DCD = -1, LTE_DTR = -1,
52+
LTE_PWR_ON_ACTIVE = HIGH, LTE_ON_ACTIVE = LOW,
53+
54+
// Power supply
55+
VIN = 39, V33_EN = -1, V33_EN_ACTIVE = HIGH,
56+
57+
// Micro SD card
58+
MICROSD_SCK = SCK, MICROSD_SDI = MISO, MICROSD_SDO = MOSI,
59+
MICROSD_DET = -1, MICROSD_PWR_EN = G1,
60+
MICROSD_CS = G0,
61+
MICROSD_DET_REMOVED = HIGH, MICROSD_PWR_EN_ACTIVE = LOW,
62+
63+
REQUIRED_GPIO_PIN = -1, REQUIRED_GPIO_PIN_ACTIVE = HIGH,
64+
65+
#elif (HW_TARGET == SPARKFUN_RTK_EVERYWHERE)
66+
// LTE (DCE)
67+
LTE_RESET = -1, LTE_PWR_ON = 26, LTE_ON = 5, LTE_INT = -1,
68+
LTE_TXI = 13, LTE_RXO = 14, LTE_RTS = -1, LTE_CTS = -1,
69+
LTE_RI = -1, LTE_DSR = -1, LTE_DCD = -1, LTE_DTR = -1,
70+
LTE_NI = 34,
71+
LTE_PWR_ON_ACTIVE = HIGH, LTE_ON_ACTIVE = HIGH,
72+
73+
// Power supply
74+
VIN = -1, V33_EN = 32, V33_EN_ACTIVE = HIGH,
75+
76+
// Micro SD card
77+
MICROSD_SCK = SCK, MICROSD_SDI = MISO, MICROSD_SDO = MOSI,
78+
MICROSD_DET = 36, MICROSD_PWR_EN = -1,
79+
MICROSD_CS = 4,
80+
MICROSD_DET_REMOVED = LOW, MICROSD_PWR_EN_ACTIVE = LOW,
81+
82+
// Required GPIO pin - on SPARKFUN_RTK_EVERYWHERE this is the WizNet W5500 CS
83+
REQUIRED_GPIO_PIN = 27, REQUIRED_GPIO_PIN_ACTIVE = HIGH,
84+
85+
#endif
86+
PIN_INVALID = -1
87+
};
88+
89+
class HW {
90+
91+
public:
92+
93+
/** constructor
94+
*/
95+
HW(){
96+
hwInit();
97+
}
98+
99+
void hwInit(void) {
100+
// Do any top-level hardware initialization here:
101+
// Initialize any required GPIO pins
102+
if (PIN_INVALID != REQUIRED_GPIO_PIN) {
103+
digitalWrite(REQUIRED_GPIO_PIN, REQUIRED_GPIO_PIN_ACTIVE);
104+
pinMode(REQUIRED_GPIO_PIN, OUTPUT);
105+
digitalWrite(REQUIRED_GPIO_PIN, REQUIRED_GPIO_PIN_ACTIVE);
106+
}
107+
// Turn on the 3.3V regulator - if present
108+
if (PIN_INVALID != V33_EN) {
109+
digitalWrite(V33_EN, V33_EN_ACTIVE);
110+
pinMode(V33_EN, OUTPUT);
111+
digitalWrite(V33_EN, V33_EN_ACTIVE);
112+
}
113+
log_i("Hardware initialized");
114+
}
115+
116+
};
117+
118+
HW Hardware; //!< The global HW object
119+
120+
#endif // __HW_H__

0 commit comments

Comments
 (0)