Skip to content

Commit 4110ec8

Browse files
committed
sleep after fatal read meter error
1 parent 4e06f92 commit 4110ec8

12 files changed

+34
-5
lines changed

WEBFiles/protect/setmeter.htm

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ <h2 class="title">Настройка</h2>
3939
<td class="label">Кол-во повторов после ошибки:</td>
4040
<td><input name='cfg_glo_pwmt_cerr' maxlength='10' value='~cfg_glo_pwmt_cerr~'></td>
4141
</tr>
42+
<tr>
43+
<td class="label">Пауза после неустранимой ошибки:</td>
44+
<td><input name='cfg_glo_sleep_err' maxlength='10' value='~cfg_glo_sleep_err~'> сек</td>
45+
</tr>
4246
<tr>
4347
<td class="label">Кол-во повторяющихся ошибок для отключения питания (GPIO0+GPIO2=0):</td>
4448
<td><input title='используется внешний мк для сброса питания (WatchdogESP01), 255 - выкл.' name='cfg_glo_pwmt_rbt' maxlength='10' value='~cfg_glo_pwmt_rbt~'></td>

app/include/power_meter.h

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef struct {
5151
char sntp_server[20];
5252
uint32 Fram_Pos; // start pos of
5353
uint8 repeated_errors_thr;// power restart required after threshold is reached
54+
uint16 sleep_after_series_errors; // sec
5455
} CFG_GLO;
5556
CFG_GLO __attribute__((aligned(4))) cfg_glo;
5657

@@ -83,6 +84,7 @@ uint32 Web_ChMD; // ~ChMD~, Chart max days for historyall.htm
8384
uint8 Web_ShowBy; // ~ShowBy~ : 0 - all, 1 - by day, 2 - by hour
8485
uint32 Fram_SaveCountdown;
8586
uint8 Fram_halted;
87+
uint16 sleep_after_errors_cnt; // sec
8688
//
8789
void user_initialize(uint8 index) ICACHE_FLASH_ATTR;
8890
void FRAM_Store_Init(void) ICACHE_FLASH_ATTR;

app/include/tcp2uart.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ uint32_t UART0_IrDA_RX_CLK; // will be set after TX all data
5656
void uart0_set_flow(bool flow_en) ICACHE_FLASH_ATTR;
5757
void update_rts0(void) ICACHE_FLASH_ATTR;
5858
void update_mux_uart0(void) ICACHE_FLASH_ATTR;
59+
void disable_mux_uart0(void) ICACHE_FLASH_ATTR;
5960
#endif
6061
void update_mux_txd1(void) ICACHE_FLASH_ATTR;
6162
void set_uartx_invx(uint8 uartn, uint8 set, uint32 bit_mask) ICACHE_FLASH_ATTR;

app/user/mercury.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ void ICACHE_FLASH_ATTR pwmt_read_time_array(uint8 arr)
310310
pwmt_send_to_uart();
311311
}
312312

313-
void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every PWMT_READ_TIMEOUT
313+
void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_read_timeout
314314
{
315-
if(uart_queue_len) {
315+
if(uart_queue_len && !sleep_after_errors_cnt) {
316316
uint32 dt = system_get_time() - uart_queue[0].time;
317317
uint8 fl = uart_queue[0].flag;
318318
if(fl == UART_SEND_WAITING) {
@@ -366,17 +366,20 @@ void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every PWMT_READ_TIM
366366
uart_queue[0].flag = UART_SEND_WAITING;
367367
uart_queue[0].time = system_get_time();
368368
} else {
369+
pwmt_repeat_on_error_cnt = cfg_glo.pwmt_on_error_repeat_cnt;
369370
dbg_printf("Eu%u,%u:%d,%d=", dbg_next_time(), dt, pwmt_last_response, UART_Buffer_idx);
370371
uint8 jjj;
371372
for(jjj = 0; jjj < uart_queue[0].len; jjj++) {
372373
dbg_printf("%02X", uart_queue[0].buffer[jjj]);
373374
}
374375
//dbg_printf("\n");
375-
376376
dbg_printf(", del\n");
377377
uart_queue[0].flag = UART_DELETED;
378-
pwmt_send_to_uart();
379-
pwmt_repeat_on_error_cnt = cfg_glo.pwmt_on_error_repeat_cnt;
378+
if(cfg_glo.sleep_after_series_errors) { // UART0 off
379+
sleep_after_errors_cnt = cfg_glo.sleep_after_series_errors;
380+
uart_drv_close();
381+
disable_mux_uart0();
382+
} else pwmt_send_to_uart();
380383
}
381384
}
382385
}
@@ -517,6 +520,7 @@ void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every PWMT_READ_TIM
517520

518521
void ICACHE_FLASH_ATTR pwmt_request_timer_func(void) // call every: cfg_glo.request_period
519522
{
523+
if(sleep_after_errors_cnt) return;
520524
uint8 autosend = !uart_queue_len;
521525
if((uart_queue_len == 0 && pwmt_connect_status == PWMT_NOT_CONNECTED)
522526
|| (pwmt_last_response == 6 && pwmt_connect_status != PWMT_CONNECTING)) {

app/user/power_meter.c

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "sdk/libmain.h"
2121
#include "driver/eeprom.h"
2222
#include "hw/gpio_register.h"
23+
#include "tcp2uart.h"
2324
#include "wifi.h"
2425
#include "wifi_events.h"
2526
#include "power_meter.h"
@@ -124,6 +125,10 @@ void ICACHE_FLASH_ATTR update_cnt_timer_func(void) // repeat every 1 sec
124125
}
125126
}
126127
}
128+
if(sleep_after_errors_cnt) if(--sleep_after_errors_cnt == 0) {
129+
update_mux_uart0();
130+
pwmt_send_to_uart();
131+
}
127132
if(pwmt_cur.Time == 0) return; else pwmt_cur.Time++;
128133
if(!(pwmt_cur.Time >= fram_store.ByMin.LastTime + TIME_STEP_SEC) || FRAM_Status) return; // dont passed 1 min
129134

