Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't send a data value of 0 via IR module. #2751

Closed
crankyoldgit opened this issue May 17, 2018 · 1 comment
Closed

Can't send a data value of 0 via IR module. #2751

crankyoldgit opened this issue May 17, 2018 · 1 comment

Comments

@crankyoldgit
Copy link
Contributor

Can't send a data value of 0 via the IR module.

The IR subsystem fails to send a message when the data payload is 0 (zero).

To Reproduce
Send a MQTT message to the irsend module.
e.g.
topic: "cmnd/SONOFF_DEVICE/irsend"
payload: '{"Protocol": "SAMSUNG","Bits":32,"data":0}'
Expected behavior
A Samsung 32bit message with a value of 0 should be transmitted.
e.g. A call of irsend->sendSAMSUNG(0, 32); should be made. It doesn't.

Screenshots
N/A

Additional context
I think the bug is here:
https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/xdrv_02_irremote.ino#L301

        data = strtoul(root[UpperCase_P(parm_uc, PSTR(D_JSON_IR_DATA))], NULL, 0);
        if (protocol && bits && data) {

When data is 0, it evaluates as False in the above if statement.

Most simple fix is to change:

        if (protocol && bits && data) {

to:

        if (protocol && bits) {

Technically a more correct fix is to check if you had a parsing error (you can't do that with strtoul()) and to NOT assume a return value of 0 from strtoul() is a parse error, a str of "0" is valid and a potential value, and a real result of strtoul().

TL;DR: When strtoul() returns zero, it isn't always a failure to convert.

Workarounds:
Specify a value that has the lower bits as zero. e.g. 2^32 which has the lower 32 bits as 0, but the entire value is != 0. e.g. 0b100000000000000000000000000000000

MQTT example of the workaround:

payload: '{"Protocol": "SAMSUNG","Bits":32,"data":0}'  // does nothing
payload: '{"Protocol": "SAMSUNG","Bits":32,"data":4294967296}'  // works (sends a 0 IR message)

Ref:
crankyoldgit/IRremoteESP8266#447 (comment)

@crankyoldgit crankyoldgit changed the title Can't send a data value of 0 via IR modue. Can't send a data value of 0 via IR module. May 17, 2018
@arendst
Copy link
Owner

arendst commented May 17, 2018

I agree. I went for your simple fix and PR

Another solution would be to test for any string length before using strtoul

@arendst arendst closed this as completed May 17, 2018
arendst added a commit that referenced this issue May 17, 2018
5.14.0a
 * Add KNX energy data (#2750)
 * Fix display selection of
un-available GPIO options in Module Configuration webpage (#2718)
 * Fix
IRSend not accepting data value of 0 (#2751)
curzon01 pushed a commit to curzon01/Tasmota that referenced this issue Sep 7, 2018
Ref: Issue arendst#2751

Incorrect assumption that if the result of `strtoul()` is zero (0) it is a parse failure. That's incorrect as the "data" payload could actually be 0.

Ref: crankyoldgit/IRremoteESP8266#447 (comment)
curzon01 pushed a commit to curzon01/Tasmota that referenced this issue Sep 7, 2018
5.14.0a
 * Add KNX energy data (arendst#2750)
 * Fix display selection of
un-available GPIO options in Module Configuration webpage (arendst#2718)
 * Fix
IRSend not accepting data value of 0 (arendst#2751)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants