mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-06 21:54:44 +00:00
add gust and lull computation
This commit is contained in:
parent
416fac62dd
commit
6b0cc27658
@ -200,9 +200,10 @@ int32_t SerialModule::runOnce()
|
|||||||
} else if ((moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_WS85)) {
|
} else if ((moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_WS85)) {
|
||||||
static unsigned int lastAveraged = 0;
|
static unsigned int lastAveraged = 0;
|
||||||
static unsigned int averageIntervalMillis = 300000; // 5 minutes
|
static unsigned int averageIntervalMillis = 300000; // 5 minutes
|
||||||
static int dirSum = 0;
|
static int dirSum = 0; // TODO : this needs trig, probably a second variable to keep track
|
||||||
static float velSum = 0;
|
static float velSum = 0;
|
||||||
static float gust = 0;
|
static float gust = 0;
|
||||||
|
static float lull = -1;
|
||||||
static int velCount = 0;
|
static int velCount = 0;
|
||||||
static int dirCount = 0;
|
static int dirCount = 0;
|
||||||
static char windDir[4] = "xxx"; // Assuming windDir is 3 characters long + null terminator
|
static char windDir[4] = "xxx"; // Assuming windDir is 3 characters long + null terminator
|
||||||
@ -210,8 +211,8 @@ int32_t SerialModule::runOnce()
|
|||||||
static char windGust[5] = "xx.x"; // Assuming windGust is 4 characters long + null terminator
|
static char windGust[5] = "xx.x"; // Assuming windGust is 4 characters long + null terminator
|
||||||
static char batVoltage[5] = "0.0V";
|
static char batVoltage[5] = "0.0V";
|
||||||
static char capVoltage[5] = "0.0V";
|
static char capVoltage[5] = "0.0V";
|
||||||
static float batVoltageF = 1;
|
static float batVoltageF = 0;
|
||||||
static float capVoltageF = 1;
|
static float capVoltageF = 0;
|
||||||
bool gotwind = false;
|
bool gotwind = false;
|
||||||
|
|
||||||
while (Serial2.available()) {
|
while (Serial2.available()) {
|
||||||
@ -220,9 +221,10 @@ int32_t SerialModule::runOnce()
|
|||||||
// memset(formattedString, '\0', sizeof(formattedString));
|
// memset(formattedString, '\0', sizeof(formattedString));
|
||||||
serialPayloadSize = Serial2.readBytes(serialBytes, meshtastic_Constants_DATA_PAYLOAD_LEN);
|
serialPayloadSize = Serial2.readBytes(serialBytes, meshtastic_Constants_DATA_PAYLOAD_LEN);
|
||||||
// check for a string we care about
|
// check for a string we care about
|
||||||
// WindDir = 173
|
// WindDir = 79
|
||||||
// 19 : 21 : 37.325->WindSpeed = 0.0
|
// WindSpeed = 0.5
|
||||||
// 19 : 21 : 37.325->WindGust = 0.5
|
// WindGust = 0.6
|
||||||
|
// GXTS04Temp = 24.4
|
||||||
if (serialPayloadSize > 0) {
|
if (serialPayloadSize > 0) {
|
||||||
// Define variables for line processing
|
// Define variables for line processing
|
||||||
int lineStart = 0;
|
int lineStart = 0;
|
||||||
@ -254,8 +256,12 @@ int32_t SerialModule::runOnce()
|
|||||||
} else if (windSpeedPos != NULL) {
|
} else if (windSpeedPos != NULL) {
|
||||||
// Extract data after "=" for WindSpeed
|
// Extract data after "=" for WindSpeed
|
||||||
strcpy(windVel, windSpeedPos + 15); // Add 15 to skip "WindSpeed = "
|
strcpy(windVel, windSpeedPos + 15); // Add 15 to skip "WindSpeed = "
|
||||||
velSum += strtof(windVel, nullptr);
|
float newv = strtof(windVel, nullptr);
|
||||||
|
velSum += newv;
|
||||||
velCount++;
|
velCount++;
|
||||||
|
if (newv < lull)
|
||||||
|
lull = newv;
|
||||||
|
|
||||||
} else if (windGustPos != NULL) {
|
} else if (windGustPos != NULL) {
|
||||||
strcpy(windGust, windGustPos + 15); // Add 15 to skip "WindSpeed = "
|
strcpy(windGust, windGustPos + 15); // Add 15 to skip "WindSpeed = "
|
||||||
float newg = strtof(windGust, nullptr);
|
float newg = strtof(windGust, nullptr);
|
||||||
@ -263,24 +269,18 @@ int32_t SerialModule::runOnce()
|
|||||||
gust = newg;
|
gust = newg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// there are also voltage data we care about possibly
|
// these are also voltage data we care about possibly
|
||||||
} else if (strstr(line, "BatVoltage") != NULL) { // we have a battVoltage line
|
// } else if (strstr(line, "BatVoltage") != NULL) { // we have a battVoltage line
|
||||||
char *batVoltagePos = strstr(line, "BatVoltage = ");
|
// char *batVoltagePos = strstr(line, "BatVoltage = ");
|
||||||
if (batVoltagePos != NULL) {
|
// if (batVoltagePos != NULL) {
|
||||||
strcpy(batVoltage, batVoltagePos + 17); // 18 for ws 80, 17 for ws85
|
// strcpy(batVoltage, batVoltagePos + 17); // 18 for ws 80, 17 for ws85
|
||||||
batVoltageF = strtof(batVoltage, nullptr);
|
// batVoltageF = strtof(batVoltage, nullptr);
|
||||||
// float voltage_f = strtof(batVoltage, &endptr);
|
// }
|
||||||
// batVoltageInt = static_cast<int>(voltage_f * 10);
|
|
||||||
}
|
|
||||||
} else if (strstr(line, "CapVoltage") != NULL) { // we have a cappVoltage line
|
} else if (strstr(line, "CapVoltage") != NULL) { // we have a cappVoltage line
|
||||||
// should parse CapVoltage = 5.40V } else if (strstr(line,
|
|
||||||
// "CapVoltage") != NULL) { // we have a battVoltage line
|
|
||||||
char *capVoltagePos = strstr(line, "CapVoltage = ");
|
char *capVoltagePos = strstr(line, "CapVoltage = ");
|
||||||
if (capVoltagePos != NULL) {
|
if (capVoltagePos != NULL) {
|
||||||
strcpy(capVoltage, capVoltagePos + 17); // 18 for ws 80, 17 for ws85
|
strcpy(capVoltage, capVoltagePos + 17); // 18 for ws 80, 17 for ws85
|
||||||
capVoltageF = strtof(capVoltage, nullptr);
|
capVoltageF = strtof(capVoltage, nullptr);
|
||||||
// float voltage_f = strtof(capVoltage, &endptr);
|
|
||||||
// capVoltageInt = static_cast<int>(voltage_f * 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,13 +291,14 @@ int32_t SerialModule::runOnce()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gotwind) {
|
if (gotwind) {
|
||||||
|
|
||||||
LOG_INFO("WS85 : %i %.1fg%.1f %.1fv %.1fv\n", atoi(windDir), strtof(windVel, nullptr),
|
LOG_INFO("WS85 : %i %.1fg%.1f %.1fv %.1fv\n", atoi(windDir), strtof(windVel, nullptr),
|
||||||
strtof(windGust, nullptr), batVoltageF, capVoltageF);
|
strtof(windGust, nullptr), batVoltageF, capVoltageF);
|
||||||
}
|
}
|
||||||
if (gotwind && millis() - lastAveraged > averageIntervalMillis) {
|
if (gotwind && millis() - lastAveraged > averageIntervalMillis) {
|
||||||
// calulate average and send to the mesh
|
// calulate average and send to the mesh
|
||||||
float velAvg = 1.0 * velSum / velCount;
|
float velAvg = 1.0 * velSum / velCount;
|
||||||
float dirAvg = dirSum / dirCount;
|
float dirAvg = dirSum / dirCount; // TODO : this needs some trig to be accurate
|
||||||
// gust = gust
|
// gust = gust
|
||||||
// sprintf(formattedString, "%i %.1fg%.1f %.1fv %.1fv", dirAvg, velAvg * 2.23, gust * 2.23, batVoltageF,
|
// sprintf(formattedString, "%i %.1fg%.1f %.1fv %.1fv", dirAvg, velAvg * 2.23, gust * 2.23, batVoltageF,
|
||||||
// capVoltageF);
|
// capVoltageF);
|
||||||
@ -307,8 +308,9 @@ int32_t SerialModule::runOnce()
|
|||||||
meshtastic_Telemetry m = meshtastic_Telemetry_init_zero;
|
meshtastic_Telemetry m = meshtastic_Telemetry_init_zero;
|
||||||
m.variant.environment_metrics.wind_speed = velAvg;
|
m.variant.environment_metrics.wind_speed = velAvg;
|
||||||
m.variant.environment_metrics.wind_direction = dirAvg;
|
m.variant.environment_metrics.wind_direction = dirAvg;
|
||||||
// m.variant.environment_metrics.wind_gust = gust;
|
m.variant.environment_metrics.wind_gust = gust;
|
||||||
// m.variant.environment_metrics.wind_lull = lull;
|
m.variant.environment_metrics.wind_lull = lull;
|
||||||
|
m.variant.environment_metrics.voltage = capVoltageF; // why not send sensor voltage too ?
|
||||||
|
|
||||||
LOG_INFO("(Sending): wind speed=%fm/s, direction=%d degrees\n", m.variant.environment_metrics.wind_speed,
|
LOG_INFO("(Sending): wind speed=%fm/s, direction=%d degrees\n", m.variant.environment_metrics.wind_speed,
|
||||||
m.variant.environment_metrics.wind_direction);
|
m.variant.environment_metrics.wind_direction);
|
||||||
@ -325,9 +327,10 @@ int32_t SerialModule::runOnce()
|
|||||||
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
p->priority = meshtastic_MeshPacket_Priority_RELIABLE;
|
||||||
service.sendToMesh(p, RX_SRC_LOCAL, true);
|
service.sendToMesh(p, RX_SRC_LOCAL, true);
|
||||||
|
|
||||||
// reset counters
|
// reset counters and gust/lull
|
||||||
velSum = velCount = dirSum = dirCount = 0;
|
velSum = velCount = dirSum = dirCount = 0;
|
||||||
gust = 0;
|
gust = 0;
|
||||||
|
lull = -1;
|
||||||
|
|
||||||
// clear serialBytes first;
|
// clear serialBytes first;
|
||||||
// memset(serialBytes, '\0', sizeof(serialBytes));
|
// memset(serialBytes, '\0', sizeof(serialBytes));
|
||||||
|
Loading…
Reference in New Issue
Block a user