crankyoldgit / IRremoteESP8266

Infrared remote library for ESP8266/ESP32: send and receive infrared signals with multiple protocols. Based on: https://github.com/shirriff/Arduino-IRremote/
GNU Lesser General Public License v2.1
2.98k stars 832 forks source link

IRremoteESP8266 cannot switch off SAMSUNG AC #604

Closed kalpakchiev closed 5 years ago

kalpakchiev commented 5 years ago

Dear Sir,

So far I can set the temperature, fan speed, mode and turn it on, but I have never managed to switch Samsung AC off.

Please kindly advice how to switch it off?

Version/revison of the library used

IRremoteESP8266.h v2.5.4

Actual behavior

In both cases it sends the code for on For example: if the AC is off and I send ac.off(); ac.send(); it turns on. if it is on and I send ac.off(); ac.send(); it just beeps.

Similar code works properly with a Toshiba AC

bool              ButtonState          =   false;
const int         buttonPin1           =   5;
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Samsung.h>
const uint16_t kIrLed = 4;  // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRSamsungAc ac(kIrLed);  // Set the GPIO to be used for sending messages.

void setup() {
  Serial.begin(115200);
  Serial.println(" ");
  pinMode(buttonPin1,     INPUT_PULLUP);
  Serial.print("READY : "); Serial.println(millis());
  ac.begin();
}

void loop() {
  ButtonState = digitalRead(buttonPin1);

    if (ButtonState == 0)
    {
      Serial.println("Switch it On : ");
      ac.on();
      ac.setFan(kSamsungAcFanAuto);
      ac.setMode(kSamsungAcHeat);
      ac.setTemp(28);
      Serial.println("AC ON, Fan AUTO, Heat mode, 28°C");
      ac.send();
    }
    else
    {
      Serial.println("Switch it Off : ");
      ac.off();
      Serial.println("AC OFF");
      ac.send();
    }
  }
}
crankyoldgit commented 5 years ago

@kalpakchiev I believe you need to use ac.sendExtended(); when doing power changes. See https://github.com/markszabo/IRremoteESP8266/blob/master/examples/ControlSamsungAC/ControlSamsungAC.ino#L92 for an example.

If that doesn't work, please let me know and supply a IRrecvDumpV2 capture of a valid "off" signal from the actual remote that best matches the settings in your example. That way I can debug what might be the cause of the issue.

crankyoldgit commented 5 years ago

And also see: https://github.com/markszabo/IRremoteESP8266/blob/master/src/ir_Samsung.cpp#L266

crankyoldgit commented 5 years ago

FYI'ing @Hollako who also has a samsung a/c and used the code, so may also be able to help.

kalpakchiev commented 5 years ago

Thanks for the prompt response.

Last night I tried ac.sendExtended(); , but unfortunately with no success. I ended using raw. With raw it works.

