Quellcode durchsuchen

consolidate redundant sml energy fields

Thomas Buck vor 4 Monaten
Ursprung
Commit
7211a8d1ca
2 geänderte Dateien mit 36 neuen und 14 gelöschten Zeilen
  1. 2
    3
      src/lora.cpp
  2. 34
    11
      src/smart_meter.cpp

+ 2
- 3
src/lora.cpp Datei anzeigen

@@ -133,7 +133,6 @@ static void lora_rx(void) {
133 133
 static bool lora_tx(enum lora_sml_type type, double value) {
134 134
     bool tx_legal = millis() > (last_tx + minimum_pause);
135 135
     if (!tx_legal) {
136
-        //debug.printf("Legal limit, wait %i sec.\n", (int)((minimum_pause - (millis() - last_tx)) / 1000) + 1);
137 136
         return false;
138 137
     }
139 138
 
@@ -145,13 +144,14 @@ static bool lora_tx(enum lora_sml_type type, double value) {
145 144
     uint8_t *data = (uint8_t *)&msg;
146 145
     const size_t len = sizeof(struct lora_sml_msg);
147 146
 
147
+    debug.printf("TX [%d] (%lu) ", data[0], len);
148
+
148 149
 #ifdef LORA_XOR_KEY
149 150
     for (size_t i = 0; i < len; i++) {
150 151
         data[i] ^= LORA_XOR_KEY[i];
151 152
     }
152 153
 #endif
153 154
 
154
-    debug.printf("TX [%d] (%lu) ", data[0], len);
155 155
     radio.clearDio1Action();
156 156
 
157 157
     heltec_led(LORA_LED_BRIGHTNESS);
@@ -318,7 +318,6 @@ void lora_run(void) {
318 318
         return;
319 319
     }
320 320
 
321
-    // If a packet was received, display it and the RSSI and SNR
322 321
     if (rx_flag) {
323 322
         rx_flag = false;
324 323
 

+ 34
- 11
src/smart_meter.cpp Datei anzeigen

@@ -115,27 +115,19 @@ void sml_run(void) {
115 115
 
116 116
         if (!isnan(SumWh)) {
117 117
             debug.printf("Sum: %14.3lf Wh\n", SumWh);
118
-#ifdef FEATURE_LORA
119
-            lora_sml_send(LORA_SML_SUM_WH, SumWh, counter);
120
-#endif // FEATURE_LORA
121 118
         }
122 119
 
123 120
         if (!isnan(T1Wh)) {
124 121
             debug.printf(" T1: %14.3lf Wh\n", T1Wh);
125
-#ifdef FEATURE_LORA
126
-            lora_sml_send(LORA_SML_T1_WH, T1Wh, counter);
127
-#endif // FEATURE_LORA
128 122
         }
129 123
 
130 124
         if (!isnan(T2Wh)) {
131 125
             debug.printf(" T2: %14.3lf Wh\n", T2Wh);
132
-#ifdef FEATURE_LORA
133
-            lora_sml_send(LORA_SML_T2_WH, T2Wh, counter);
134
-#endif // FEATURE_LORA
135 126
         }
136 127
 
137 128
         if (!isnan(SumW)) {
138 129
             debug.printf("Sum: %14.3lf W\n", SumW);
130
+
139 131
 #ifdef FEATURE_LORA
140 132
             lora_sml_send(LORA_SML_SUM_W, SumW, counter);
141 133
 #endif // FEATURE_LORA
@@ -150,6 +142,7 @@ void sml_run(void) {
150 142
 
151 143
         if (!isnan(L2W)) {
152 144
             debug.printf(" L2: %14.3lf W\n", L2W);
145
+
153 146
 #ifdef FEATURE_LORA
154 147
             lora_sml_send(LORA_SML_L2_W, L2W, counter);
155 148
 #endif // FEATURE_LORA
@@ -157,16 +150,46 @@ void sml_run(void) {
157 150
 
158 151
         if (!isnan(L3W)) {
159 152
             debug.printf(" L3: %14.3lf W\n", L3W);
153
+
160 154
 #ifdef FEATURE_LORA
161 155
             lora_sml_send(LORA_SML_L3_W, L3W, counter);
162 156
 #endif // FEATURE_LORA
163 157
         }
164 158
 
159
+        debug.println();
160
+
165 161
 #ifdef FEATURE_LORA
162
+        // the power readings (Watt) are just sent as is, if available.
163
+        // the energy readings are consolidated if possible, to avoid
164
+        // unneccessary data transmission
165
+        if ((!isnan(SumWh)) && (!isnan(T1Wh))
166
+                && (fabs(SumWh - T1Wh) < 0.1)
167
+                && ((isnan(T2Wh)) || (fabs(T2Wh) < 0.1))) {
168
+            // (SumWh == T1Wh) && ((T2Wh == 0) || (T2Wh == NAN))
169
+            // just send T1Wh
170
+            lora_sml_send(LORA_SML_T1_WH, T1Wh, counter);
171
+        } else if ((!isnan(SumWh)) && (!isnan(T2Wh))
172
+                && (fabs(SumWh - T2Wh) < 0.1)
173
+                && ((isnan(T1Wh)) || (fabs(T1Wh) < 0.1))) {
174
+            // (SumWh == T2Wh) && ((T1Wh == 0) || (T1Wh == NAN))
175
+            // just send T2Wh
176
+            lora_sml_send(LORA_SML_T2_WH, T2Wh, counter);
177
+        } else {
178
+            // just do normal sending if available
179
+            if (!isnan(SumWh)) {
180
+                lora_sml_send(LORA_SML_SUM_WH, SumWh, counter);
181
+            }
182
+            if (!isnan(T1Wh)) {
183
+                lora_sml_send(LORA_SML_T1_WH, T1Wh, counter);
184
+            }
185
+            if (!isnan(T2Wh)) {
186
+                lora_sml_send(LORA_SML_T2_WH, T2Wh, counter);
187
+            }
188
+        }
189
+
190
+        // update own battery state with each sml readout
166 191
         lora_sml_send(LORA_SML_BAT_V, lora_get_mangled_bat(), counter);
167 192
 #endif // FEATURE_LORA
168
-
169
-        debug.println();
170 193
     }
171 194
 }
172 195
 

Laden…
Abbrechen
Speichern