@@ -251,38 +251,34 @@ void check_limit() {
251
251
const uint16_t max_limit = INVERTER_LIMIT; // unthrottled WR while backfeed is small enough
252
252
const uint16_t min_aMinus = BACKFEED_MIN; // if actual backfeed is lower, inverter gets less limited
253
253
const uint16_t max_aMinus = BACKFEED_MAX; // if actual backfeed is higher, inverter gets more limited
254
-
254
+ const uint16_t min_check_delay_s = 10 ; // high enough to make power calc from counter reliable
255
+ // low enough to limit time with too high backfeed
255
256
static uint32_t uptime = 0 ;
256
257
static uint64_t aMinus = 0 ;
257
258
258
259
uint64_t aMinusW = 0 ;
259
260
260
- static uint32_t update_ms = 0 ;
261
-
262
261
if ( itron.valid == 0x3f ) {
263
262
// we have valid backfeed data
264
- if ( uptime && uptime ! = itron.uptime ) {
265
- // and data was updated since last check
266
- uint32_t delta_t = itron. uptime - uptime;
263
+ uint32_t delta_t = itron.uptime - uptime;
264
+ if ( uptime && delta_t > min_check_delay_s ) {
265
+ // the last check is more than min_check_delay_s ago
267
266
// calculate average backfeed in W from the ever increasing backfeed counter
268
267
// and the elapsed time since last check
269
268
aMinusW = (itron.aMinus - aMinus) * 360 / delta_t ;
270
269
// / syslog.logf(LOG_INFO, "Check: Curr A-: %llu W, dt = %u s", aMinusW, delta_t);
271
270
272
- uint32_t now = millis ();
273
- if ( curr_limit != UINT16_MAX && reachable && (now - update_ms) > 30000 ) {
271
+ if ( curr_limit != UINT16_MAX && reachable ) {
274
272
// only try to change the limit if the current limit is known
275
- // and the inverter is reachable and the last change is more than 30s ago
273
+ // and the inverter is reachable
276
274
if ( aMinusW > max_aMinus && curr_limit > 0 ) {
277
275
// current backfeed is too high and inverter is not yet fully limited
278
- update_ms = now;
279
276
// change of inverter limit to backfeed right in the middle of the desired range
280
277
uint16_t delta = aMinusW - (min_aMinus + max_aMinus)/2 ;
281
278
publish_limit (aMinusW, (curr_limit > delta) ? curr_limit - delta : 0 );
282
279
}
283
280
else if ( aMinusW < min_aMinus && curr_limit < max_limit ) {
284
281
// current backfeed is too low and inverter is not yet fully opened
285
- update_ms = now;
286
282
// change of inverter limit to backfeed right in the middle of the desired range
287
283
uint16_t delta = (min_aMinus + max_aMinus)/2 - aMinusW;
288
284
publish_limit (aMinusW, (curr_limit + delta < max_limit) ? curr_limit + delta : max_limit);
@@ -294,10 +290,9 @@ void check_limit() {
294
290
else {
295
291
// / syslog.logf(LOG_INFO, "Check: current limit %u W not changed, elapsed since update: %u s", curr_limit, (now - update_ms)/1000);
296
292
}
293
+ uptime = itron.uptime ;
294
+ aMinus = itron.aMinus ;
297
295
}
298
-
299
- uptime = itron.uptime ;
300
- aMinus = itron.aMinus ;
301
296
}
302
297
}
303
298
0 commit comments