Trim float values for MQTT
This commit is contained in:
17
Kuhnya/.vscode/extensions.json
vendored
17
Kuhnya/.vscode/extensions.json
vendored
@@ -1,7 +1,10 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
]
|
||||
}
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -79,3 +79,4 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
|
||||
void onMqttConnect(bool sessionPresent);
|
||||
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
|
||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
|
||||
void trim(char *s);
|
||||
|
||||
@@ -257,18 +257,22 @@ void publishMin()
|
||||
digitalWrite(BLUE, HIGH);
|
||||
if(!isnan(tempOut)){
|
||||
dtostrf(tempOut, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"kuh/temp_out", 1, false, strFVal);
|
||||
}
|
||||
if(!isnan(tempIn)){
|
||||
dtostrf(tempIn, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"kuh/temp_in", 1, false, strFVal);
|
||||
}
|
||||
if(!isnan(hum)){
|
||||
dtostrf(hum, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"kuh/humidity", 1, false, strFVal);
|
||||
}
|
||||
if(!isnan(press)){
|
||||
dtostrf(press, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"kuh/pressure", 1, false, strFVal);
|
||||
}
|
||||
//itoa(lightSP, strFVal, 10);
|
||||
@@ -279,14 +283,17 @@ void publishMin()
|
||||
mqttClient.publish(TOPIC"kuh/light_cur", 1, false, strFVal);
|
||||
if(!isnan(tempHol)){
|
||||
dtostrf(tempHol, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"kuh/hol_top", 1, false, strFVal);
|
||||
}
|
||||
if(!isnan(tempHoM)){
|
||||
dtostrf(tempHoM, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"kuh/hol_down", 1, false, strFVal);
|
||||
}
|
||||
if(!isnan(tempMor)){
|
||||
dtostrf(tempMor, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"kuh/moroz", 1, false, strFVal);
|
||||
}
|
||||
ultoa(crun, strFVal, 10);
|
||||
@@ -394,3 +401,31 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
||||
EEPROM.commit();
|
||||
}
|
||||
}
|
||||
void trim(char *s)
|
||||
{
|
||||
// удаляем пробелы и табы с начала строки:
|
||||
unsigned int i=0,j;
|
||||
while((s[i]==' ')||(s[i]=='\t'))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if(i>0)
|
||||
{
|
||||
for(j=0; j < strlen(s); j++)
|
||||
{
|
||||
s[j]=s[j+i];
|
||||
}
|
||||
s[j]='\0';
|
||||
}
|
||||
|
||||
// удаляем пробелы и табы с конца строки:
|
||||
i=strlen(s)-1;
|
||||
while((s[i]==' ')||(s[i]=='\t'))
|
||||
{
|
||||
i--;
|
||||
}
|
||||
if(i < (strlen(s)-1))
|
||||
{
|
||||
s[i+1]='\0';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user