stefanbode / Sonoff-Tasmota

Provide ESP8266 based itead Sonoff with Web, MQTT and OTA firmware using Arduino IDE, enhanced with I2C options
GNU General Public License v3.0
127 stars 41 forks source link

Modyfication for pulse counter #15

Closed roblad closed 6 years ago

roblad commented 6 years ago

Hi,

What do you think (or if you can help me) to modyfi counter of pulse.

See that:

https://github.com/arendst/Sonoff-Tasmota/issues/1300

stefanbode commented 6 years ago

In general no big deal to store the counter in RTC memory and maybe also in Flash. But we have to take into consideration how many pulses we expect in which timeframe. Additionally, it is interesting how you want to react on a reboot (accidentally or intended). Is there a requirement to remember the last state. What about power off? is it ok if we remember on 400 pulses and it was 415 when it was shut down on power? Questions to anser: 1.) How many pulses in which timeframe you expect? 2.) Need the pulsescount survive a reboot? (Using RTC memory) 2.) Need the pulsecount survive power off (Using Flash)

stefanbode commented 6 years ago

I do see, that the behaviour is somewhere already in the code. Normally the count will only be reported by the TELEPERIOD (afaik). This will not give you exactly the state when 1L is reached, but you will get an update on the flow, for example, every 10sek.

roblad commented 6 years ago

Hi,

1) Pulses not in timeframe - it could be 10, 100 in the same period of time - it is flow and when tap is open fully or many taps are opened the flow will be different. 2) Currently I have AVR controller where I save value for every 100 L to EPROM. When there is power cut the latest value from EEPROM is taken - correction I send to the AFR through RMF69 and I receive through RMF69. The attache interput have 2 counters 1 is for getting 4100 for each 10 L of water and one is for counting each pulse. 3) I need to keep some last value in eeprom i.e. or RTC memory, but main is a possibility to multiply counter for i.e. 410 pulses for 1 L and result it on MQTT or/and www. The best is to set somewhere the multiplayer in some variable.

PS. Could you give me your e-mail ?

stefanbode commented 6 years ago

Hi, yes stefan_bode at web de. Please see the newest version. introduced a new command counterdevider

roblad commented 6 years ago

Hi, It was tested and:

BTW - Is it possible to define COUNTERDEVIDER i user_config.h ?

I sugest to add/change to : sonoff\xsns_01_counter.ino line 25 uint32_t pulse_devider = COUNTERDEVIDER; in user_config.h line 161

define COUNTERDEVIDER 10 // counter divider or set CounterDevider 1-4

RESULT without changes:

It does not count correctly when I set on type counterType as pulse debaunce for 100 ms

it count as it wants, usualy count each pulse or shows more of 10 20 50.

there was not send to consloe

The "CounterDevider1" was not set from console

After setting CounterDevider1 to 10 starts work.

What do you think about that suggestion:

// STB mode //avoid DIV 0 on unitiialized Settings.pulse_devider[i] = COUNTERDEVIDER; if (Settings.pulse_devider[i] == 0 || Settings.pulse_devider[i] == 65535 ) {Settings.pulse_devider[i] = 1;} // end

it seams to work when I sen in configure COUNTERDEVIDER to 10 (or set fromconsole - without any modyfication of code after setting CounterDevider1 to 10 ), every 10 pulse it gives 1.

Additionaly when on web there is some devider , I sugest add that information to WWW and to MQTT if you can.

And Counter result send every change as tele message or in some other possibility

tele/wemeos/SENSOR = {"Czas":"2017-12-04T21:17:24","Przelacznik1":"OFF","Licznik1":23,"Wej_analogowe0":3}

That is nice to have receive any pulse change to be just send to MQTT :-) the same for i.e. analog read status :-) by execute some command as:

21:24:50 CMD: Status 10 21:24:50 MQT: stat/wemeos/STATUS10 = {"StatusSNS":{"Czas":"2017-12-04T21:24:50","Przelacznik1":"OFF","Licznik1":31,"Wej_analogowe0":3}}

PS

I sent you e-mail with subject:

Tasmota roblad contact github

stefanbode commented 6 years ago

it should be

define D_CMND_COUNTERDEVIDER "CounterDevider"

there is a command, not text to translate, it has CounterDevider1 or CounterDevider2 or CounterDevider3 or CounterDevider4 depends on max_counters I suggested to change it - but I updated the response to #15

yep, there is a reason that command normally should stay in English. Changed back and will be updated with the next sync.

roblad commented 6 years ago

Hi,

Could you try to add other things, and I sent you a mail, could you answer ?

Thanks, RL

stefanbode commented 6 years ago

I saw just one mail from you where you said: hello from monday. no requests

roblad commented 6 years ago

Hi,

I have not received , could yoy try again ?