uint16_t SendOFF[349] = {642, 17730,  3056, 8916,  542, 448, 552, 1440, 552, 444,
                         552, 444,  552, 444,  552, 440,  556, 440,  556, 440,  556,
                         1436,  552, 444,  552, 444,  552, 1440,  548, 470,  526, 1464,
                         470, 526,  516, 1470,  552, 1440,  552, 1440,  550, 1436,
                         556, 1434,  552, 444,  552, 444,  552, 444,  552, 442, 552,
                         444,  546, 470,  526, 470,  526, 470,  470, 524,  518, 474,
                         548, 448,  552, 444,  552, 442,  552, 444,  550, 444,  552,
                         440,  556, 440,  556, 438,  556, 440,  552, 442,  552, 444,
                         552, 442,  552, 444,  550, 470,  526, 466,  524, 470,  470,
                         524,  470, 524,  518, 476,  548, 444,  552, 444,  556, 440,
                         552, 442,  552, 444,  550, 1436,  556, 1436,  552, 2946,
                         3026, 8918,  550, 1440,  552, 444,  548, 468,  526, 468,
                         470, 526,  470, 526,  542, 452,  548, 444,  552, 1440,  550,
                         444,  552, 444,  552, 1436,  556, 438,  552, 442,  552, 1440,
                         552, 1440,  552, 1460,  526, 1464,  470, 1516,  548, 1444, 552,
                         444,  552, 442,  552, 444,  552, 438,  556, 440,  556, 440, 552,
                         444,  552, 444,  552, 444,  552, 444,  552, 444,  548, 448,  546,
                         470,  526, 468,  526, 470,  470, 524,  520, 470,  548, 448,  552,
                         444,  552, 444,  552, 444,  552, 444,  552, 438,  556, 440,  556,
                         438,  552, 444,  552, 442,  552, 444,  552, 444,  552, 444,  552,
                         470,  526, 466,  526, 470,  470, 524,  518, 478,  546, 448,  552,
                         2920,  3052, 8916,  552, 1434,  556, 440,  556, 438,  552, 444,
                         552, 442,  552, 442,  552, 442,  552, 444,  548, 1444,  548, 470,
                         526, 470,  522, 1466,  470, 1520,  548, 1438,  556, 1436,  552,
                         1440,  552, 442,  552, 1436,  552, 1440,  552, 1440,  552, 442,
                         552, 470,  522, 1466,  526, 1466,  470, 1516,  552, 444,  552, 442,
                         552, 444,  552, 1436,  556, 1436,  552, 1440,  550, 444,  552, 444,
                         552, 444,  548, 448,  546, 448,  548, 470,  526, 1462,  474, 1518,
                         548, 1440,  552, 1438,  556, 440,  550, 444,  552, 444,  552, 444,
                         552, 440,  556, 1436,  552, 444,  552, 444,  552, 444,  550, 470,
                         522, 470,  524, 470,  470, 524,  518, 1474,  548, 1440,  556
                        };

uint16_t SendON[349] = {638, 17808,  3056, 8912,  552, 444,  552, 1440,  552, 444,
                        552, 440,  556, 440,  556, 440,  556, 440,  552, 444,  552, 1440,
                        552, 444,  552, 442,  552, 1462,  526, 470,  526, 470,  472, 524,
                        544, 1444,  552, 1440,  552, 1434,  556, 1434,  552, 1440,  552,
                        442,  552, 444,  550, 444,  552, 442,  552, 444,  548, 448,  546,
                        468,  526, 468,  526, 468,  470, 524,  544, 452,  548, 444,  552,
                        444,  550, 444,  552, 442,  552, 442,  552, 444,  552, 440,  556,
                        440,  556, 438,  556, 438,  552, 444,  552, 448,  546, 448,  546,
                        470,  526, 470,  470, 524,  470, 520,  522, 474,  548, 448,  552,
                        444,  552, 444,  552, 1440,  552, 1434,  556, 1436,  556, 1436,
                        550, 2944,  3028, 8922,  546, 1440,  552, 468,  526, 470,  470,
                        520,  476, 520,  546, 448,  548, 448,  552, 444,  552, 1436,  556,
                        440,  556, 440,  552, 1438,  552, 444,  552, 444,  552, 1440,  552,
                        1438,  548, 1466,  526, 1466,  516, 1474,  548, 1440,  552, 442,
                        556, 438,  552, 444,  552, 444,  552, 444,  552, 444,  552, 444,
                        552, 444,  552, 444,  550, 444,  548, 448,  548, 470,  526, 470,
                        526, 470,  470, 524,  518, 478,  542, 448,  552, 444,  552, 444,
                        552, 444,  552, 444,  552, 442,  552, 444,  552, 440,  556, 440,
                        550, 444,  552, 448,  548, 448,  548, 448,  548, 468,  526, 468,
                        526, 468,  470, 522,  470, 524,  548, 446,  548, 448,  552, 2918,
                        3052, 8916,  552, 1440,  552, 442,  552, 438,  556, 440,  552,
                        444,  552, 448,  546, 448,  548, 446,  548, 1466,  526, 470,
                        470, 520,  474, 1516,  546, 1444,  552, 442,  552, 1440,  552,
                        1434,  556, 438,  552, 1440,  552, 1440,  552, 1438,  552, 444,
                        550, 470,  522, 1466,  470, 1520,  518, 1474,  546, 448,  548,
                        444,  556, 438,  556, 1434,  552, 1438,  552, 1436,  556, 444,
                        552, 444,  546, 448,  546, 448,  546, 470,  526, 468,  526, 1466,
                        470, 1516,  548, 1444,  552, 1438,  552, 444,  550, 440,  556, 440,
                        556, 438,  552, 444,  552, 1440,  552, 444,  550, 444,  552, 444,
                        548, 470,  526, 470,  470, 1522,  516, 1470,  552, 1440,  552,
                        1440,  552
                       };

