اطلاعیه

Collapse
No announcement yet.

روشن کردن کولر و تلوزیون با nodemcu

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    روشن کردن کولر و تلوزیون با nodemcu

    سلام
    من یه بورد nodemcu + یه گیرنده ی ir و یه فرستنده ی ir گرفتم
    با کد دریافت irremote که توی گیت هاب بود کد کنترل تلوزیون رو در اوردم(rowdata) بعد اونو جایگذینه نمونه کد ارسال کردم اما هیچ دستگاهی رو نمکیشه با هیچ کدی روشن کرد فقط rowdata ای که تو خود کد ارسال بود به عنوان نمونه تلوزیون رو روشن خاموش میکنه

    کد دریافت:
    کد:
    /*
     * IRremoteESP8266: IRrecvDumpV2 - dump details of IR codes with IRrecv
     * An IR detector/demodulator must be connected to the input kRecvPin.
     *
     * Copyright 2009 Ken Shirriff, http://arcfn.com
     * Copyright 2017-2019 David Conran
     *
     * Example circuit diagram:
     *  https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-receiving
     *
     * Changes:
     *   Version 1.0 October, 2019
     *     - Internationalisation (i18n) support.
     *     - Stop displaying the legacy raw timing info.
     *   Version 0.5 June, 2019
     *     - Move A/C description to IRac.cpp.
     *   Version 0.4 July, 2018
     *     - Minor improvements and more A/C unit support.
     *   Version 0.3 November, 2017
     *     - Support for A/C decoding for some protocols.
     *   Version 0.2 April, 2017
     *     - Decode from a copy of the data so we can start capturing faster thus
     *       reduce the likelihood of miscaptures.
     * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009,
     */
    
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <Arduino.h>
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <IRrecv.h>
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <IRremoteESP8266.h>
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <IRac.h>
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <IRtext.h>
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <IRutils.h>
    
    // ==================== start of TUNEABLE PARAMETERS ====================
    // An IR detector/demodulator is connected to GPIO pin 14
    // e.g. D5 on a NodeMCU board.
    // Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts.
    const uint16_t kRecvPin = 14;
    
    // The Serial connection baud rate.
    // i.e. Status message will be sent to the PC at this baud rate.
    // Try to avoid slow speeds like 9600, as you will miss messages and
    // cause other problems. 115200 (or faster) is recommended.
    // NOTE: Make sure you set your Serial Monitor to the same speed.
    const uint32_t kBaudRate = 115200;
    
    // As this program is a special purpose capture/decoder, let us use a larger
    // than normal buffer so we can handle Air Conditioner remote codes.
    const uint16_t kCaptureBufferSize = 1024;
    
    // kTimeout is the Nr. of milli-Seconds of no-more-data before we consider a
    // message ended.
    // This parameter is an interesting trade-off. The longer the timeout, the more
    // complex a message it can capture. e.g. Some device protocols will send
    // multiple message packets in quick succession, like Air Conditioner remotes.
    // Air Coniditioner protocols often have a considerable gap (20-40+ms) between
    // packets.
    // The downside of a large timeout value is a lot of less complex protocols
    // send multiple messages when the remote's button is held down. The gap between
    // them is often also around 20+ms. This can result in the raw data be 2-3+
    // times larger than needed as it has captured 2-3+ messages in a single
    // capture. Setting a low timeout value can resolve this.
    // So, choosing the best kTimeout value for your use particular case is
    // quite nuanced. Good luck and happy hunting.
    // NOTE: Don't exceed kMaxTimeoutMs. Typically 130ms.
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=if"]#if[/URL]  DECODE_AC
    // Some A/C units have gaps in their protocols of ~40ms. e.g. Kelvinator
    // A value this large may swallow repeats of some protocols
    const uint8_t kTimeout = 50;
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=else"]#else[/URL]    // DECODE_AC
    // Suits most messages, while not swallowing many repeats.
    const uint8_t kTimeout = 15;
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=endif"]#endif[/URL]   // DECODE_AC
    // Alternatives:
    // const uint8_t kTimeout = 90;
    // Suits messages with big gaps like XMP-1 & some aircon units, but can
    // accidentally swallow repeated messages in the rawData[] output.
    //
    // const uint8_t kTimeout = kMaxTimeoutMs;
    // This will set it to our currently allowed maximum.
    // Values this high are problematic because it is roughly the typical boundary
    // where most messages repeat.
    // e.g. It will stop decoding a message and start sending it to serial at
    //      precisely the time when the next message is likely to be transmitted,
    //      and may miss it.
    
    // Set the smallest sized "UNKNOWN" message packets we actually care about.
    // This value helps reduce the false-positive detection rate of IR background
    // noise as real messages. The chances of background IR noise getting detected
    // as a message increases with the length of the kTimeout value. (See above)
    // The downside of setting this message too large is you can miss some valid
    // short messages for protocols that this library doesn't yet decode.
    //
    // Set higher if you get lots of random short UNKNOWN messages when nothing
    // should be sending a message.
    // Set lower if you are sure your setup is working, but it doesn't see messages
    // from your device. (e.g. Other IR remotes work.)
    // NOTE: Set this value very high to effectively turn off UNKNOWN detection.
    const uint16_t kMinUnknownSize = 12;
    
    // Legacy (No longer supported!)
    //
    // Change to `true` if you miss/need the old "Raw Timing[]" display.
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define"]#define[/URL]  LEGACY_TIMING_INFO false
    // ==================== end of TUNEABLE PARAMETERS ====================
    
    // Use turn on the save buffer feature for more complete capture coverage.
    IRrecv irrecv(kRecvPin, kCaptureBufferSize, kTimeout, true);
    decode_results results;  // Somewhere to store the results
    
    // This section of code runs only once at start-up.
    void setup() {
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=if"]#if[/URL]  defined(ESP8266)
      Serial.begin(kBaudRate, SERIAL_8N1, SERIAL_TX_ONLY);
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=else"]#else[/URL]   // ESP8266
      Serial.begin(kBaudRate, SERIAL_8N1);
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=endif"]#endif[/URL]   // ESP8266
      while (!Serial)  // Wait for the serial connection to be establised.
        delay(50);
      Serial.printf("\n" D_STR_IRRECVDUMP_STARTUP "\n", kRecvPin);
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=if"]#if[/URL]  DECODE_HASH
      // Ignore messages with less than minimum on or off pulses.
      irrecv.setUnknownThreshold(kMinUnknownSize);
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=endif"]#endif[/URL]   // DECODE_HASH
      irrecv.enableIRIn();  // Start the receiver
    }
    
    // The repeating section of the code
    void loop() {
      // Check if the IR code has been received.
      if (irrecv.decode(&results)) {
        // Display a crude timestamp.
        uint32_t now = millis();
        Serial.printf(D_STR_TIMESTAMP " : %06u.%03u\n", now / 1000, now % 1000);
        // Check if we got an IR message that was to big for our capture buffer.
        if (results.overflow)
          Serial.printf(D_WARN_BUFFERFULL "\n", kCaptureBufferSize);
        // Display the library version the message was captured with.
        Serial.println(D_STR_LIBRARY "   : v" _IRREMOTEESP8266_VERSION_ "\n");
        // Display the basic output of what we found.
        Serial.print(resultToHumanReadableBasic(&results));
        // Display any extra A/C info if we have it.
        String description = IRAcUtils::resultAcToString(&results);
        if (description.length()) Serial.println(D_STR_MESGDESC ": " + description);
        yield();  // Feed the WDT as the text output can take a while to print.
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=if"]#if[/URL]  LEGACY_TIMING_INFO
        // Output legacy RAW timing info of the result.
        Serial.println(resultToTimingInfo(&results));
        yield();  // Feed the WDT (again)
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=endif"]#endif[/URL]   // LEGACY_TIMING_INFO
        // Output the results as source code
        Serial.println(resultToSourceCode(&results));
        Serial.println();    // Blank line between entries
        yield();             // Feed the WDT (again)
      }
    }

    و کد ارسال:

    کد:
    /*
     * IRremoteESP8266: IRsendGCDemo
     * demonstrates sending Global Cache-formatted IR codes with IRsend
     * Copyright 2009 Ken Shirriff
     * [URL]http://arcfn.com[/URL]
     *
     * Version 0.2 June, 2017
     *   Added helpful comments
     *   Better includes files.
     * Version 0.1 30 March, 2016
     *   Based on Ken Shirriff's IrsendDemo
     *   Version 0.1 July, 2009
     *
     * An IR LED circuit *MUST* be connected to the ESP8266 on a pin
     * as specified by IR_LED below.
     *
     * TL;DR: The IR LED needs to be driven by a transistor for a good result.
     *
     * Suggested circuit:
     *     [URL]https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending[/URL]
     *
     * Common mistakes & tips:
     *   * Don't just connect the IR LED directly to the pin, it won't
     *     have enough current to drive the IR LED effectively.
     *   * Make sure you have the IR LED polarity correct.
     *     See: [URL]https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity[/URL]
     *   * Typical digital camera/phones can be used to see if the IR LED is
     * flashed. Replace the IR LED with a normal LED if you don't have a digital
     * camera when debugging.
     *   * Avoid using the following pins unless you really know what you are doing:
     *     * Pin 0/D3: Can interfere with the boot/program mode & support circuits.
     *     * Pin 1/TX/TXD0: Any serial transmissions from the ESP8266 will
     * interfere.
     *     * Pin 3/RX/RXD0: Any serial transmissions to the ESP8266 will interfere.
     *   * ESP-01 modules are tricky. We suggest you use a module with more GPIOs
     *     for your first time. e.g. ESP-12 etc.
     */
    
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <Arduino.h>
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <IRremoteESP8266.h>
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include"]#include[/URL]  <IRsend.h>
    
    // Codes are in Global Cache format less the emitter ID and request ID.
    // These codes can be found in GC's Control Tower database.
    
    uint16_t Samsung_power_toggle[71] = {
        38000, 1,  1,  170, 170, 20, 63, 20, 63, 20, 63,  20, 20, 20, 20,
        20,    20, 20, 20,  20,  20, 20, 63, 20, 63, 20,  63, 20, 20, 20,
        20,    20, 20, 20,  20,  20, 20, 20, 20, 20, 63,  20, 20, 20, 20,
        20,    20, 20, 20,  20,  20, 20, 20, 20, 63, 20,  20, 20, 63, 20,
        63,    20, 63, 20,  63,  20, 63, 20, 63, 20, 1798};
    
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define"]#define[/URL]  IR_LED 4  // ESP8266 GPIO pin to use. Recommended: 4 (D2).
    
    IRsend irsend(IR_LED);  // Set the GPIO to be used to sending the message.
    
    void setup() {
      irsend.begin();
      Serial.begin(115200);
    }
    
    void loop() {
      Serial.println("Toggling power");
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=if"]#if[/URL]  SEND_GLOBALCACHE
      irsend.sendGC(Samsung_power_toggle, 71);
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=else"]#else[/URL]    // SEND_GLOBALCACHE
      Serial.println("Can't send because SEND_GLOBALCACHE has been disabled.");
    [URL="https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=endif"]#endif[/URL]   // SEND_GLOBALCACHE
      delay(10000);
    }
    کد ارسال بالا کار میکنه اما اگه rowdata رو تغییر بدم دیگه کار نمیکنه


    ممنون میشم راهنماییم کنید
لطفا صبر کنید...
X