Update mqttMessageHandler
This commit is contained in:
@@ -247,45 +247,43 @@ void loop()
|
||||
WiFiClientSecure wifiClient = WiFiClientSecure();
|
||||
MqttClient mqttClient(wifiClient);
|
||||
|
||||
void mqttMessageHandler(int messageSize) {
|
||||
// Testing with /pp/ubx/0236/ip + /pp/ip/eu + /pp/ubx/mga shows the initial data length can be more than 13KBytes
|
||||
const uint16_t spartnCountLimit = 16384;
|
||||
uint8_t *spartnData = new uint8_t[spartnCountLimit];
|
||||
uint16_t spartnCount = 0;
|
||||
void mqttMessageHandler(int messageSize)
|
||||
{
|
||||
const uint16_t mqttLimit = 512;
|
||||
uint8_t *mqttData = new uint8_t[mqttLimit]; // Allocate memory to hold the MQTT data
|
||||
if (mqttData == NULL)
|
||||
{
|
||||
Serial.println(F("Memory allocation for mqttData failed!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print(F("Pushing data from "));
|
||||
Serial.print(mqttClient.messageTopic());
|
||||
Serial.println(F(" topic to ZED"));
|
||||
|
||||
while (mqttClient.available())
|
||||
{
|
||||
char ch = mqttClient.read();
|
||||
//Serial.write(ch); //Pipe to serial port is fine but beware, it's a lot of binary data
|
||||
spartnData[spartnCount++] = ch;
|
||||
if (spartnCount == spartnCountLimit)
|
||||
uint16_t mqttCount = 0;
|
||||
|
||||
while (mqttClient.available())
|
||||
{
|
||||
Serial.print(F("Warning!! MQTT data exceeded "));
|
||||
Serial.print(spartnCountLimit);
|
||||
Serial.println(F(" bytes!!"));
|
||||
break;
|
||||
char ch = mqttClient.read();
|
||||
//Serial.write(ch); //Pipe to serial port is fine but beware, it's a lot of binary data
|
||||
mqttData[mqttCount++] = ch;
|
||||
|
||||
if (mqttCount == mqttLimit)
|
||||
break;
|
||||
}
|
||||
|
||||
if (mqttCount > 0)
|
||||
{
|
||||
//Push KEYS or SPARTN data to GNSS module over I2C
|
||||
myGNSS.pushRawData(mqttData, mqttCount, false);
|
||||
lastReceived_ms = millis();
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t maxSpartnCount = 0;
|
||||
if (spartnCount > maxSpartnCount)
|
||||
{
|
||||
maxSpartnCount = spartnCount;
|
||||
Serial.print(F("Maximum MQTT data length is "));
|
||||
Serial.print(maxSpartnCount);
|
||||
Serial.println(F(" bytes"));
|
||||
}
|
||||
|
||||
if (spartnCount > 0)
|
||||
{
|
||||
//Push KEYS or SPARTN data to GNSS module over I2C
|
||||
myGNSS.pushRawData(spartnData, spartnCount, false);
|
||||
lastReceived_ms = millis();
|
||||
}
|
||||
|
||||
delete[] spartnData;
|
||||
delete[] mqttData;
|
||||
}
|
||||
|
||||
//Connect to STARTN MQTT broker, receive RTCM, and push to ZED module over I2C
|
||||
|
||||
Reference in New Issue
Block a user