bool              ButtonState          =   false;
bool              OldButtonState       =   false;
const int         buttonPin1           =   5;
//int               InputChanged         =   0;
//int POWER, BEEP, CLEAN, QUIET, FAN, MODE, SWING, TEMP;
#include "MyButton.h"

#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Samsung.h>
const uint16_t kIrLed = 4;  // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRSamsungAc ac(kIrLed);  // Set the GPIO to be used for sending messages.
IRsend irsend(kIrLed);  // Set the GPIO to be used to sending the message.
//https://github.com/markszabo/IRremoteESP8266/issues

void setup() {

  Serial.begin(115200);
  Serial.println(" ");
  //  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin1,     INPUT_PULLUP);
  //    attachInterrupt(buttonPin1, MyCheckButton, CHANGE);
  Serial.print("READY : "); Serial.println(millis());
  ac.begin();
  //  POWER  = ac.getPower();   Serial.print("POWER : "); Serial.println(POWER);
  //  BEEP   = ac.getBeep();    Serial.print("BEEP  : "); Serial.println(BEEP);
  //  CLEAN  = ac.getClean();   Serial.print("CLEAN : "); Serial.println(CLEAN);
  //  QUIET  = ac.getQuiet();   Serial.print("QUIET : "); Serial.println(QUIET);
  //  FAN    = ac.getFan();     Serial.print("FAN   : "); Serial.println(FAN);
  //  MODE   = ac.getMode();    Serial.print("MODE  : "); Serial.println(MODE);
  //  SWING  = ac.getClean();   Serial.print("SWING : "); Serial.println(SWING);
  //  TEMP   = ac.getTemp();    Serial.print("TEMP : "); Serial.println(TEMP);
//  ac.setBeep  (true);
}

void loop() {
  ButtonState = digitalRead(buttonPin1);

  if (ButtonState == !OldButtonState) {
    Serial.println("Door change ! ");
    OldButtonState = ButtonState; delay(5000);
    ButtonState = digitalRead(buttonPin1);

    if (ButtonState == 0)
    { Serial.println("Switch it On : ");
      ac.setPower (true);
      ac.setBeep  (true);
      ac.setClean (true);
      ac.setQuiet (true);
      ac.setFan   (kSamsungAcFanAuto);
      ac.setMode  (kSamsungAcHeat);
      ac.setSwing (true);
      ac.setTemp  (28);
      ac.on();
//      ac.sendExtended     ();
      ac.send     ();
      checkState();
    }
    else
    { Serial.println("Switch it Off : ");
    ac.setBeep  (true);ac.send     ();//ac.sendExtended     ();
      irsend.sendRaw(SendOFF, 349, 38); delay(200);
    }
  }
}

void checkState() {
  Serial.printf("  %s\n", ac.toString().c_str());
  unsigned char* ir_code = ac.getRaw();
  Serial.print("IR Code: 0x");
  for (uint8_t i = 0; i < kSamsungACSectionLength; i++)
    Serial.printf("%02X", ir_code[i]);
  Serial.println();
}

