Update mqttMessageHandler
This commit is contained in:
+28
-20
@@ -93,35 +93,43 @@ void loop()
|
||||
WiFiClientSecure wifiClient = WiFiClientSecure();
|
||||
MqttClient mqttClient(wifiClient);
|
||||
|
||||
void mqttMessageHandler(int messageSize) {
|
||||
const uint16_t mgaCountLimit = 16384;
|
||||
uint8_t *mgaData = new uint8_t[mgaCountLimit];
|
||||
uint16_t mgaCount = 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
|
||||
mgaData[mgaCount++] = ch;
|
||||
if (mgaCount == mgaCountLimit)
|
||||
uint16_t mqttCount = 0;
|
||||
|
||||
while (mqttClient.available())
|
||||
{
|
||||
Serial.print(F("Warning!! MQTT data exceeded "));
|
||||
Serial.print(mgaCountLimit);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
if (mgaCount > 0)
|
||||
{
|
||||
//Push MGA data to GNSS module over I2C
|
||||
myGNSS.pushRawData(mgaData, mgaCount, false);
|
||||
lastReceived_ms = millis();
|
||||
}
|
||||
|
||||
delete[] mgaData;
|
||||
delete[] mqttData;
|
||||
}
|
||||
|
||||
//Connect to MQTT broker, receive MGA, and push to ZED module over I2C
|
||||
|
||||
Reference in New Issue
Block a user