@@ -310,6 +315,7 @@ void ICACHE_FLASH_ATTR user_initialize(uint8 index)
310315
Web_ShowBy = 0;
311316
Fram_SaveCountdown = FRAM_SAVE_PERIOD;
312317
Fram_halted = 0;
318+
sleep_after_errors_cnt = 0;
313319
#if DEBUGSOO > 3
314320
os_printf("FSize=%u, CntSize=%u\n", cfg_glo.Fram_Size, ArrayOfCntsSize);
315321
#endif

app/web/uart_tcp.c

+9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ void ICACHE_FLASH_ATTR update_rts0(void)
130130
#endif
131131
}
132132
}
133+
134+
void ICACHE_FLASH_ATTR disable_mux_uart0(void)
135+
{
136+
MUX_TX_UART0 = (1<<GPIO_MUX_FUN_BIT0) | (1<<GPIO_MUX_FUN_BIT1) | (1<<GPIO_MUX_PULLDOWN_BIT); // VAL_MUX_TX_UART0_OFF;
137+
GPIO_OUT_W1TC = (1<<1); // GPIO1
138+
MUX_RX_UART0 = VAL_MUX_RX_UART0_OFF;
139+
// MUX_RTS_UART0 = VAL_MUX_RTS_UART0_OFF;
140+
// MUX_CTS_UART0 = VAL_MUX_CTS_UART0_OFF;
141+
}
133142
//=============================================================================
134143
// Обновить mux выводов UART0
135144
// update_mux_txd1()

app/web/web_int_callbacks.c

+1
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ void ICACHE_FLASH_ATTR web_int_callback(TCP_SERV_CONN *ts_conn, uint8 *cstr)
11031103
else ifcmp("time_maxmism") tcp_puts("%u", cfg_glo.TimeMaxMismatch);
11041104
else ifcmp("refresh_t") tcp_puts("%u", cfg_glo.page_refresh_time);
11051105
else ifcmp("req_period") tcp_puts("%u", cfg_glo.request_period);
1106+
else ifcmp("sleep_err") tcp_puts("%u", cfg_glo.sleep_after_series_errors);
11061107
else ifcmp("pwmt_") {
11071108
cstr += 5;
11081109
ifcmp("rtout") tcp_puts("%u", cfg_glo.pwmt_read_timeout);

app/web/web_int_vars.c

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ xfram_save: if(!Fram_halted) eeprom_write_block(cfg_glo.Fram_Pos, (uint8 *)&fra
364364
if(reinit) irda_init();
365365
}
366366
else ifcmp("time_maxmism") cfg_glo.TimeMaxMismatch = val;
367+
else ifcmp("sleep_err") cfg_glo.sleep_after_series_errors = val;
367368
else ifcmp("pwmt_") {
368369
cstr += 5;
369370
ifcmp("tout") cfg_glo.pwmt_response_timeout = val;

bin/0x00000.bin

16 Bytes
Binary file not shown.

bin/0x07000.bin

192 Bytes
Binary file not shown.

bin/firmware.bin

192 Bytes
Binary file not shown.

webbin/web_vars.txt

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ cfg_glo_pwmt_rtout
337337
cfg_glo_pwmt_tout
338338
cfg_glo_pwmt_derr
339339
cfg_glo_pwmt_cerr
340+
cfg_glo_sleep_err
340341
cfg_glo_pwmt_rbt
341342
cfg_glo_T1St
342343
cfg_glo_T1En

0 commit comments

Comments
 (0)