Trim float values for MQTT
This commit is contained in:
17
ESP12SmallRoom/.vscode/extensions.json
vendored
17
ESP12SmallRoom/.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"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -21,3 +21,4 @@ lib_deps =
|
||||
PubSubClient @ ^2.8
|
||||
jwrw/ESP_EEPROM @ ^2.0.0
|
||||
marvinroger/AsyncMqttClient @ ^0.9.0
|
||||
adafruit/Adafruit HTU21DF Library @ ^1.0.5
|
||||
|
||||
@@ -57,6 +57,7 @@ void onMqttSubscribe(uint16_t packetId, uint8_t qos);
|
||||
void onMqttUnsubscribe(uint16_t packetId);
|
||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
|
||||
void onMqttPublish(uint16_t packetId);
|
||||
void trim(char *s);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
@@ -209,11 +210,13 @@ void publishMin()
|
||||
//digitalWrite(LED_BLUE, HIGH);
|
||||
if(!isnan(temp)){
|
||||
dtostrf(temp, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"smallroom/temp", 0, false, strFVal);
|
||||
//client.publish(TOPIC"smallroom/temp", strFVal);
|
||||
}
|
||||
if(!isnan(rel_hum)){
|
||||
dtostrf(rel_hum, 6, 1, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish(TOPIC"smallroom/rel_hum", 0, false, strFVal);
|
||||
//client.publish(TOPIC"smallroom/rel_hum", strFVal);
|
||||
}
|
||||
@@ -240,11 +243,13 @@ void publishSec()
|
||||
//digitalWrite(LED_GREEN, HIGH);
|
||||
if(!isnan(temp)){
|
||||
dtostrf(temp, 7, 3, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish("/hometest/smallroom/temp", 0, false, strFVal);
|
||||
//client.publish("/hometest/smallroom/temp", strFVal);
|
||||
}
|
||||
if(!isnan(rel_hum)){
|
||||
dtostrf(rel_hum, 7, 3, strFVal);
|
||||
trim(strFVal);
|
||||
mqttClient.publish("/hometest/smallroom/rel_hum", 0, false, strFVal);
|
||||
//client.publish("/hometest/smallroom/rel_hum", strFVal);
|
||||
}
|
||||
@@ -332,4 +337,32 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
||||
}
|
||||
|
||||
void onMqttPublish(uint16_t packetId) {
|
||||
}
|
||||
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';
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ void onMqttSubscribe(uint16_t packetId, uint8_t qos);
|
||||
void onMqttUnsubscribe(uint16_t packetId);
|
||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
|
||||
void onMqttPublish(uint16_t packetId);
|
||||
void trim(char *s);
|
||||
|
||||
leds bled(LED_B, 300, true);
|
||||
|
||||
@@ -277,17 +278,20 @@ void loop() {
|
||||
// Serial.println("Temp: " + String(temp));
|
||||
// Serial.println("Hum: " + String(hum));
|
||||
dtostrf(temp, 6, 1, s);
|
||||
trim(s);
|
||||
bled.start();
|
||||
mqttClient.publish(TOPIC"temp", 1, false, s);
|
||||
}
|
||||
if(hum != 0.0f){
|
||||
dtostrf(hum, 6, 1, s);
|
||||
trim(s);
|
||||
mqttClient.publish(TOPIC"hum", 1, false, s);
|
||||
//sendDataI(msgLight, LightLev);
|
||||
//minuts = 0;
|
||||
}
|
||||
bled.start();
|
||||
dtostrf(cRun / 60000.0, 6, 1, s);
|
||||
trim(s);
|
||||
mqttClient.publish(TOPIC"mins", 1, false, s);
|
||||
itoa(WiFi.RSSI(), s, 10);
|
||||
mqttClient.publish(TOPIC"RSSI", 1, false, s);
|
||||
@@ -461,3 +465,32 @@ void onMqttPublish(uint16_t packetId) {
|
||||
// Serial.println(packetId);
|
||||
//g_led.start();
|
||||
}
|
||||
|
||||
void trim(char *s)
|
||||
{
|
||||
// удаляем пробелы и табы с начала строки:
|
||||
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';
|
||||
}
|
||||
}
|
||||
17
ESP_MidRoom/.vscode/extensions.json
vendored
17
ESP_MidRoom/.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"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -26,3 +26,4 @@ uint32_t co2;
|
||||
bool firstRun;
|
||||
float p, t, h;
|
||||
int light, lightPrev;
|
||||
void trim(char *s);
|
||||
@@ -232,9 +232,11 @@ void loop() {
|
||||
itoa(adc, v, 10);
|
||||
mqttClient.publish(TOPIC"/light", 1, false, v);
|
||||
dtostrf(t, 5, 1,v);
|
||||
trim(v);
|
||||
mqttClient.publish(TOPIC"/temp", 1, false, v);
|
||||
//Serial1.println("Publish1");
|
||||
dtostrf(h, 5, 1,v);
|
||||
trim(v);
|
||||
mqttClient.publish(TOPIC"/humid", 1, false, v);
|
||||
//Serial1.println("Publish2");
|
||||
if(firstRun){
|
||||
@@ -250,6 +252,7 @@ void loop() {
|
||||
}
|
||||
else if(minCnt % 20 == 0){
|
||||
dtostrf(millis() / 60000.0, 7, 2, v);
|
||||
trim(v);
|
||||
//ultoa(millis(), v, 10);
|
||||
if(mqttClient.connected()){
|
||||
g_led.start();
|
||||
@@ -347,4 +350,32 @@ void onMqttPublish(uint16_t packetId) {
|
||||
//g_led.start();
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
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';
|
||||
}
|
||||
}
|
||||
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';
|
||||
}
|
||||
}
|
||||
17
VT_ESP8266/.vscode/extensions.json
vendored
17
VT_ESP8266/.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"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user