> On 25 Jan 2019, at 1:05, David Conran <notifications@github.com> wrote:
> 
> @kalpakchiev <https://github.com/kalpakchiev> I believe you need to use ac.sendExtended(); when doing power changes. See https://github.com/markszabo/IRremoteESP8266/blob/master/examples/ControlSamsungAC/ControlSamsungAC.ino#L92 <https://github.com/markszabo/IRremoteESP8266/blob/master/examples/ControlSamsungAC/ControlSamsungAC.ino#L92> for an example.
> 
> If that doesn't work, please let me know and supply a IRrecvDumpV2 capture of a valid "off" signal from the actual remote that best matches the settings in your example. That way I can debug what might be the cause of the issue.
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub <https://github.com/markszabo/IRremoteESP8266/issues/604#issuecomment-457392162>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJqoIPQEQut_gdrv5DzfeuSlD6yj3EgVks5vGjw7gaJpZM4aRVNB>.
> 
crankyoldgit commented 5 years ago

Thanks for the report & data. I'll try to look into it soon to work out what the issue might be.

crankyoldgit commented 5 years ago

FYI, in your supplied code, you probably want to substitute kSamsungACSectionLength with kSamsungACStateLength.

kalpakchiev commented 5 years ago

With:

" for (uint8_t i = 0; i < kSamsungACStateLength; i++) "

the sketch does not compile.

“ 'kSamsungACStateLength' was not declared in this scope "

With kSamsungACSectionLength it compiles and print correctly

On 25 Jan 2019, at 8:29, David Conran notifications@github.com wrote:

kSamsungACStateLength

crankyoldgit commented 5 years ago

Sorry, it should be: kSamsungAcStateLength from https://github.com/markszabo/IRremoteESP8266/blob/master/src/IRremoteESP8266.h#L371

P.S. That won't effect the send/sendExtended issue. It's just a bug in your code I noticed. I haven't looked at the raw data yet.

crankyoldgit commented 5 years ago

I've found a number of issues with the extended message creation/decoding. I'll upload some improvements later, but the main issue is the checksum calculation doesn't work for these extended messages. Until we work that out, extended messages won't work via the Class methods.

kalpakchiev commented 5 years ago

Thanks for the update.

Currently there are sample sketches only for some of the supported AC models. Maybe it worths to consider adding sample sketches for each of the supported AC models.

crankyoldgit commented 5 years ago

Some of the improvements have been included in the new v2.5.5 release of the library.

dresende commented 5 years ago

I'm using v2.5.6 and the issue still stands, or at least I still cannot turn off a Samsung A/C.

Hollako commented 5 years ago

Hello Dresende,

I have a Samsung AC using the same IRremote library, and i am able to turn off the Samsung AC but with a small workaround for the Power commands. here is below the commands that should be used.

IRsend ACirsend (IR_LED); uint8_t stateoff[21] = {0x02, 0xB2, 0x0F, 0x00, 0x00, 0x00, 0xC0, 0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xFF, 0x71, 0x80, 0x11, 0xC0}; uint8_t stateon[21] = {0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE2, 0xFE, 0x71, 0x80, 0x11, 0xF0};

To turn it ON you should send: ACirsend.sendSamsungAC(stateon, 21); To turn it OFF you should send: ACirsend.sendSamsungAC(stateoff, 21);

Regards.

dresende commented 5 years ago

Thank you @Hollako, will try this tomorrow and report back 👍

crankyoldgit commented 5 years ago

@dresende Yes, I know it isn't fixed, though thank for confirming it. I haven't yet been able to workout the checksum calculations required for an extended message. Hence the issue/bug is still open. The only workaround at present is to manually play a known-good state for doing the on/off as @Hollako has suggested.

dresende commented 5 years ago

Works perfectly 😃

crankyoldgit commented 5 years ago

FYI, The changes mentioned above have been include in v2.6.1 of this library, which has just been released.