Giter VIP home page Giter VIP logo

Comments (2)

stefanbode avatar stefanbode commented on July 20, 2024

Yes indeed this is strange code looking without context. The idea was to set it only, if there is a meaningful value inside, but the if clause seems to be wrong. Based on the branching in my configuration dump it can easily happen that on new introduced variables I get a 0 or a FF. In General the clause is ok.

No, now I r member. This is right because this is only on initialization. Does mean if there is e.g. 5 inside do not change because this is configuration setting , but if it is 0 then it is a init. value that needs to be corrected. The clause should only executed if wrong values at boot time are in the configuration. Let’s. Check where your error is. The IF seems to be ok.

from sonoff-tasmota.

roblad avatar roblad commented on July 20, 2024

Hi,

I tested and suggested code is ok in that file but in set command there is an error. Divider must be also set there, I suggest the code in sonoff.ino about line 778 (release o)
RtcSettings.pulse_counter[index -1] keeps the value multiply by Settings.pulse_devider[index -1] and huge variable is needed in my case divider 4100 unsigned long that already has ben set

now the command response and sprinf on www shows correct values, may be there is a possibility some how tu keep proper value in RtcSettings.pulse_counter[index -1] as displayed. For saved value the huge value is also stored. Values need to be extended to payload32.

else if ((CMND_COUNTER == command_code) && (index > 0) && (index <= MAX_COUNTERS)) {
if ((data_len > 0) && (pin[GPIO_CNTR1 + index -1] < 99)) {
//stb mod
RtcSettings.pulse_counter[index -1] = payload32 * Settings.pulse_devider[index -1];
Settings.pulse_counter[index -1] = payload32 * Settings.pulse_devider[index -1];
//stb end
}
//stb mod
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_LVALUE, command, index, (RtcSettings.pulse_counter[index -1]/Settings.pulse_devider[index -1]));
//end
}
else if ((CMND_COUNTERTYPE == command_code) && (index > 0) && (index <= MAX_COUNTERS)) {
if ((payload >= 0) && (payload <= 1) && (pin[GPIO_CNTR1 + index -1] < 99)) {
bitWrite(Settings.pulse_counter_type, index -1, payload &1);
RtcSettings.pulse_counter[index -1] = 0;
Settings.pulse_counter[index -1] = 0;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_NVALUE, command, index, bitRead(Settings.pulse_counter_type, index -1));
}
else if (CMND_COUNTERDEBOUNCE == command_code) {
if ((data_len > 0) && (payload16 < 32001)) {
Settings.pulse_counter_debounce = payload16;
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.pulse_counter_debounce);
}
//STB mod
else if ((CMND_COUNTERDEVIDER == command_code) && (index > 0) && (index <= MAX_COUNTERS)) {
if (data_len > 0) {
unsigned long _counter;
_counter = Settings.pulse_devider[index -1];
Settings.pulse_devider[index -1] = payload16;
RtcSettings.pulse_counter[index -1] = _counter * Settings.pulse_devider[index -1];
}
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_NVALUE, command, index, Settings.pulse_devider[index -1]);
}
//end

from sonoff-tasmota.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.