初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,196 @@
/*************************************************************
Emulate a physical remote via an iOS and Android App.
Copyright Gaurav Barwalia 2020
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on ESP8266 chip.
Note: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right ESP8266 module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/*
// After decoding received below codes
// Power button
18:12:33.993 -> Protocol : NEC
18:12:33.993 -> Code : 0x1FE50AF (32 Bits)
18:12:33.993 -> uint16_t rawData[71] = {9040, 4452, 606, 532, 606, 534, 630, 508, 604, 534, 604, 534, 604, 534, 630, 506, 606, 1646, 632, 1620, 606, 1646, 632, 1620, 630, 1620, 632, 1620, 630, 1620, 606, 1646, 632, 506, 632, 506, 632, 1620, 632, 506, 632, 1620, 632, 506, 632, 508, 632, 506, 632, 506, 632, 1620, 632, 506, 632, 1624, 628, 506, 632, 1620, 632, 1618, 632, 1620, 632, 1620, 632, 39016, 9040, 2216, 630}; // NEC 1FE50AF
18:12:34.027 -> uint32_t address = 0x80;
18:12:34.027 -> uint32_t command = 0xA;
18:12:34.027 -> uint64_t data = 0x1FE50AF;
//mute button
18:13:27.215 -> Protocol : NEC
18:13:27.215 -> Code : 0x1FE30CF (32 Bits)
18:13:27.215 -> uint16_t rawData[71] = {9094, 4398, 660, 478, 658, 480, 658, 480, 658, 480, 658, 480, 658, 480, 660, 480, 658, 1594, 658, 1594, 658, 1594, 658, 1594, 658, 1592, 658, 1594, 658, 1592, 658, 1594, 660, 480, 658, 480, 658, 480, 658, 1592, 658, 1592, 658, 480, 658, 480, 660, 478, 660, 478, 658, 1594, 658, 1592, 658, 480, 658, 480, 658, 1594, 658, 1592, 658, 1594, 658, 1594, 658, 38986, 9094, 2162, 658}; // NEC 1FE30CF
18:13:27.285 -> uint32_t address = 0x80;
18:13:27.285 -> uint32_t command = 0xC;
18:13:27.285 -> uint64_t data = 0x1FE30CF;
//Vol. low
18:14:44.427 -> Protocol : NEC
18:14:44.427 -> Code : 0x1FEC03F (32 Bits)
18:14:44.427 -> uint16_t rawData[71] = {9120, 4374, 658, 478, 658, 480, 658, 480, 658, 480, 658, 482, 658, 478, 658, 480, 658, 1594, 658, 1594, 658, 1592, 660, 1594, 658, 1592, 658, 1594, 658, 1594, 658, 1592, 660, 480, 658, 1594, 658, 1594, 658, 480, 658, 480, 660, 480, 658, 480, 658, 480, 658, 480, 658, 480, 658, 480, 658, 1594, 660, 1592, 658, 1594, 658, 1594, 658, 1592, 658, 1594, 658, 39002, 9094, 2162, 658}; // NEC 1FEC03F
18:14:44.497 -> uint32_t address = 0x80;
18:14:44.497 -> uint32_t command = 0x3;
18:14:44.497 -> uint64_t data = 0x1FEC03F;
//VOl. High
18:15:11.677 -> Protocol : NEC
18:15:11.677 -> Code : 0x1FE40BF (32 Bits)
18:15:11.677 -> uint16_t rawData[67] = {9068, 4426, 630, 506, 632, 508, 630, 508, 630, 508, 630, 508, 630, 508, 630, 508, 630, 1622, 630, 1622, 630, 1622, 630, 1622, 656, 1594, 630, 1622, 632, 1620, 630, 1622, 630, 508, 630, 508, 630, 1622, 630, 508, 630, 508, 630, 508, 630, 508, 630, 508, 630, 508, 630, 1622, 656, 482, 630, 1622, 630, 1622, 630, 1622, 630, 1622, 630, 1622, 632, 1620, 630}; // NEC 1FE40BF
18:15:11.747 -> uint32_t address = 0x80;
18:15:11.747 -> uint32_t command = 0x2;
18:15:11.747 -> uint64_t data = 0x1FE40BF;
//Play/Pause
18:15:38.529 -> Protocol : NEC
18:15:38.529 -> Code : 0x1FE32CD (32 Bits)
18:15:38.529 -> uint16_t rawData[71] = {9092, 4400, 632, 504, 658, 480, 658, 480, 632, 506, 658, 480, 658, 480, 658, 482, 632, 1620, 658, 1594, 658, 1594, 632, 1618, 658, 1594, 658, 1594, 632, 1620, 632, 1618, 634, 506, 658, 480, 658, 480, 632, 1620, 658, 1598, 656, 478, 658, 478, 658, 1594, 658, 482, 632, 1618, 632, 1618, 634, 506, 632, 506, 658, 1594, 632, 1620, 658, 480, 632, 1620, 658, 38998, 9094, 2162, 660}; // NEC 1FE32CD
18:15:38.564 -> uint32_t address = 0x80;
18:15:38.564 -> uint32_t command = 0x4C;
18:15:38.564 -> uint64_t data = 0x1FE32CD;
//Song Back
18:16:07.527 -> Protocol : NEC
18:16:07.527 -> Code : 0x1FEA05F (32 Bits)
18:16:07.562 -> uint16_t rawData[71] = {9590, 3902, 684, 452, 686, 456, 652, 480, 660, 480, 684, 456, 656, 480, 658, 480, 684, 1568, 658, 1594, 658, 1594, 686, 1566, 658, 1594, 684, 1568, 658, 1594, 658, 1594, 686, 454, 684, 1568, 686, 454, 658, 1594, 684, 454, 686, 454, 658, 480, 660, 480, 684, 454, 658, 482, 658, 1594, 682, 456, 658, 1596, 658, 1594, 686, 1568, 660, 1592, 684, 1568, 686, 38982, 9098, 2162, 684}; // NEC 1FEA05F
18:16:07.597 -> uint32_t address = 0x80;
18:16:07.597 -> uint32_t command = 0x5;
18:16:07.597 -> uint64_t data = 0x1FEA05F;
//Song Forward
18:17:20.541 -> Protocol : NEC
18:17:20.541 -> Code : 0x1FEE01F (32 Bits)
18:17:20.575 -> uint16_t rawData[71] = {9068, 4424, 632, 506, 630, 506, 632, 508, 606, 532, 632, 506, 630, 508, 630, 508, 632, 1620, 632, 1620, 632, 1620, 604, 1646, 606, 1646, 630, 1622, 604, 1646, 632, 1620, 606, 534, 630, 1622, 604, 1646, 630, 1622, 604, 534, 630, 508, 604, 534, 606, 534, 630, 508, 630, 508, 606, 534, 606, 532, 630, 1622, 604, 1646, 632, 1620, 604, 1648, 604, 1646, 604, 39040, 9040, 2216, 604}; // NEC 1FEE01F
18:17:20.610 -> uint32_t address = 0x80;
18:17:20.610 -> uint32_t command = 0x7;
18:17:20.610 -> uint64_t data = 0x1FEE01F;
*/
// check complete video tutorial here for program explanation https://www.youtube.com/watch?v=LqmkDKu54XY&t=17s
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#else
#include <WiFi.h>
#endif // ESP8266
#if defined(ESP32)
#include <BlynkSimpleEsp32.h>
#endif // ESP32
// IR library
#include <IRremoteESP8266.h>
#include <IRsend.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
BLYNK_WRITE(V51) { // Power button
if (param.asInt() == 0) {
// Serial.println("NEC");
irsend.sendNEC(0x1FE50AF);
}
}
BLYNK_WRITE(V52) { // Mute button
if (param.asInt() == 0) {
// Serial.println("NEC");
irsend.sendNEC(0x1FE30CF);
}
}
BLYNK_WRITE(V53) { // Song Forward
if (param.asInt() == 0) {
// Serial.println("NEC");
irsend.sendNEC(0x1FEE01F);
}
}
BLYNK_WRITE(V54) { // Song Backward
if (param.asInt() == 0) {
// Serial.println("NEC");
irsend.sendNEC(0x1FEA05F);
delay(10); // double tap back button to back one song
irsend.sendNEC(0x1FEA05F);
}
}
BLYNK_WRITE(V55) { // Volume --
if (param.asInt() == 0) {
// Serial.println("NEC");
irsend.sendNEC(0x1FEC03F);
}
}
BLYNK_WRITE(V56) { // Volume ++
if (param.asInt() == 0) {
// Serial.println("NEC");
irsend.sendNEC(0x1FE40BF);
}
}
BLYNK_WRITE(V57) { // Play/Pause
if (param.asInt() == 0) {
// Serial.println("NEC");
irsend.sendNEC(0x1FE32CD);
}
}
void setup() {
#if defined(BLYNK_PRINT)
// Debug console
Serial.begin(115200);
#endif // BLYNK_PRINT
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
}

View File

@@ -0,0 +1,35 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
platform = espressif8266
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[common]
lib_deps_builtin =
lib_deps_external =
Blynk
[common_esp8266]
lib_deps_external =
${common.lib_deps_builtin}
${common.lib_deps_external}
[common_esp32]
lib_deps_external =
${common.lib_deps_builtin}
${common.lib_deps_external}
[env:nodemcuv2]
board = nodemcuv2
lib_deps = ${common_esp8266.lib_deps_external}
[env:esp32dev]
platform = espressif32
board = esp32dev
lib_deps = ${common_esp32.lib_deps_external}

View File

@@ -0,0 +1,72 @@
/* Copyright 2019 David Conran
*
* This example code demonstrates how to use the "Common" IRac class to control
* various air conditions. The IRac class does not support all the features
* for every protocol. Some have more detailed support that what the "Common"
* interface offers, and some only have a limited subset of the "Common" options.
*
* This example code will:
* o Try to turn on, then off every fully supported A/C protocol we know of.
* o It will try to put the A/C unit into Cooling mode at 25C, with a medium
* fan speed, and no fan swinging.
* Note: Some protocols support multiple models, only the first model is tried.
*
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRac.h>
#include <IRutils.h>
const uint16_t kIrLed = 4; // The ESP GPIO pin to use that controls the IR LED.
IRac ac(kIrLed); // Create a A/C object using GPIO to sending messages with.
void setup() {
Serial.begin(115200);
delay(200);
// Set up what we want to send.
// See state_t, opmode_t, fanspeed_t, swingv_t, & swingh_t in IRsend.h for
// all the various options.
ac.next.protocol = decode_type_t::DAIKIN; // Set a protocol to use.
ac.next.model = 1; // Some A/Cs have different models. Try just the first.
ac.next.mode = stdAc::opmode_t::kCool; // Run in cool mode initially.
ac.next.celsius = true; // Use Celsius for temp units. False = Fahrenheit
ac.next.degrees = 25; // 25 degrees.
ac.next.fanspeed = stdAc::fanspeed_t::kMedium; // Start the fan at medium.
ac.next.swingv = stdAc::swingv_t::kOff; // Don't swing the fan up or down.
ac.next.swingh = stdAc::swingh_t::kOff; // Don't swing the fan left or right.
ac.next.light = false; // Turn off any LED/Lights/Display that we can.
ac.next.beep = false; // Turn off any beep from the A/C if we can.
ac.next.econo = false; // Turn off any economy modes if we can.
ac.next.filter = false; // Turn off any Ion/Mold/Health filters if we can.
ac.next.turbo = false; // Don't use any turbo/powerful/etc modes.
ac.next.quiet = false; // Don't use any quiet/silent/etc modes.
ac.next.sleep = -1; // Don't set any sleep time or modes.
ac.next.clean = false; // Turn off any Cleaning options if we can.
ac.next.clock = -1; // Don't set any current time if we can avoid it.
ac.next.power = false; // Initially start with the unit off.
Serial.println("Try to turn on & off every supported A/C type ...");
}
void loop() {
// For every protocol the library has ...
for (int i = 1; i < kLastDecodeType; i++) {
decode_type_t protocol = (decode_type_t)i;
// If the protocol is supported by the IRac class ...
if (ac.isProtocolSupported(protocol)) {
Serial.println("Protocol " + String(protocol) + " / " +
typeToString(protocol) + " is supported.");
ac.next.protocol = protocol; // Change the protocol used.
ac.next.power = true; // We want to turn on the A/C unit.
Serial.println("Sending a message to turn ON the A/C unit.");
ac.sendAc(); // Have the IRac class create and send a message.
delay(5000); // Wait 5 seconds.
ac.next.power = false; // Now we want to turn the A/C off.
Serial.println("Send a message to turn OFF the A/C unit.");
ac.sendAc(); // Send the message.
delay(1000); // Wait 1 second.
}
}
Serial.println("Starting from the begining again ...");
}

View File

@@ -0,0 +1,26 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev
; Build the program forcing the compiler to treat all warnings as errors.
[env:shakedown_all_protocols]
platform = espressif8266
board = nodemcuv2
build_flags =
${env.build_flags}
-Werror

View File

@@ -0,0 +1,94 @@
/* Copyright 2019 David Conran
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.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 used for sending messages.
void printState() {
// Display the settings.
Serial.println("Samsung A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
}
void setup() {
ac.begin();
Serial.begin(115200);
delay(200);
// Set up what we want to send. See ir_Samsung.cpp for all the options.
Serial.println("Default state of the remote.");
printState();
Serial.println("Setting initial state for A/C.");
ac.off();
ac.setFan(kSamsungAcFanLow);
ac.setMode(kSamsungAcCool);
ac.setTemp(25);
ac.setSwing(false);
printState();
}
void loop() {
// Turn the A/C unit on
Serial.println("Turn on the A/C ...");
ac.on();
ac.send();
printState();
delay(15000); // wait 15 seconds
// and set to cooling mode.
Serial.println("Set the A/C mode to cooling ...");
ac.setMode(kSamsungAcCool);
ac.send();
printState();
delay(15000); // wait 15 seconds
// Increase the fan speed.
Serial.println("Set the fan to high and the swing on ...");
ac.setFan(kSamsungAcFanHigh);
ac.setSwing(true);
ac.send();
printState();
delay(15000);
// Change to Fan mode, lower the speed, and stop the swing.
Serial.println("Set the A/C to fan only with a low speed, & no swing ...");
ac.setSwing(false);
ac.setMode(kSamsungAcFan);
ac.setFan(kSamsungAcFanLow);
ac.send();
printState();
delay(15000);
// Turn the A/C unit off.
Serial.println("Turn off the A/C ...");
ac.off();
ac.send();
printState();
delay(15000); // wait 15 seconds
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,133 @@
/*
* IRremoteESP8266: DumbIRRepeater.ino - Record and playback IR codes.
* Copyright 2019 David Conran (crankyoldgit)
*
* This program will try to capture incoming IR messages and replay them back.
* It doesn't use any of the advanced detection features, thus it will just
* replay the messages at fixed modulated frequency (kFrequency) and a 50% duty
* cycle.
*
* Note:
* This might NOT be the frequency of the incoming message, so some replayed
* messages may not work. The frequency of incoming messages & duty cycle is
* lost at the point of the Hardware IR demodulator. The ESP can't see it.
*
* W A R N I N G
* This code is just for educational/example use only. No help will be given
* to you to make it do something else, or to make it work with some
* weird device or circuit, or to make it more usable or practical.
* If it works for you. Great. If not, Congratulations on changing/fixing it.
*
* An IR detector/demodulator must be connected to the input, kRecvPin.
* An IR LED circuit must be connected to the output, kIrLedPin.
*
* Example circuit diagrams (both are needed):
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-receiving
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * Some 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 ESP will interfere.
* * Pin 3/RX/RXD0: Any serial transmissions to the ESP will interfere.
* * Pin 16/D0: Has no interrupts on the ESP8266, so can't be used for IR
* receiving with this library.
* * ESP-01 modules are tricky. We suggest you use a module with more GPIOs
* for your first time. e.g. ESP-12 etc.
*
* Changes:
* Version 1.0: June, 2019
* - Initial version.
*/
#include <Arduino.h>
#include <IRsend.h>
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRutils.h>
// ==================== start of TUNEABLE PARAMETERS ====================
// The GPIO an IR detector/demodulator is connected to. Recommended: 14 (D5)
// Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts.
const uint16_t kRecvPin = 14;
// GPIO to use to control the IR LED circuit. Recommended: 4 (D2).
const uint16_t kIrLedPin = 4;
// The Serial connection baud rate.
// 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/resender, let's use a larger
// than expected buffer so we can handle very large IR messages.
// i.e. Up to 512 bits.
const uint16_t kCaptureBufferSize = 1024;
// kTimeout is the Nr. of milli-Seconds of no-more-data before we consider a
// message ended.
const uint8_t kTimeout = 50; // Milli-Seconds
// kFrequency is the modulation frequency all messages will be replayed at.
const uint16_t kFrequency = 38000; // in Hz. e.g. 38kHz.
// ==================== end of TUNEABLE PARAMETERS ====================
// The IR transmitter.
IRsend irsend(kIrLedPin);
// The IR receiver.
IRrecv irrecv(kRecvPin, kCaptureBufferSize, kTimeout, false);
// Somewhere to store the captured message.
decode_results results;
// This section of code runs only once at start-up.
void setup() {
irrecv.enableIRIn(); // Start up the IR receiver.
irsend.begin(); // Start up the IR sender.
Serial.begin(kBaudRate, SERIAL_8N1);
while (!Serial) // Wait for the serial connection to be establised.
delay(50);
Serial.println();
Serial.print("DumbIRRepeater is now running and waiting for IR input "
"on Pin ");
Serial.println(kRecvPin);
Serial.print("and will retransmit it on Pin ");
Serial.println(kIrLedPin);
}
// The repeating section of the code
void loop() {
// Check if an IR message has been received.
if (irrecv.decode(&results)) { // We have captured something.
// The capture has stopped at this point.
// Convert the results into an array suitable for sendRaw().
// resultToRawArray() allocates the memory we need for the array.
uint16_t *raw_array = resultToRawArray(&results);
// Find out how many elements are in the array.
uint16_t length = getCorrectedRawLength(&results);
// Send it out via the IR LED circuit.
irsend.sendRaw(raw_array, length, kFrequency);
// Resume capturing IR messages. It was not restarted until after we sent
// the message so we didn't capture our own message.
irrecv.resume();
// Deallocate the memory allocated by resultToRawArray().
delete [] raw_array;
// Display a crude timestamp & notification.
uint32_t now = millis();
Serial.printf(
"%06u.%03u: A message that was %d entries long was retransmitted.\n",
now / 1000, now % 1000, length);
}
yield(); // Or delay(milliseconds); This ensures the ESP doesn't WDT reset.
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,70 @@
/*
* IRremoteESP8266: IRsendGCDemo
* demonstrates sending Global Cache-formatted IR codes with IRsend
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*
* 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:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <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};
#define 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");
#if SEND_GLOBALCACHE
irsend.sendGC(Samsung_power_toggle, 71);
#else // SEND_GLOBALCACHE
Serial.println("Can't send because SEND_GLOBALCACHE has been disabled.");
#endif // SEND_GLOBALCACHE
delay(10000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,136 @@
/*
* IRremoteESP8266: IRGCTCPServer - send Global Cache-formatted codes via TCP.
* An IR emitter must be connected to GPIO pin 4.
* Version 0.2 May, 2017
* Copyright 2016 Hisham Khalifa, http://www.hishamkhalifa.com
* Copyright 2017 David Conran
*
* Example command - Samsung TV power toggle: 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\r\n
* For more codes, visit: https://irdb.globalcache.com/
*
* How to use this program:
* 1) Update "kSsid" and "kPassword" below for your WIFI network.
* 2) Compile and upload the sketch to your ESP8266 module.
* 3) (Optional) Use the serial connection to confirm it started and get the
* IP address.
* 4) From a client machine, connect to port 4998 on the ESP8266, using
* 'telnet', 'nc' (netcat), 'putty' or similar command, etc.
* You may need to install one.
* Unix/OSX:
* Start a shell. Then type:
* telnet <esp8266deviceIPaddress> 4998
* Windows:
* Start a new CMD window, then type:
* telnet <esp8266deviceIPaddress> 4998
*
* 5) Enter a Global Cache-formatted code, starting at the frequency,
* and then a return/enter at the end. No spaces. e.g.:
*
* 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
*
* To exit the 'telnet' command:
* press <control> + <]> at the same time, then press 'q', and then <return>.
* or:
* <control> + <d> might work.
*
* This program will display the ESP's IP address on the serial console, or you
* can check your wifi router for it's address.
*/
#include <Arduino.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#endif // ESP8266
#if defined(ESP32)
#include <WiFi.h>
#endif // ESP32
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
const char* kSsid = "..."; // Put your WIFI SSID here.
const char* kPassword = "..."; // Put your WIFI Password here.
WiFiServer server(4998); // Uses port 4998.
WiFiClient client;
uint16_t *code_array;
#define 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 sendGCString(String str) {
int16_t index;
uint16_t count;
// Find out how many items there are in the string.
index = -1;
count = 1;
do {
index = str.indexOf(',', index + 1);
count++;
} while (index != -1);
// Now we know how many there are, allocate the memory to store them all.
code_array = reinterpret_cast<uint16_t*>(malloc(count * sizeof(uint16_t)));
// Check we malloc'ed successfully.
if (code_array == NULL) { // malloc failed, so give up.
Serial.printf("\nCan't allocate %d bytes. (%d bytes free)\n",
count * sizeof(uint16_t), ESP.getFreeHeap());
Serial.println("Giving up & forcing a reboot.");
ESP.restart(); // Reboot.
delay(500); // Wait for the restart to happen.
return; // Should never get here, but just in case.
}
// Now convert the strings to integers and place them in code_array.
count = 0;
uint16_t start_from = 0;
do {
index = str.indexOf(',', start_from);
code_array[count] = str.substring(start_from, index).toInt();
start_from = index + 1;
count++;
} while (index != -1);
#if SEND_GLOBALCACHE
irsend.sendGC(code_array, count); // All done. Send it.
#endif // SEND_GLOBALCACHE
free(code_array); // Free up the memory allocated.
}
void setup() {
// initialize serial:
Serial.begin(115200);
delay(100);
Serial.println(" ");
Serial.println("IR TCP Server");
WiFi.begin(kSsid, kPassword);
while (WiFi.status() != WL_CONNECTED) {
delay(900);
Serial.print(".");
}
server.begin();
IPAddress myAddress = WiFi.localIP();
Serial.println(myAddress.toString());
irsend.begin();
}
void loop() {
while (!client)
client = server.available();
while (!client.connected()) {
delay(900);
client = server.available();
}
if (client.available()) {
String ir_code_str = client.readStringUntil('\r'); // Exclusive of \r
client.readStringUntil('\n'); // Skip new line as well
client.flush();
sendGCString(ir_code_str);
}
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,434 @@
/*
* Send & receive arbitrary IR codes via a web server or MQTT.
* Copyright David Conran 2016, 2017, 2018, 2019
*/
#ifndef EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_
#define EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#endif // ESP8266
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRsend.h>
#include <IRtext.h>
#include <IRtimer.h>
#include <IRutils.h>
#include <IRac.h>
// ---------------- Start of User Configuration Section ------------------------
#ifndef MQTT_ENABLE
#define MQTT_ENABLE true // Whether or not MQTT is used at all.
#endif // MQTT_ENABLE
#ifndef EXAMPLES_ENABLE
// Whether or not examples are included. `false` saves ~2.5K of program space.
#define EXAMPLES_ENABLE true
#endif // EXAMPLES_ENABLE
// ---------------------- Board Related Settings -------------------------------
// NOTE: Make sure you set your Serial Monitor to the same speed.
#define BAUD_RATE 115200 // Serial port Baud rate.
// Change if you need multiple independent send gpios & topics. (MQTT only)
const uint8_t kNrOfIrTxGpios = 1;
// Default GPIO the IR LED is connected to/controlled by. GPIO 4 = D2.
// For an ESP-01 we suggest you use RX/GPIO3/Pin 7. i.e. kDefaultIrLed = 3
// Note: A value of -1 means unused.
const int8_t kDefaultIrLed = 4; // <=- CHANGE_ME (optional)
// **DANGER** Optional flag to invert the output. (default = false)
// `false`: The LED is illuminated when the GPIO is HIGH.
// `true`: The LED is illuminated when GPIO is LOW rather than HIGH.
// Setting this to something other than the default could
// easily destroy your IR LED if you are overdriving it.
// Unless you *REALLY* know what you are doing, don't change this.
const bool kInvertTxOutput = false;
// Default GPIO the IR demodulator is connected to/controlled by. GPIO 14 = D5.
// Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts.
const int8_t kDefaultIrRx = 14; // <=- CHANGE_ME (optional)
// Enable/disable receiving/decoding IR messages entirely.
// Note: IR_RX costs about 40k+ of program memory.
#define IR_RX true
// Should we use PULLUP on the IR Rx gpio?
#define IR_RX_PULLUP false
// --------------------- Network Related Settings ------------------------------
const uint16_t kHttpPort = 80; // The TCP port the HTTP server is listening on.
// Change to 'true'/'false' if you do/don't want these features or functions.
#define USE_STATIC_IP false // Change to 'true' if you don't want to use DHCP.
// We obtain our network config via DHCP by default but allow an easy way to
// use a static IP config.
#if USE_STATIC_IP
const IPAddress kIPAddress = IPAddress(10, 0, 1, 78);
const IPAddress kGateway = IPAddress(10, 0, 1, 1);
const IPAddress kSubnetMask = IPAddress(255, 255, 255, 0);
#endif // USE_STATIC_IP
// See: https://github.com/tzapu/WiFiManager#filter-networks for these settings.
#define HIDE_DUPLICATE_NETWORKS false // Make WifiManager hide duplicate SSIDs
// #define MIN_SIGNAL_STRENGTH 20 // Minimum WiFi signal stength (percentage)
// before we will connect.
// The unset default is 8%.
// (Uncomment to enable)
// Do you want/need mdns enabled? (https://en.wikipedia.org/wiki/Multicast_DNS)
#define MDNS_ENABLE true // `false` to disable and save ~21k of program space.
// ----------------------- HTTP Related Settings -------------------------------
#define FIRMWARE_OTA true // Allow remote update of the firmware via http.
// Less secure if enabled.
// Note: Firmware OTA is also disabled until
// a password is set.
#define HTML_PASSWORD_ENABLE false // Protect access to the HTML interface.
// Note: OTA & GPIO updates are always
// passworded.
// If you do not set a password, Firmware OTA & GPIO updates will be blocked.
// ----------------------- MQTT Related Settings -------------------------------
#if MQTT_ENABLE
const uint32_t kMqttReconnectTime = 5000; // Delay(ms) between reconnect tries.
#define MQTT_ACK "sent" // Sub-topic we send back acknowledgements on.
#define MQTT_SEND "send" // Sub-topic we get new commands from.
#define MQTT_RECV "received" // Topic we send received IRs to.
#define MQTT_LOG "log" // Topic we send log messages to.
#define MQTT_LWT "status" // Topic for the Last Will & Testament.
#define MQTT_CLIMATE "ac" // Sub-topic for the climate topics.
#define MQTT_CLIMATE_CMND "cmnd" // Sub-topic for the climate command topics.
#define MQTT_CLIMATE_STAT "stat" // Sub-topic for the climate stat topics.
// Enable sending/receiving climate via JSON. `true` cost ~5k of program space.
#define MQTT_CLIMATE_JSON false
// Use Home Assistant-style operation modes.
// TL;DR: Power and Mode are linked together. One changes the other.
// i.e.
// - When power is set to "off", the mode is set to "off".
// - When the mode changes from "off" to something else, power is set to "on".
// See: https://www.home-assistant.io/components/climate.mqtt/#modes
// *** WARNING ***
// This setting will cause IRMQTTServer to forget what the previous operation
// mode was. e.g. a power "on" -> "off" -> "on" will cause it to use the
// default mode for your A/C, not the previous mode.
// Typically this is "Auto" or "Cool" mode.
// Change to false, if your home automation system doesn't like this, or if
// you want IRMQTTServer to be the authoritative source for controling your
// A/C.
#define MQTT_CLIMATE_HA_MODE true
// Do we send an IR message when we reboot and recover the existing A/C state?
// If set to `false` you may miss requested state changes while the ESP was
// down. If set to `true`, it will resend the previous desired state sent to the
// A/C. Depending on your circumstances, you may need to change this.
#define MQTT_CLIMATE_IR_SEND_ON_RESTART false
#define MQTTbroadcastInterval 10 * 60 // Seconds between rebroadcasts.
#define QOS 1 // MQTT broker should queue up any unreceived messages for us
// #define QOS 0 // MQTT broker WON'T queue up messages for us. Fire & Forget.
// Enable(true)/Disable(false) the option to send a MQTT Discovery message for
// the AirCon/Climate system to Home Assistant. Note: `false` saves ~1.5k.
#define MQTT_DISCOVERY_ENABLE true
// Enable(true)/Disable(false) the option to clear any settings stored in MQTT
// for this device's current config. e.g. Climate states using MQTT retain.
// In theory, you shouldn't need this as you can always clean up by hand, hence
// it is disabled by default. Note: `false` saves ~1.2k.
#define MQTT_CLEAR_ENABLE false
#endif // MQTT_ENABLE
// ------------------------ IR Capture Settings --------------------------------
// Should we stop listening for IR messages when we send a message via IR?
// Set this to `true` if your IR demodulator is picking up self transmissions.
// Use `false` if it isn't or can't see the self-sent transmissions
// Using `true` may mean some incoming IR messages are lost or garbled.
// i.e. `false` is better if you can get away with it.
#define DISABLE_CAPTURE_WHILE_TRANSMITTING true
// Let's use a larger than normal buffer so we can handle AirCon remote codes.
const uint16_t kCaptureBufferSize = 1024;
#if 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 kCaptureTimeout = 50; // Milliseconds
#else // DECODE_AC
// Suits most messages, while not swallowing many repeats.
const uint8_t kCaptureTimeout = 15; // Milliseconds
#endif // DECODE_AC
// Ignore unknown messages with <10 pulses (see also REPORT_UNKNOWNS)
const uint16_t kMinUnknownSize = 2 * 10;
#define REPORT_UNKNOWNS false // Report inbound IR messages that we don't know.
#define REPORT_RAW_UNKNOWNS false // Report the whole buffer, recommended:
// MQTT_MAX_PACKET_SIZE of 1024 or more
// Should we use and report individual A/C settings we capture via IR if we
// can understand the individual settings of the remote.
// e.g. Aquire the A/C settings from an actual A/C IR remote and override
// any local settings set via MQTT/HTTP etc.
#define USE_DECODED_AC_SETTINGS true // `false` to disable. `true` to enable.
// Should we allow or ignore an A/C IR remote to override the A/C protocol/model
// as set via MQTT or HTTP?
// e.g. If `true`, you can use any fully supported A/C remote to control
// another brand's or model's A/C unit. `false` means change to the new
// protocol/model if we support it via `USE_DECODED_AC_SETTINGS`.
#define IGNORE_DECODED_AC_PROTOCOL true
// Do we (re-)send the captured & decoded A/C message via the IR_LED?
// `false` if you don't want to repeat the captured message.
// e.g. Useful if the IR demodulator is located in the path between the remote
// and the A/C unit so the command isn't sent twice.
// `true` if you want it sent anyway.
// e.g. The IR demodulator is in a completely different location than than the
// actual a/c unit.
#define REPLAY_DECODED_AC_MESSAGE false
// ------------------------ Advanced Usage Only --------------------------------
// Reports the input voltage to the ESP chip. **NOT** the input voltage
// to the development board (e.g. NodeMCU, D1 Mini etc) which are typically
// powered by USB (5V) which is then lowered to 3V via a Low Drop Out (LDO)
// Voltage regulator. Hence, this feature is turned off by default as it
// make little sense for most users as it really isn't the actual input voltage.
// E.g. For purposes of monitoring a battery etc.
// Note: Turning on the feature costs ~250 bytes of prog space.
#define REPORT_VCC false // Do we report Vcc via html info page & MQTT?
// Keywords for MQTT topics, html arguments, or config file.
#define KEY_PROTOCOL "protocol"
#define KEY_MODEL "model"
#define KEY_POWER "power"
#define KEY_MODE "mode"
#define KEY_TEMP "temp"
#define KEY_FANSPEED "fanspeed"
#define KEY_SWINGV "swingv"
#define KEY_SWINGH "swingh"
#define KEY_QUIET "quiet"
#define KEY_TURBO "turbo"
#define KEY_LIGHT "light"
#define KEY_BEEP "beep"
#define KEY_ECONO "econo"
#define KEY_SLEEP "sleep"
#define KEY_FILTER "filter"
#define KEY_CLEAN "clean"
#define KEY_CELSIUS "use_celsius"
#define KEY_JSON "json"
#define KEY_RESEND "resend"
#define KEY_VCC "vcc"
// HTML arguments we will parse for IR code information.
#define KEY_TYPE "type" // KEY_PROTOCOL is also checked too.
#define KEY_CODE "code"
#define KEY_BITS "bits"
#define KEY_REPEAT "repeats"
#define KEY_CHANNEL "channel" // Which IR TX channel to send on.
// GPIO html/config keys
#define KEY_TX_GPIO "tx"
#define KEY_RX_GPIO "rx"
// Text for Last Will & Testament status messages.
const char* kLwtOnline = "Online";
const char* kLwtOffline = "Offline";
const uint8_t kHostnameLength = 30;
const uint8_t kPortLength = 5; // Largest value of uint16_t is "65535".
const uint8_t kUsernameLength = 15;
const uint8_t kPasswordLength = 20;
// -------------------------- Json Settings ------------------------------------
const uint16_t kJsonConfigMaxSize = 512; // Bytes
const uint16_t kJsonAcStateMaxSize = 1024; // Bytes
// -------------------------- Debug Settings -----------------------------------
// Debug output is disabled if any of the IR pins are on the TX (D1) pin.
// See `isSerialGpioUsedByIr()`.
// Note: Debug costs ~6k of program space.
#ifndef DEBUG
#define DEBUG false // Change to 'true' for serial debug output.
#endif // DEBUG
// ----------------- End of User Configuration Section -------------------------
// Constants
#define _MY_VERSION_ "v1.5.0"
const uint8_t kRebootTime = 15; // Seconds
const uint8_t kQuickDisplayTime = 2; // Seconds
// Common bit sizes for the simple protocols.
const uint8_t kCommonBitSizes[] = {
12, 13, 15, 16, 20, 24, 28, 32, 35, 36, 42, 48, 56, 64};
// Gpio related
#if defined(ESP8266)
const int8_t kTxGpios[] = {-1, 0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16};
const int8_t kRxGpios[] = {-1, 0, 1, 2, 3, 4, 5, 12, 13, 14, 15};
#endif // ESP8266
#if defined(ESP32)
// Ref: https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
const int8_t kTxGpios[] = {
-1, 0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23,
25, 26, 27, 32, 33};
const int8_t kRxGpios[] = {
-1, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23,
25, 26, 27, 32, 33, 34, 35, 36, 39};
#endif // ESP32
// JSON stuff
// Name of the json config file in SPIFFS.
const char* kConfigFile = "/config.json";
const char* kMqttServerKey = "mqtt_server";
const char* kMqttPortKey = "mqtt_port";
const char* kMqttUserKey = "mqtt_user";
const char* kMqttPassKey = "mqtt_pass";
const char* kMqttPrefixKey = "mqtt_prefix";
const char* kHostnameKey = "hostname";
const char* kHttpUserKey = "http_user";
const char* kHttpPassKey = "http_pass";
const char* kCommandDelimiter = ",";
// URLs
const char* kUrlRoot = "/";
const char* kUrlAdmin = "/admin";
const char* kUrlAircon = "/aircon";
const char* kUrlSendDiscovery = "/send_discovery";
const char* kUrlExamples = "/examples";
const char* kUrlGpio = "/gpio";
const char* kUrlGpioSet = "/gpio/set";
const char* kUrlInfo = "/info";
const char* kUrlReboot = "/quitquitquit";
const char* kUrlWipe = "/reset";
const char* kUrlClearMqtt = "/clear_retained";
#if MQTT_ENABLE
const uint32_t kBroadcastPeriodMs = MQTTbroadcastInterval * 1000; // mSeconds.
// How long should we listen to recover for previous states?
// Default is 5 seconds per IR TX GPIOs (channels) used.
const uint32_t kStatListenPeriodMs = 5 * 1000 * kNrOfIrTxGpios; // mSeconds
const int32_t kMaxPauseMs = 10000; // 10 Seconds.
const char* kSequenceDelimiter = ";";
const char kPauseChar = 'P';
#if defined(ESP8266)
const uint32_t kChipId = ESP.getChipId();
#endif // ESP8266
#if defined(ESP32)
const uint32_t kChipId = ESP.getEfuseMac(); // Discard the top 16 bits.
#endif // ESP32
const char* kClimateTopics =
"(" KEY_PROTOCOL "|" KEY_MODEL "|" KEY_POWER "|" KEY_MODE "|" KEY_TEMP "|"
KEY_FANSPEED "|" KEY_SWINGV "|" KEY_SWINGH "|" KEY_QUIET "|"
KEY_TURBO "|" KEY_LIGHT "|" KEY_BEEP "|" KEY_ECONO "|" KEY_SLEEP "|"
KEY_FILTER "|" KEY_CLEAN "|" KEY_CELSIUS "|" KEY_RESEND
#if MQTT_CLIMATE_JSON
"|" KEY_JSON
#endif // MQTT_CLIMATE_JSON
")<br>";
const char* kMqttTopics[] = {
KEY_PROTOCOL, KEY_MODEL, KEY_POWER, KEY_MODE, KEY_TEMP, KEY_FANSPEED,
KEY_SWINGV, KEY_SWINGH, KEY_QUIET, KEY_TURBO, KEY_LIGHT, KEY_BEEP,
KEY_ECONO, KEY_SLEEP, KEY_FILTER, KEY_CLEAN, KEY_CELSIUS, KEY_RESEND,
KEY_JSON}; // KEY_JSON needs to be the last one.
void mqttCallback(char* topic, byte* payload, unsigned int length);
String listOfCommandTopics(void);
void handleSendMqttDiscovery(void);
void subscribing(const String topic_name);
void unsubscribing(const String topic_name);
void mqttLog(const char* str);
bool mountSpiffs(void);
bool reconnect(void);
void receivingMQTT(String const topic_name, String const callback_str);
void callback(char* topic, byte* payload, unsigned int length);
void sendMQTTDiscovery(const char *topic);
void doBroadcast(TimerMs *timer, const uint32_t interval,
IRac *climates[], const bool retain,
const bool force);
#if MQTT_CLIMATE_JSON
stdAc::state_t jsonToState(const stdAc::state_t current, const char *str);
void sendJsonState(const stdAc::state_t state, const String topic,
const bool retain = false,
const bool ha_mode = MQTT_CLIMATE_HA_MODE);
#endif // MQTT_CLIMATE_JSON
#endif // MQTT_ENABLE
#if REPORT_VCC
String vccToString(void);
#endif // REPORT_VCC
bool isSerialGpioUsedByIr(void);
void debug(const char *str);
void saveWifiConfigCallback(void);
void saveWifiConfig(void);
void loadWifiConfigFile(void);
void doRestart(const char* str, const bool serial_only = false);
String msToHumanString(uint32_t const msecs);
String timeElapsed(uint32_t const msec);
String timeSince(uint32_t const start);
String gpioToString(const int16_t gpio);
uint8_t getDefaultIrSendIdx(void);
IRsend* getDefaultIrSendPtr(void);
int8_t getDefaultTxGpio(void);
String genStatTopic(const uint16_t channel = 0);
String listOfTxGpios(void);
bool hasUnsafeHTMLChars(String input);
String htmlHeader(const String title, const String h1_text = "");
String htmlEnd(void);
String htmlButton(const String url, const String button,
const String text = "");
String htmlMenu(void);
void handleRoot(void);
String addJsReloadUrl(const String url, const uint16_t timeout_s,
const bool notify);
void handleExamples(void);
String htmlSelectBool(const String name, const bool def);
String htmlSelectClimateProtocol(const String name, const decode_type_t def);
String htmlSelectAcStateProtocol(const String name, const decode_type_t def,
const bool simple);
String htmlSelectModel(const String name, const int16_t def);
String htmlSelectMode(const String name, const stdAc::opmode_t def);
String htmlSelectFanspeed(const String name, const stdAc::fanspeed_t def);
String htmlSelectSwingv(const String name, const stdAc::swingv_t def);
String htmlSelectSwingh(const String name, const stdAc::swingh_t def);
void handleAirCon(void);
void handleAirConSet(void);
void handleAdmin(void);
void handleInfo(void);
void handleReset(void);
void handleReboot(void);
bool parseStringAndSendAirCon(IRsend *irsend, const decode_type_t irType,
const String str);
uint16_t countValuesInStr(const String str, char sep);
uint16_t * newCodeArray(const uint16_t size);
#if SEND_GLOBALCACHE
bool parseStringAndSendGC(IRsend *irsend, const String str);
#endif // SEND_GLOBALCACHE
#if SEND_PRONTO
bool parseStringAndSendPronto(IRsend *irsend, const String str,
uint16_t repeats);
#endif // SEND_PRONTO
#if SEND_RAW
bool parseStringAndSendRaw(IRsend *irsend, const String str);
#endif // SEND_RAW
void handleIr(void);
void handleNotFound(void);
void setup_wifi(void);
void init_vars(void);
void setup(void);
void loop(void);
uint32_t maxSketchSpace(void);
uint64_t getUInt64fromHex(char const *str);
bool sendIRCode(IRsend *irsend, decode_type_t const ir_type,
uint64_t const code, char const * code_str, uint16_t bits,
uint16_t repeat);
bool sendInt(const String topic, const int32_t num, const bool retain);
bool sendBool(const String topic, const bool on, const bool retain);
bool sendString(const String topic, const String str, const bool retain);
bool sendFloat(const String topic, const float_t temp, const bool retain);
void updateClimate(stdAc::state_t *current, const String str,
const String prefix, const String payload);
bool cmpClimate(const stdAc::state_t a, const stdAc::state_t b);
bool sendClimate(const String topic_prefix, const bool retain,
const bool forceMQTT, const bool forceIR,
const bool enableIR = true, IRac *ac = NULL);
bool decodeCommonAc(const decode_results *decode);
#endif // EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,56 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
build_flags = -DMQTT_MAX_PACKET_SIZE=768 ; -D_IR_LOCALE_=en-AU
framework = arduino
platform = espressif8266
monitor_speed = 115200
[common]
lib_deps_builtin =
lib_deps_external =
PubSubClient
ArduinoJson@>=6.0
[common_esp8266]
lib_deps_external =
${common.lib_deps_builtin}
${common.lib_deps_external}
WifiManager@>=0.14
[common_esp32]
lib_deps_external =
${common.lib_deps_builtin}
${common.lib_deps_external}
https://github.com/tzapu/WiFiManager.git#development
[env:nodemcuv2]
board = nodemcuv2
lib_deps = ${common_esp8266.lib_deps_external}
[env:d1_mini]
board = d1_mini
lib_deps = ${common_esp8266.lib_deps_external}
[env:d1_mini_no_mqtt]
board = d1_mini
build_flags =
${env.build_flags}
-DMQTT_ENABLE=false
lib_deps = ${common_esp8266.lib_deps_external}
[env:esp32dev]
platform = espressif32
board = esp32dev
lib_deps = ${common_esp32.lib_deps_external}
[env:esp01_1m]
board = esp01_1m
build_flags =
${env.build_flags}
-Wl,-Teagle.flash.1m64.ld
lib_deps = ${common_esp8266.lib_deps_external}

View File

@@ -0,0 +1,149 @@
/*
* IRremoteESP8266: IRServer - demonstrates sending IR codes controlled from a webserver
* Version 0.3 May, 2019
* Version 0.2 June, 2017
* Copyright 2015 Mark Szabo
* Copyright 2019 David Conran
*
* An IR LED circuit *MUST* be connected to the ESP on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#endif // ESP8266
#if defined(ESP32)
#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#endif // ESP32
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <WiFiClient.h>
const char* kSsid = ".....";
const char* kPassword = ".....";
MDNSResponder mdns;
#if defined(ESP8266)
ESP8266WebServer server(80);
#undef HOSTNAME
#define HOSTNAME "esp8266"
#endif // ESP8266
#if defined(ESP32)
WebServer server(80);
#undef HOSTNAME
#define HOSTNAME "esp32"
#endif // ESP32
const uint16_t kIrLed = 4; // ESP GPIO pin to use. Recommended: 4 (D2).
IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
void handleRoot() {
server.send(200, "text/html",
"<html>" \
"<head><title>" HOSTNAME " Demo </title>" \
"<meta http-equiv=\"Content-Type\" " \
"content=\"text/html;charset=utf-8\">" \
"</head>" \
"<body>" \
"<h1>Hello from " HOSTNAME ", you can send NEC encoded IR" \
"signals from here!</h1>" \
"<p><a href=\"ir?code=16769055\">Send 0xFFE01F</a></p>" \
"<p><a href=\"ir?code=16429347\">Send 0xFAB123</a></p>" \
"<p><a href=\"ir?code=16771222\">Send 0xFFE896</a></p>" \
"</body>" \
"</html>");
}
void handleIr() {
for (uint8_t i = 0; i < server.args(); i++) {
if (server.argName(i) == "code") {
uint32_t code = strtoul(server.arg(i).c_str(), NULL, 10);
#if SEND_NEC
irsend.sendNEC(code, 32);
#endif // SEND_NEC
}
}
handleRoot();
}
void handleNotFound() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++)
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
server.send(404, "text/plain", message);
}
void setup(void) {
irsend.begin();
Serial.begin(115200);
WiFi.begin(kSsid, kPassword);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(kSsid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP().toString());
#if defined(ESP8266)
if (mdns.begin(HOSTNAME, WiFi.localIP())) {
#else // ESP8266
if (mdns.begin(HOSTNAME)) {
#endif // ESP8266
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/ir", handleIr);
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void) {
server.handleClient();
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,51 @@
/*
* IRremoteESP8266: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* This is very simple teaching code to show you how to use the library.
* If you are trying to decode your Infra-Red remote(s) for later replay,
* use the IRrecvDumpV2.ino (or later) example code instead of this.
* An IR detector/demodulator must be connected to the input kRecvPin.
* Copyright 2009 Ken Shirriff, http://arcfn.com
* Example circuit diagram:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-receiving
* Changes:
* Version 0.2 June, 2017
* Changed GPIO pin to the same as other examples.
* Used our own method for printing a uint64_t.
* Changed the baud rate to 115200.
* Version 0.1 Sept, 2015
* Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
// An IR detector/demodulator is connected to GPIO pin 14(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;
IRrecv irrecv(kRecvPin);
decode_results results;
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // Start the receiver
while (!Serial) // Wait for the serial connection to be establised.
delay(50);
Serial.println();
Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");
Serial.println(kRecvPin);
}
void loop() {
if (irrecv.decode(&results)) {
// print() & println() can't handle printing long longs. (uint64_t)
serialPrintUint64(results.value, HEX);
Serial.println("");
irrecv.resume(); // Receive the next value
}
delay(100);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
build_flags = ; -D_IR_LOCALE_=en-AU
monitor_speed = 115200
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,102 @@
/*
* IRremoteESP8266: IRrecvDump - dump details of IR codes with IRrecv
* Copyright 2009 Ken Shirriff, http://arcfn.com
*
***** DEPRECATED - DO NOT USE *****
* Unless you know what you are doing, you should be using the
* IRrecvDumpV2.ino sketch/example instead for capturing & decoding IR messages.
* In almost ALL ways it is BETTER, FASTER, and MORE DETAILED.
*
* This code is left only for legacy reasons, and as another simple example of
* how to use the IRremoteESP8266 library.
*
* As of November 2017 it will no longer be updated or supported.
* You have been warned.
***** DEPRECATED - DO NOT USE *****
*
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.2 Oct 2017
* Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009,
* JVC and Panasonic protocol added by Kristian Lauszus
* (Thanks to zenwheel and other people at the original blog post)
* LG added by Darryl Smith (based on the JVC protocol)
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
// an IR detector/demodulator is connected to GPIO pin 2
uint16_t RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // Start the receiver
}
void dump(decode_results *results) {
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
uint16_t count = results->rawlen;
if (results->decode_type == UNKNOWN) {
Serial.print("Unknown encoding: ");
} else if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
} else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
} else if (results->decode_type == RC5) {
Serial.print("Decoded RC5: ");
} else if (results->decode_type == RC5X) {
Serial.print("Decoded RC5X: ");
} else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
} else if (results->decode_type == RCMM) {
Serial.print("Decoded RCMM: ");
} else if (results->decode_type == PANASONIC) {
Serial.print("Decoded PANASONIC - Address: ");
Serial.print(results->address, HEX);
Serial.print(" Value: ");
} else if (results->decode_type == LG) {
Serial.print("Decoded LG: ");
} else if (results->decode_type == JVC) {
Serial.print("Decoded JVC: ");
} else if (results->decode_type == AIWA_RC_T501) {
Serial.print("Decoded AIWA RC T501: ");
} else if (results->decode_type == WHYNTER) {
Serial.print("Decoded Whynter: ");
} else if (results->decode_type == NIKAI) {
Serial.print("Decoded Nikai: ");
}
serialPrintUint64(results->value, 16);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): {");
for (uint16_t i = 1; i < count; i++) {
if (i % 100 == 0)
yield(); // Preemptive yield every 100th entry to feed the WDT.
if (i & 1) {
Serial.print(results->rawbuf[i] * kRawTick, DEC);
} else {
Serial.print(", ");
Serial.print((uint32_t) results->rawbuf[i] * kRawTick, DEC);
}
}
Serial.println("};");
}
void loop() {
if (irrecv.decode(&results)) {
dump(&results);
Serial.println("DEPRECATED: Please use IRrecvDumpV2.ino instead!");
irrecv.resume(); // Receive the next value
}
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,156 @@
/*
* 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,
*/
#include <Arduino.h>
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRac.h>
#include <IRtext.h>
#include <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.
#if 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;
#else // DECODE_AC
// Suits most messages, while not swallowing many repeats.
const uint8_t kTimeout = 15;
#endif // 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.
#define 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() {
#if defined(ESP8266)
Serial.begin(kBaudRate, SERIAL_8N1, SERIAL_TX_ONLY);
#else // ESP8266
Serial.begin(kBaudRate, SERIAL_8N1);
#endif // ESP8266
while (!Serial) // Wait for the serial connection to be establised.
delay(50);
Serial.printf("\n" D_STR_IRRECVDUMP_STARTUP "\n", kRecvPin);
#if DECODE_HASH
// Ignore messages with less than minimum on or off pulses.
irrecv.setUnknownThreshold(kMinUnknownSize);
#endif // 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.
#if LEGACY_TIMING_INFO
// Output legacy RAW timing info of the result.
Serial.println(resultToTimingInfo(&results));
yield(); // Feed the WDT (again)
#endif // LEGACY_TIMING_INFO
// Output the results as source code
Serial.println(resultToSourceCode(&results));
Serial.println(); // Blank line between entries
yield(); // Feed the WDT (again)
}
}

View File

@@ -0,0 +1,58 @@
[platformio]
src_dir = .
[env]
; Default platform
platform = espressif8266
; Default board
board = nodemcuv2
framework = arduino
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
board = nodemcuv2
; build_flags = -D_IR_LOCALE_=en-AU
[env:esp32dev]
platform = espressif32
board = esp32dev
; build_flags = -D_IR_LOCALE_=en-AU
[env:de-CH]
build_flags = -D_IR_LOCALE_=de-CH ; German (Swiss)
[env:de-DE]
build_flags = -D_IR_LOCALE_=de-DE ; German
[env:en-AU]
build_flags = -D_IR_LOCALE_=en-AU ; English (Australian) (Default)
[env:en-IE]
build_flags = -D_IR_LOCALE_=en-IE ; English (Irish)
[env:en-UK]
build_flags = -D_IR_LOCALE_=en-UK ; English (UK)
[env:en-US]
build_flags = -D_IR_LOCALE_=en-US ; English (Simplified) (USA)
[env:es-ES]
build_flags = -D_IR_LOCALE_=es-ES ; Spanish
[env:fr-FR]
build_flags = -D_IR_LOCALE_=fr-FR ; French
[env:it-IT]
build_flags = -D_IR_LOCALE_=it-IT ; Italian
[env:zh-CN]
build_flags = -D_IR_LOCALE_=zh-CN ; Chinese (Simplified)
; Build the library with all protocols disabled to flush out #if/#ifdef issues &
; any compiler warnings, by turning them into errors.
[env:shakedown_no_protocols]
build_flags = -D_IR_ENABLE_DEFAULT_=false -Werror

View File

@@ -0,0 +1,71 @@
// Copyright 2020 Christian Nilsson (@nikize)
// Based on public Arduino BasicOTA example
#ifndef EXAMPLES_IRRECVDUMPV3_BASEOTA_H_
#define EXAMPLES_IRRECVDUMPV3_BASEOTA_H_
#ifndef OTA_ENABLE
#define OTA_ENABLE false
#endif // OTA_ENABLE
#if OTA_ENABLE
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
void OTAwifi() {
// start default wifi (previously saved on the ESP) for OTA
WiFi.mode(WIFI_STA);
WiFi.begin();
}
void OTAinit() {
// See BasicOTA ESP example for source and settings
ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else
type = "filesystem";
Serial.println("Start updating " + type);
})
.onEnd([]() {
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println();
if (WiFi.waitForConnectResult() == WL_CONNECTED) {
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("Wifi Connection Failed.");
}
}
void OTAloopHandler() {
ArduinoOTA.handle();
}
#else // OTA_ENABLE
void OTAwifi() {}
void OTAinit() {}
void OTAloopHandler() {}
#endif // OTA_ENABLE
#endif // EXAMPLES_IRRECVDUMPV3_BASEOTA_H_

View File

@@ -0,0 +1,166 @@
/*
* IRremoteESP8266: IRrecvDumpV3 - 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.1 May, 2020
* - Create DumpV3 from DumpV2
* - Add OTA Base
* 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,
*/
// Allow over air update
// #define OTA_ENABLE true
#include "BaseOTA.h"
#include <Arduino.h>
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRac.h>
#include <IRtext.h>
#include <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.
#if 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;
#else // DECODE_AC
// Suits most messages, while not swallowing many repeats.
const uint8_t kTimeout = 15;
#endif // 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.
#define 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() {
OTAwifi(); // start default wifi (previously saved on the ESP) for OTA
#if defined(ESP8266)
Serial.begin(kBaudRate, SERIAL_8N1, SERIAL_TX_ONLY);
#else // ESP8266
Serial.begin(kBaudRate, SERIAL_8N1);
#endif // ESP8266
while (!Serial) // Wait for the serial connection to be establised.
delay(50);
Serial.printf("\n" D_STR_IRRECVDUMP_STARTUP "\n", kRecvPin);
OTAinit(); // setup OTA handlers and show IP
#if DECODE_HASH
// Ignore messages with less than minimum on or off pulses.
irrecv.setUnknownThreshold(kMinUnknownSize);
#endif // 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.
#if LEGACY_TIMING_INFO
// Output legacy RAW timing info of the result.
Serial.println(resultToTimingInfo(&results));
yield(); // Feed the WDT (again)
#endif // LEGACY_TIMING_INFO
// Output the results as source code
Serial.println(resultToSourceCode(&results));
Serial.println(); // Blank line between entries
yield(); // Feed the WDT (again)
}
OTAloopHandler();
}

View File

@@ -0,0 +1,53 @@
[platformio]
src_dir = .
[env]
; Default platform
platform = espressif8266
; Default board
board = nodemcuv2
framework = arduino
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
board = nodemcuv2
; build_flags = -D_IR_LOCALE_=en-AU
[env:esp32dev]
platform = espressif32
board = esp32dev
; build_flags = -D_IR_LOCALE_=en-AU
[env:de-CH]
build_flags = -D_IR_LOCALE_=de-CH ; German (Swiss)
[env:de-DE]
build_flags = -D_IR_LOCALE_=de-DE ; German
[env:en-AU]
build_flags = -D_IR_LOCALE_=en-AU ; English (Australian) (Default)
[env:en-IE]
build_flags = -D_IR_LOCALE_=en-IE ; English (Irish)
[env:en-UK]
build_flags = -D_IR_LOCALE_=en-UK ; English (UK)
[env:en-US]
build_flags = -D_IR_LOCALE_=en-US ; English (Simplified) (USA)
[env:es-ES]
build_flags = -D_IR_LOCALE_=es-ES ; Spanish
[env:fr-FR]
build_flags = -D_IR_LOCALE_=fr-FR ; French
[env:it-IT]
build_flags = -D_IR_LOCALE_=it-IT ; Italian
[env:zh-CN]
build_flags = -D_IR_LOCALE_=zh-CN ; Chinese (Simplified)

View File

@@ -0,0 +1,74 @@
/* IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend.
*
* Version 1.1 January, 2019
* Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009,
* Copyright 2009 Ken Shirriff, http://arcfn.com
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
// Example of data captured by IRrecvDumpV2.ino
uint16_t rawData[67] = {9000, 4500, 650, 550, 650, 1650, 600, 550, 650, 550,
600, 1650, 650, 550, 600, 1650, 650, 1650, 650, 1650,
600, 550, 650, 1650, 650, 1650, 650, 550, 600, 1650,
650, 1650, 650, 550, 650, 550, 650, 1650, 650, 550,
650, 550, 650, 550, 600, 550, 650, 550, 650, 550,
650, 1650, 600, 550, 650, 1650, 650, 1650, 650, 1650,
650, 1650, 650, 1650, 650, 1650, 600};
// Example Samsung A/C state captured from IRrecvDumpV2.ino
uint8_t samsungState[kSamsungAcStateLength] = {
0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0,
0x01, 0xE2, 0xFE, 0x71, 0x40, 0x11, 0xF0};
void setup() {
irsend.begin();
#if ESP8266
Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
#else // ESP8266
Serial.begin(115200, SERIAL_8N1);
#endif // ESP8266
}
void loop() {
Serial.println("NEC");
irsend.sendNEC(0x00FFE01FUL);
delay(2000);
Serial.println("Sony");
irsend.sendSony(0xa90, 12, 2); // 12 bits & 2 repeats
delay(2000);
Serial.println("a rawData capture from IRrecvDumpV2");
irsend.sendRaw(rawData, 67, 38); // Send a raw data capture at 38kHz.
delay(2000);
Serial.println("a Samsung A/C state from IRrecvDumpV2");
irsend.sendSamsungAC(samsungState);
delay(2000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,114 @@
/* IRremoteESP8266: IRsendProntoDemo
* Copyright 2017 David Conran
*
* Demonstrates sending Pronto codes with IRsend.
*
* Version 1.0 June, 2017
*
* An IR LED circuit *MUST* be connected to ESP8266 pin 4 (D2), unless you
* change the kIrLed value below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
// Panasonic Plasma TV Descrete code (Power On).
// Acquired from:
// https://irdb.globalcache.com/
// e.g.
// 0000 006D 0000 0022 00ac 00ac 0016 0040 0016 0040 0016 0040 0016 0015 0016
// 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0040 0016 0040 0016 0015
// 0016 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0015 0016 0015 0016
// 0040 0016 0040 0016 0015 0016 0015 0016 0040 0016 0015 0016 0040 0016 0040
// 0016 0015 0016 0015 0016 0040 0016 0040 0016 0015 0016 071c
//
// Or the equiv. of sendSamsung(0xE0E09966);
uint16_t samsungProntoCode[72] = {
0x0000, 0x006D, 0x0000, 0x0022,
0x00ac, 0x00ac, 0x0016, 0x0040, 0x0016, 0x0040, 0x0016, 0x0040,
0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015,
0x0016, 0x0015, 0x0016, 0x0040, 0x0016, 0x0040, 0x0016, 0x0040,
0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015,
0x0016, 0x0015, 0x0016, 0x0040, 0x0016, 0x0015, 0x0016, 0x0015,
0x0016, 0x0040, 0x0016, 0x0040, 0x0016, 0x0015, 0x0016, 0x0015,
0x0016, 0x0040, 0x0016, 0x0015, 0x0016, 0x0040, 0x0016, 0x0040,
0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0040, 0x0016, 0x0040,
0x0016, 0x0015, 0x0016, 0x071c
};
// Panasonic Plasma TV Descrete code (Power On).
// Acquired from:
// ftp://ftp.panasonic.com/pub/panasonic/drivers/monitors/Discrete-remote-control-codesProntoCCFformat.pdf
// e.g.
// 0000 0071 0000 0032 0080 003F 0010 0010 0010 0030 0010 0010 0010 0010 0010
// 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010
// 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010
// 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010
// 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010
// 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0010 0010 0030
// 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0030 0010 0A98
//
// Or the equiv. of sendPanasonic64(0x400401007C7D);
uint16_t panasonicProntoCode[104] = {
0x0000, 0x0071, 0x0000, 0x0032,
0x0080, 0x003F, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0030, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0030,
0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0030,
0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0010,
0x0010, 0x0030, 0x0010, 0x0A98};
void setup() {
irsend.begin();
#if defined(ESP8266)
Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
#else // ESP8266
Serial.begin(115200, SERIAL_8N1);
#endif // ESP8266
}
void loop() {
#if SEND_PRONTO
Serial.println("Sending a Samsung TV 'on' command.");
irsend.sendPronto(samsungProntoCode, 72);
delay(2000);
Serial.println("Sending a Panasonic Plasma TV 'on' command.");
irsend.sendPronto(panasonicProntoCode, 104);
delay(2000);
#else // SEND_PRONTO
Serial.println("Can't send because SEND_PRONTO has been disabled.");
delay(10000);
#endif // SEND_PRONTO
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,61 @@
/*
* IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend
* Version 0.1 June, 2015
* Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
const uint16_t kPanasonicAddress = 0x4004; // Panasonic address (Pre data)
const uint32_t kPanasonicPower = 0x100BCBD; // Panasonic Power button
const uint16_t kJVCPower = 0xC5E8;
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
void setup() {
irsend.begin();
}
void loop() {
// This should turn your TV on and off
#if SEND_PANASONIC
irsend.sendPanasonic(kPanasonicAddress, kPanasonicPower);
#else // SEND_PANASONIC
Serial.println("Can't send because SEND_PANASONIC has been disabled.");
#endif // SEND_PANASONIC
#if SEND_JVC
irsend.sendJVC(kJVCPower, 16, 1); // hex value, 16 bits, single repeat
#else // SEND_JVC
Serial.println("Can't send because SEND_JVC has been disabled.");
#endif // SEND_JVC
delay(10000); // Wait 10 seconds before we repeat everything.
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,263 @@
// Copyright 2015 chaeplin
// Copyright 2017 xpokor22
// This is based on:
// https://github.com/z3t0/Arduino-IRremote/blob/master/examples/LGACSendDemo/LGACSendDemo.ino
#include <IRremoteESP8266.h>
#include <IRsend.h>
IRsend irsend(14); // An IR LED is controlled by GPIO pin 14 (D5)
// 0 : TOWER
// 1 : WALL
const unsigned int kAc_Type = 1;
// 0 : cooling
// 1 : heating
unsigned int ac_heat = 1;
// 0 : off
// 1 : on
unsigned int ac_power_on = 0;
// 0 : off
// 1 : on --> power on
unsigned int ac_air_clean_state = 0;
// temperature : 18 ~ 30
unsigned int ac_temperature = 24;
// 0 : low
// 1 : mid
// 2 : high
// if kAc_Type = 1, 3 : change
unsigned int ac_flow = 0;
const uint8_t kAc_Flow_Tower[3] = {0, 4, 6};
const uint8_t kAc_Flow_Wall[4] = {0, 2, 4, 5};
uint32_t ac_code_to_sent;
void Ac_Send_Code(uint32_t code) {
Serial.print("code to send : ");
Serial.print(code, BIN);
Serial.print(" : ");
Serial.println(code, HEX);
#if SEND_LG
irsend.sendLG(code, 28);
#else // SEND_LG
Serial.println("Can't send because SEND_LG has been disabled.");
#endif // SEND_LG
}
void Ac_Activate(unsigned int temperature, unsigned int air_flow,
unsigned int heat) {
ac_heat = heat;
unsigned int ac_msbits1 = 8;
unsigned int ac_msbits2 = 8;
unsigned int ac_msbits3 = 0;
unsigned int ac_msbits4;
if (ac_heat == 1)
ac_msbits4 = 4; // heating
else
ac_msbits4 = 0; // cooling
unsigned int ac_msbits5 = (temperature < 15) ? 0 : temperature - 15;
unsigned int ac_msbits6 = 0;
if (air_flow <= 2) {
if (kAc_Type == 0)
ac_msbits6 = kAc_Flow_Tower[air_flow];
else
ac_msbits6 = kAc_Flow_Wall[air_flow];
}
// calculating using other values
unsigned int ac_msbits7 = (ac_msbits3 + ac_msbits4 + ac_msbits5 +
ac_msbits6) & B00001111;
ac_code_to_sent = ac_msbits1 << 4;
ac_code_to_sent = (ac_code_to_sent + ac_msbits2) << 4;
ac_code_to_sent = (ac_code_to_sent + ac_msbits3) << 4;
ac_code_to_sent = (ac_code_to_sent + ac_msbits4) << 4;
ac_code_to_sent = (ac_code_to_sent + ac_msbits5) << 4;
ac_code_to_sent = (ac_code_to_sent + ac_msbits6) << 4;
ac_code_to_sent = (ac_code_to_sent + ac_msbits7);
Ac_Send_Code(ac_code_to_sent);
ac_power_on = 1;
ac_temperature = temperature;
ac_flow = air_flow;
}
void Ac_Change_Air_Swing(int air_swing) {
if (kAc_Type == 0) {
if (air_swing == 1)
ac_code_to_sent = 0x881316B;
else
ac_code_to_sent = 0x881317C;
} else {
if (air_swing == 1)
ac_code_to_sent = 0x8813149;
else
ac_code_to_sent = 0x881315A;
}
Ac_Send_Code(ac_code_to_sent);
}
void Ac_Power_Down() {
ac_code_to_sent = 0x88C0051;
Ac_Send_Code(ac_code_to_sent);
ac_power_on = 0;
}
void Ac_Air_Clean(int air_clean) {
if (air_clean == '1')
ac_code_to_sent = 0x88C000C;
else
ac_code_to_sent = 0x88C0084;
Ac_Send_Code(ac_code_to_sent);
ac_air_clean_state = air_clean;
}
void setup() {
Serial.begin(115200);
delay(1000);
irsend.begin();
}
void loop() {
char b = ' ';
Serial.println("# a : mode or temp b : air_flow, temp, swing, clean,"
" cooling/heating");
Serial.println("# 0 : off 0");
Serial.println("# 1 : on 0");
Serial.println("# 2 : air_swing 0 or 1");
Serial.println("# 3 : air_clean 0 or 1");
Serial.println("# 4 : air_flow 0 ~ 2 : flow");
Serial.println("# + : temp + 1");
Serial.println("# - : temp - 1");
Serial.println("# c : cooling");
Serial.println("# h : heating");
Serial.println("# m : change cooling to air clean, air clean to cooling");
Serial.println("a="); // Prompt User for input
while (Serial.available() == 0) { // Wait for user input
}
char a = Serial.read(); // Read user input into a
switch (a) {
case '0':
case '1':
case '+':
case '-':
case 'c':
case 'h':
case 'm':
break;
default:
Serial.println("b="); // Prompt User for input
while (Serial.available() == 0) {}
b = Serial.read();
}
/*
# a : mode or temp b : air_flow, temp, swing, clean, cooling/heating
# 18 ~ 30 : temp 0 ~ 2 : flow // on
# 0 : off 0
# 1 : on 0
# 2 : air_swing 0 or 1
# 3 : air_clean 0 or 1
# 4 : air_flow 0 ~ 3 : flow
# + : temp + 1
# - : temp - 1
# c : cooling
# h : heating
# m : change cooling to air clean, air clean to cooling
*/
Serial.print("a : ");
Serial.print(a);
Serial.print(" b : ");
Serial.println(b);
switch (a) {
case '0': // off
Ac_Power_Down();
break;
case '1': // on
Ac_Activate(ac_temperature, ac_flow, ac_heat);
break;
case '2':
if (b == '0')
Ac_Change_Air_Swing(0);
else
Ac_Change_Air_Swing(1);
break;
case '3': // 1 : clean on, power on
if (b == '0' || b == '1')
Ac_Air_Clean(b);
break;
case '4':
switch (b) {
case '1':
Ac_Activate(ac_temperature, 1, ac_heat);
break;
case '2':
Ac_Activate(ac_temperature, 2, ac_heat);
break;
case '3':
Ac_Activate(ac_temperature, 3, ac_heat);
break;
default:
Ac_Activate(ac_temperature, 0, ac_heat);
}
break;
case '+':
if (18 <= ac_temperature && ac_temperature <= 29)
Ac_Activate((ac_temperature + 1), ac_flow, ac_heat);
break;
case '-':
if (19 <= ac_temperature && ac_temperature <= 30)
Ac_Activate((ac_temperature - 1), ac_flow, ac_heat);
break;
case 'c':
ac_heat = 0;
Ac_Activate(ac_temperature, ac_flow, ac_heat);
break;
case 'h':
ac_heat = 1;
Ac_Activate(ac_temperature, ac_flow, ac_heat);
break;
case 'm':
/*
if ac is on, 1) turn off, 2) turn on Ac_Air_Clean(1)
if ac is off, 1) turn on, 2) turn off Ac_Air_Clean(0)
*/
if (ac_power_on == 1) {
Ac_Power_Down();
delay(100);
Ac_Air_Clean(1);
} else {
if (ac_air_clean_state == 1) {
Ac_Air_Clean(0);
delay(100);
}
Ac_Activate(ac_temperature, ac_flow, ac_heat);
}
break;
}
delay(100);
Serial.println("ac_temperature");
Serial.println(ac_temperature);
Serial.println("ac_flow");
Serial.println(ac_flow);
Serial.println("ac_heat");
Serial.println(ac_heat);
Serial.println("ac_power_on");
Serial.println(ac_power_on);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,148 @@
/*
* IRremoteESP8266: SmartIRRepeater.ino - Record and playback IR codes.
* Copyright 2019 David Conran (crankyoldgit)
*
* This program will try to capture incoming IR messages and tries to
* intelligently replay them back.
* It uses the advanced detection features of the library, and the custom
* sending routines. Thus it will try to use the correct frequencies,
* duty cycles, and repeats as it thinks is required.
* Anything it doesn't understand, it will try to replay back as best it can,
* but at 38kHz.
* Note:
* That might NOT be the frequency of the incoming message, so some not
* recogised messages that are replayed may not work. The frequency & duty
* cycle of unknown incoming messages is lost at the point of the Hardware IR
* demodulator. The ESP can't see it.
*
* W A R N I N G
* This code is just for educational/example use only. No help will be given
* to you to make it do something else, or to make it work with some
* weird device or circuit, or to make it more usable or practical.
* If it works for you. Great. If not, Congratulations on changing/fixing it.
*
* An IR detector/demodulator must be connected to the input, kRecvPin.
* An IR LED circuit must be connected to the output, kIrLedPin.
*
* Example circuit diagrams (both are needed):
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-receiving
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * Some 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 ESP will interfere.
* * Pin 3/RX/RXD0: Any serial transmissions to the ESP will interfere.
* * Pin 16/D0: Has no interrupts on the ESP8266, so can't be used for IR
* receiving with this library.
* * ESP-01 modules are tricky. We suggest you use a module with more GPIOs
* for your first time. e.g. ESP-12 etc.
*
* Changes:
* Version 1.0: June, 2019
* - Initial version.
*/
#include <Arduino.h>
#include <IRsend.h>
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRutils.h>
// ==================== start of TUNEABLE PARAMETERS ====================
// The GPIO an IR detector/demodulator is connected to. Recommended: 14 (D5)
// Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts.
const uint16_t kRecvPin = 14;
// GPIO to use to control the IR LED circuit. Recommended: 4 (D2).
const uint16_t kIrLedPin = 4;
// The Serial connection baud rate.
// 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/resender, let's use a larger
// than expected buffer so we can handle very large IR messages.
const uint16_t kCaptureBufferSize = 1024; // 1024 == ~511 bits
// kTimeout is the Nr. of milli-Seconds of no-more-data before we consider a
// message ended.
const uint8_t kTimeout = 50; // Milli-Seconds
// kFrequency is the modulation frequency all UNKNOWN messages will be sent at.
const uint16_t kFrequency = 38000; // in Hz. e.g. 38kHz.
// ==================== end of TUNEABLE PARAMETERS ====================
// The IR transmitter.
IRsend irsend(kIrLedPin);
// The IR receiver.
IRrecv irrecv(kRecvPin, kCaptureBufferSize, kTimeout, false);
// Somewhere to store the captured message.
decode_results results;
// This section of code runs only once at start-up.
void setup() {
irrecv.enableIRIn(); // Start up the IR receiver.
irsend.begin(); // Start up the IR sender.
Serial.begin(kBaudRate, SERIAL_8N1);
while (!Serial) // Wait for the serial connection to be establised.
delay(50);
Serial.println();
Serial.print("SmartIRRepeater is now running and waiting for IR input "
"on Pin ");
Serial.println(kRecvPin);
Serial.print("and will retransmit it on Pin ");
Serial.println(kIrLedPin);
}
// The repeating section of the code
void loop() {
// Check if an IR message has been received.
if (irrecv.decode(&results)) { // We have captured something.
// The capture has stopped at this point.
decode_type_t protocol = results.decode_type;
uint16_t size = results.bits;
bool success = true;
// Is it a protocol we don't understand?
if (protocol == decode_type_t::UNKNOWN) { // Yes.
// Convert the results into an array suitable for sendRaw().
// resultToRawArray() allocates the memory we need for the array.
uint16_t *raw_array = resultToRawArray(&results);
// Find out how many elements are in the array.
size = getCorrectedRawLength(&results);
#if SEND_RAW
// Send it out via the IR LED circuit.
irsend.sendRaw(raw_array, size, kFrequency);
#endif // SEND_RAW
// Deallocate the memory allocated by resultToRawArray().
delete [] raw_array;
} else if (hasACState(protocol)) { // Does the message require a state[]?
// It does, so send with bytes instead.
success = irsend.send(protocol, results.state, size / 8);
} else { // Anything else must be a simple message protocol. ie. <= 64 bits
success = irsend.send(protocol, results.value, size);
}
// Resume capturing IR messages. It was not restarted until after we sent
// the message so we didn't capture our own message.
irrecv.resume();
// Display a crude timestamp & notification.
uint32_t now = millis();
Serial.printf(
"%06u.%03u: A %d-bit %s message was %ssuccessfully retransmitted.\n",
now / 1000, now % 1000, size, typeToString(protocol).c_str(),
success ? "" : "un");
}
yield(); // Or delay(milliseconds); This ensures the ESP doesn't WDT reset.
}

View File

@@ -0,0 +1,36 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev
; Build the program forcing the compiler to treat all warnings as errors.
[env:shakedown_all_protocols]
platform = espressif8266
board = nodemcuv2
build_flags =
${env.build_flags}
-Werror
; Disable all protocols to see if we can force any errors.
; Build the program forcing the compiler to treat all warnings as errors.
[env:shakedown_no_protocols]
platform = espressif8266
board = nodemcuv2
build_flags =
${env.build_flags}
-Werror
-D_IR_ENABLE_DEFAULT_=false

View File

@@ -0,0 +1,56 @@
/* Copyright 2017, 2018 crankyoldgit
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Argo.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRArgoAC ac(kIrLed); // Set the GPIO to be used to sending the message.
void setup() {
ac.begin();
Serial.begin(115200);
}
void loop() {
Serial.println("Sending...");
// Set up what we want to send. See ir_Argo.cpp for all the options.
ac.setPower(true);
ac.setFan(kArgoFan1);
ac.setMode(kArgoAuto);
ac.setTemp(25);
#if SEND_ARGO
// Now send the IR signal.
ac.send();
#else // SEND_ARGO
Serial.println("Can't send because SEND_ARGO has been disabled.");
#endif // SEND_ARGO
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,67 @@
/* Copyright 2017 sillyfrog
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Daikin.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRDaikinESP ac(kIrLed); // Set the GPIO to be used to sending the message
void setup() {
ac.begin();
Serial.begin(115200);
}
void loop() {
Serial.println("Sending...");
// Set up what we want to send. See ir_Daikin.cpp for all the options.
ac.on();
ac.setFan(1);
ac.setMode(kDaikinCool);
ac.setTemp(25);
ac.setSwingVertical(false);
ac.setSwingHorizontal(false);
// Set the current time to 1:33PM (13:33)
// Time works in minutes past midnight
ac.setCurrentTime(13 * 60 + 33);
// Turn off about 1 hour later at 2:30PM (14:30)
ac.enableOffTimer(14 * 60 + 30);
// Display what we are going to send.
Serial.println(ac.toString());
// Now send the IR signal.
#if SEND_DAIKIN
ac.send();
#endif // SEND_DAIKIN
delay(15000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,50 @@
// Copyright 2017 Jonny Graham, 2018 David Conran
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Fujitsu.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRFujitsuAC ac(kIrLed);
void printState() {
// Display the settings.
Serial.println("Fujitsu A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < ac.getStateLength(); i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void setup() {
ac.begin();
Serial.begin(115200);
delay(200);
// Set up what we want to send. See ir_Fujitsu.cpp for all the options.
Serial.println("Default state of the remote.");
printState();
Serial.println("Setting desired state for A/C.");
// See `fujitsu_ac_remote_model_t` in `ir_Fujitsu.h` for a list of models.
ac.setModel(ARRAH2E);
ac.setSwing(kFujitsuAcSwingOff);
ac.setMode(kFujitsuAcModeCool);
ac.setFanSpeed(kFujitsuAcFanHigh);
ac.setTemp(24); // 24C
ac.setCmd(kFujitsuAcCmdTurnOn);
}
void loop() {
// Now send the IR signal.
Serial.println("Sending IR command to A/C ...");
#if SEND_FUJITSU_AC
ac.send();
#else // SEND_FUJITSU_AC
Serial.println("Can't send because SEND_FUJITSU_AC has been disabled.");
#endif // SEND_FUJITSU_AC
printState();
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,77 @@
/* Copyright 2016, 2018 David Conran
* Copyright 2020 Sadid Rafsun Tulon
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Gree.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRGreeAC ac(kIrLed); // Set the GPIO to be used for sending messages.
void printState() {
// Display the settings.
Serial.println("GREE A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < kGreeStateLength; i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void setup() {
ac.begin();
Serial.begin(115200);
delay(200);
// Set up what we want to send. See ir_Gree.cpp for all the options.
// Most things default to off.
Serial.println("Default state of the remote.");
printState();
Serial.println("Setting desired state for A/C.");
ac.on();
ac.setFan(1);
// kGreeAuto, kGreeDry, kGreeCool, kGreeFan, kGreeHeat
ac.setMode(kGreeCool);
ac.setTemp(20); // 16-30C
ac.setSwingVertical(true, kGreeSwingAuto);
ac.setXFan(false);
ac.setLight(false);
ac.setSleep(false);
ac.setTurbo(false);
}
void loop() {
// Now send the IR signal.
#if SEND_GREE
Serial.println("Sending IR command to A/C ...");
ac.send();
#endif // SEND_GREE
printState();
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,75 @@
/* Copyright 2016, 2018 David Conran
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Kelvinator.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRKelvinatorAC ac(kIrLed); // Set the GPIO to be used for sending messages.
void printState() {
// Display the settings.
Serial.println("Kelvinator A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < kKelvinatorStateLength; i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void setup() {
ac.begin();
Serial.begin(115200);
delay(200);
// Set up what we want to send. See ir_Kelvinator.cpp for all the options.
// Most things default to off.
Serial.println("Default state of the remote.");
printState();
Serial.println("Setting desired state for A/C.");
ac.on();
ac.setFan(1);
ac.setMode(kKelvinatorCool);
ac.setTemp(26);
ac.setSwingVertical(false);
ac.setSwingHorizontal(true);
ac.setXFan(true);
ac.setIonFilter(false);
ac.setLight(true);
}
void loop() {
// Now send the IR signal.
#if SEND_KELVINATOR
Serial.println("Sending IR command to A/C ...");
ac.send();
#endif // SEND_KELVINATOR
printState();
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,70 @@
/* Copyright 2017, 2018 David Conran
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Mitsubishi.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRMitsubishiAC ac(kIrLed); // Set the GPIO used for sending messages.
void printState() {
// Display the settings.
Serial.println("Mitsubishi A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < kMitsubishiACStateLength; i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void setup() {
ac.begin();
Serial.begin(115200);
delay(200);
// Set up what we want to send. See ir_Mitsubishi.cpp for all the options.
Serial.println("Default state of the remote.");
printState();
Serial.println("Setting desired state for A/C.");
ac.on();
ac.setFan(1);
ac.setMode(kMitsubishiAcCool);
ac.setTemp(26);
ac.setVane(kMitsubishiAcVaneAuto);
}
void loop() {
// Now send the IR signal.
#if SEND_MITSUBISHI_AC
Serial.println("Sending IR command to A/C ...");
ac.send();
#endif // SEND_MITSUBISHI_AC
printState();
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,70 @@
/* Copyright 2019 David Conran
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_MitsubishiHeavy.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRMitsubishiHeavy152Ac ac(kIrLed); // Set the GPIO used for sending messages.
void printState() {
// Display the settings.
Serial.println("Mitsubishi Heavy A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < kMitsubishiHeavy152StateLength; i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void setup() {
ac.begin();
Serial.begin(115200);
delay(200);
// Set up what we want to send. See ir_MitsubishiHeavy.(cpp|h) for all the
// options.
Serial.println("Default state of the remote.");
printState();
Serial.println("Setting desired state for A/C.");
ac.setPower(true); // Turn it on.
ac.setFan(kMitsubishiHeavy152FanMed); // Medium Fan
ac.setMode(kMitsubishiHeavyCool); // Cool mode
ac.setTemp(26); // Celsius
ac.setSwingVertical(kMitsubishiHeavy152SwingVAuto); // Swing vertically
ac.setSwingHorizontal(kMitsubishiHeavy152SwingHMiddle); // Swing Horizontally
}
void loop() {
// Now send the IR signal.
Serial.println("Sending IR command to A/C ...");
ac.send();
printState();
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,72 @@
/* Copyright 2017, 2018 David Conran
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Panasonic.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRPanasonicAc ac(kIrLed); // Set the GPIO used for sending messages.
void printState() {
// Display the settings.
Serial.println("Panasonic A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < kPanasonicAcStateLength; i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void setup() {
ac.begin();
Serial.begin(115200);
delay(200);
// Set up what we want to send. See ir_Panasonic.cpp for all the options.
Serial.println("Default state of the remote.");
printState();
Serial.println("Setting desired state for A/C.");
ac.setModel(kPanasonicRkr);
ac.on();
ac.setFan(kPanasonicAcFanAuto);
ac.setMode(kPanasonicAcCool);
ac.setTemp(26);
ac.setSwingVertical(kPanasonicAcSwingVAuto);
ac.setSwingHorizontal(kPanasonicAcSwingHAuto);
}
void loop() {
// Now send the IR signal.
#if SEND_PANASONIC_AC
Serial.println("Sending IR command to A/C ...");
ac.send();
#endif // SEND_PANASONIC_AC
printState();
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,69 @@
/* Copyright 2017, 2018 David Conran
*
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Toshiba.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRToshibaAC ac(kIrLed); // Set the GPIO to be used for sending messages.
void printState() {
// Display the settings.
Serial.println("Toshiba A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < kToshibaACStateLength; i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void setup() {
ac.begin();
Serial.begin(115200);
delay(200);
// Set up what we want to send. See ir_Toshiba.cpp for all the options.
Serial.println("Default state of the remote.");
printState();
Serial.println("Setting desired state for A/C.");
ac.on();
ac.setFan(1);
ac.setMode(kToshibaAcCool);
ac.setTemp(26);
}
void loop() {
// Now send the IR signal.
#if SEND_TOSHIBA_AC
Serial.println("Sending IR command to A/C ...");
ac.send();
#endif // SEND_TOSHIBA_AC
printState();
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,56 @@
/* Copyright 2017 stufisher
* An IR LED circuit *MUST* be connected to the ESP8266 on a pin
* as specified by kIrLed below.
*
* TL;DR: The IR LED needs to be driven by a transistor for a good result.
*
* Suggested circuit:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* 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: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
* * 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.
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Trotec.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRTrotecESP ac(kIrLed); // Set the GPIO to be used for sending messages.
void setup() {
ac.begin();
Serial.begin(115200);
}
void loop() {
Serial.println("Sending...");
// Set up what we want to send. See ir_Trotec.cpp for all the options.
ac.setPower(true);
ac.setSpeed(kTrotecFanLow);
ac.setMode(kTrotecCool);
ac.setTemp(25);
// Now send the IR signal.
#if SEND_TROTEC
ac.send();
#else // SEND_TROTEC
Serial.println("Can't send because SEND_TROTEC has been disabled.");
#endif // SEND_TROTEC
delay(5000);
}

View File

@@ -0,0 +1,18 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
[env:esp32dev]
platform = espressif32
board = esp32dev

View File

@@ -0,0 +1,43 @@
# esp8266-AC-control
This is just a web interface for the IRremoteESP8266 library.
![Web Gui Preview](https://github.com/mariusmotea/esp8266-AC-control/raw/master/printscreen.png)
## Instructions:
- Connect IR led to one GPIO pin (recommended pin is GPIO4)
- Edit esp8266-AC-control.ino header marked as "User space". You will need to import the library dedicated for your AC model. Every library has its own commands for AC mode and fan speed that will need to be replace according to commands available in .h file of the library.
- Flash the firmware in ESP board using 1M or 2M of SPIFFS storage.
- Connect the board to your wifi network (look for "AC Remote Control" SSID and follow WiFi Manager wizard)
- Upload web application files in SPIFFS storage using build in web form located at /file-upload path.
## REST API:
Browser console will show the ajax calls to ESP8266 board. Running configuration can be displayed with GET request to /state path, any value can be changed with http PUT request to same path.
Ex:
```
➜ ~ curl 192.168.0.71/state
{"mode":2,"fan":0,"temp":27,"power":true}%
➜ ~ curl -X PUT -d '{"temp":22}' 192.168.0.71/state
{"temp":22}%
➜ ~ curl 192.168.0.71/state
{"mode":2,"fan":0,"temp":22,"power":true}%
```
## DEBUG:
Use mobile phone camera to see if the led is sending any IR signals when buttons are pressed. This will show if the circuit was properly made and the selected GPIO pin is the correct one.
## Credits:
Interface: https://github.com/ael-code/daikin-control

View File

@@ -0,0 +1,300 @@
/* Copyright 2019 Motea Marius
This example code will create a webserver that will provide basic control to AC units using the web application
build with javascript/css. User config zone need to be updated if a different class than Collix need to be used.
Javasctipt file may also require minor changes as in current version it will not allow to set fan speed if Auto mode
is selected (required for Coolix).
*/
#include <FS.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#include <ESP8266WebServer.h>
#endif // ESP8266
#if defined(ESP32)
#include <ESPmDNS.h>
#include <WebServer.h>
#include <WiFi.h>
#include <SPIFFS.h>
#include <Update.h>
#endif // ESP32
#include <WiFiUdp.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
//// ###### User configuration space for AC library classes ##########
#include <ir_Coolix.h> // replace library based on your AC unit model, check https://github.com/crankyoldgit/IRremoteESP8266
#define AUTO_MODE kCoolixAuto
#define COOL_MODE kCoolixCool
#define DRY_MODE kCoolixDry
#define HEAT_MODE kCoolixHeat
#define FAN_MODE kCoolixFan
#define FAN_AUTO kCoolixFanAuto
#define FAN_MIN kCoolixFanMin
#define FAN_MED kCoolixFanMed
#define FAN_HI kCoolixFanMax
// ESP8266 GPIO pin to use for IR blaster.
const uint16_t kIrLed = 4;
// Library initialization, change it according to the imported library file.
IRCoolixAC ac(kIrLed);
/// ##### End user configuration ######
struct state {
uint8_t temperature = 22, fan = 0, operation = 0;
bool powerStatus;
};
File fsUploadFile;
// core
state acState;
// settings
char deviceName[] = "AC Remote Control";
#if defined(ESP8266)
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdateServer;
#endif // ESP8266
#if defined(ESP32)
WebServer server(80);
#endif // ESP32
bool handleFileRead(String path) {
// send the right file to the client (if it exists)
// Serial.println("handleFileRead: " + path);
if (path.endsWith("/")) path += "index.html";
// If a folder is requested, send the index file
String contentType = getContentType(path);
// Get the MIME type
String pathWithGz = path + ".gz";
if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
// If the file exists, either as a compressed archive, or normal
if (SPIFFS.exists(pathWithGz)) // If there's a compressed version available
path += ".gz"; // Use the compressed verion
File file = SPIFFS.open(path, "r");
// Open the file
server.streamFile(file, contentType);
// Send it to the client
file.close();
// Close the file again
// Serial.println(String("\tSent file: ") + path);
return true;
}
// Serial.println(String("\tFile Not Found: ") + path);
// If the file doesn't exist, return false
return false;
}
String getContentType(String filename) {
// convert the file extension to the MIME type
if (filename.endsWith(".html")) return "text/html";
else if (filename.endsWith(".css")) return "text/css";
else if (filename.endsWith(".js")) return "application/javascript";
else if (filename.endsWith(".ico")) return "image/x-icon";
else if (filename.endsWith(".gz")) return "application/x-gzip";
return "text/plain";
}
void handleFileUpload() { // upload a new file to the SPIFFS
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
String filename = upload.filename;
if (!filename.startsWith("/")) filename = "/" + filename;
// Serial.print("handleFileUpload Name: "); //Serial.println(filename);
fsUploadFile = SPIFFS.open(filename, "w");
// Open the file for writing in SPIFFS (create if it doesn't exist)
filename = String();
} else if (upload.status == UPLOAD_FILE_WRITE) {
if (fsUploadFile)
fsUploadFile.write(upload.buf, upload.currentSize);
// Write the received bytes to the file
} else if (upload.status == UPLOAD_FILE_END) {
if (fsUploadFile) {
// If the file was successfully created
fsUploadFile.close();
// Close the file again
// Serial.print("handleFileUpload Size: ");
// Serial.println(upload.totalSize);
server.sendHeader("Location", "/success.html");
// Redirect the client to the success page
server.send(303);
} else {
server.send(500, "text/plain", "500: couldn't create file");
}
}
}
void handleNotFound() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}
void setup() {
// Serial.begin(115200);
// Serial.println();
ac.begin();
delay(1000);
// Serial.println("mounting FS...");
if (!SPIFFS.begin()) {
// Serial.println("Failed to mount file system");
return;
}
WiFiManager wifiManager;
if (!wifiManager.autoConnect(deviceName)) {
delay(3000);
ESP.restart();
delay(5000);
}
#if defined(ESP8266)
httpUpdateServer.setup(&server);
#endif // ESP8266
server.on("/state", HTTP_PUT, []() {
DynamicJsonDocument root(1024);
DeserializationError error = deserializeJson(root, server.arg("plain"));
if (error) {
server.send(404, "text/plain", "FAIL. " + server.arg("plain"));
} else {
if (root.containsKey("temp")) {
acState.temperature = (uint8_t) root["temp"];
}
if (root.containsKey("fan")) {
acState.fan = (uint8_t) root["fan"];
}
if (root.containsKey("power")) {
acState.powerStatus = root["power"];
}
if (root.containsKey("mode")) {
acState.operation = root["mode"];
}
String output;
serializeJson(root, output);
server.send(200, "text/plain", output);
delay(200);
if (acState.powerStatus) {
ac.on();
ac.setTemp(acState.temperature);
if (acState.operation == 0) {
ac.setMode(AUTO_MODE);
ac.setFan(FAN_AUTO);
acState.fan = 0;
} else if (acState.operation == 1) {
ac.setMode(COOL_MODE);
} else if (acState.operation == 2) {
ac.setMode(DRY_MODE);
} else if (acState.operation == 3) {
ac.setMode(HEAT_MODE);
} else if (acState.operation == 4) {
ac.setMode(FAN_MODE);
}
if (acState.operation != 0) {
if (acState.fan == 0) {
ac.setFan(FAN_AUTO);
} else if (acState.fan == 1) {
ac.setFan(FAN_MIN);
} else if (acState.fan == 2) {
ac.setFan(FAN_MED);
} else if (acState.fan == 3) {
ac.setFan(FAN_HI);
}
}
} else {
ac.off();
}
ac.send();
}
});
server.on("/file-upload", HTTP_POST,
// if the client posts to the upload page
[]() {
// Send status 200 (OK) to tell the client we are ready to receive
server.send(200);
},
handleFileUpload); // Receive and save the file
server.on("/file-upload", HTTP_GET, []() {
// if the client requests the upload page
String html = "<form method=\"post\" enctype=\"multipart/form-data\">";
html += "<input type=\"file\" name=\"name\">";
html += "<input class=\"button\" type=\"submit\" value=\"Upload\">";
html += "</form>";
server.send(200, "text/html", html);
});
server.on("/", []() {
server.sendHeader("Location", String("ui.html"), true);
server.send(302, "text/plain", "");
});
server.on("/state", HTTP_GET, []() {
DynamicJsonDocument root(1024);
root["mode"] = acState.operation;
root["fan"] = acState.fan;
root["temp"] = acState.temperature;
root["power"] = acState.powerStatus;
String output;
serializeJson(root, output);
server.send(200, "text/plain", output);
});
server.on("/reset", []() {
server.send(200, "text/html", "reset");
delay(100);
ESP.restart();
});
server.serveStatic("/", SPIFFS, "/", "max-age=86400");
server.onNotFound(handleNotFound);
server.begin();
}
void loop() {
server.handleClient();
}

View File

@@ -0,0 +1,37 @@
[platformio]
src_dir = .
[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU
[common]
lib_deps_builtin =
lib_deps_external =
ArduinoJson@>=6.0
[common_esp8266]
lib_deps_external =
${common.lib_deps_builtin}
${common.lib_deps_external}
WifiManager@>=0.14
[common_esp32]
lib_deps_external =
${common.lib_deps_builtin}
${common.lib_deps_external}
https://github.com/tzapu/WiFiManager.git#development
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
lib_deps = ${common_esp8266.lib_deps_external}
[env:esp32dev]
platform = espressif32
board = esp32dev
lib_deps = ${common_esp32.lib_deps_external}

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="250"
height="500"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient4457">
<stop
id="stop4459"
style="stop-color:#0000ff;stop-opacity:1"
offset="0" />
</linearGradient>
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-552.36218)"
id="layer1">
<rect
width="236.64082"
height="86.640839"
rx="15.946075"
ry="15.666504"
x="6.6795802"
y="959.03809"
id="rect2995"
style="opacity:0.87999998;fill:#46b8da;fill-opacity:0;stroke:#000000;stroke-width:13.35916042;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:35.90000153;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="250"
height="500"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient4457">
<stop
id="stop4459"
style="stop-color:#0000ff;stop-opacity:1"
offset="0" />
</linearGradient>
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-552.36218)"
id="layer1">
<rect
width="236.64082"
height="86.640839"
rx="15.946075"
ry="15.666504"
x="6.6795802"
y="959.03809"
id="rect2995"
style="opacity:0.87999998;fill:#46b8da;fill-opacity:1;stroke:#000000;stroke-width:13.35916042;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:35.90000153;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="250"
height="500"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient4457">
<stop
id="stop4459"
style="stop-color:#0000ff;stop-opacity:1"
offset="0" />
</linearGradient>
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-552.36218)"
id="layer1">
<rect
width="230.92926"
height="180.92929"
rx="22.392242"
ry="22.274536"
x="9.5353565"
y="861.89758"
id="rect2995"
style="opacity:0.87999998;fill:#46b8da;fill-opacity:0;stroke:#000000;stroke-width:19.07071304;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:35.90000153;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="250"
height="500"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient4457">
<stop
id="stop4459"
style="stop-color:#0000ff;stop-opacity:1"
offset="0" />
</linearGradient>
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-552.36218)"
id="layer1">
<rect
width="230.92926"
height="180.92929"
rx="22.392242"
ry="22.274536"
x="9.5353565"
y="861.89758"
id="rect2995"
style="opacity:0.87999998;fill:#46b8da;fill-opacity:1;stroke:#000000;stroke-width:19.07071304;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:35.90000153;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="250"
height="500"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient4457">
<stop
id="stop4459"
style="stop-color:#0000ff;stop-opacity:1"
offset="0" />
</linearGradient>
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-552.36218)"
id="layer1">
<rect
width="226.6387"
height="276.63873"
rx="36.69751"
ry="40.173462"
x="11.680637"
y="764.04285"
id="rect2995"
style="opacity:0.87999998;fill:#46b8da;fill-opacity:0;stroke:#000000;stroke-width:23.36127472;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:35.90000153;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="250"
height="500"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient4457">
<stop
id="stop4459"
style="stop-color:#0000ff;stop-opacity:1"
offset="0" />
</linearGradient>
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-552.36218)"
id="layer1">
<rect
width="226.6387"
height="276.63873"
rx="36.69751"
ry="40.173462"
x="11.680637"
y="764.04285"
id="rect2995"
style="opacity:0.87999998;fill:#46b8da;fill-opacity:1;stroke:#000000;stroke-width:23.36127472;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:35.90000153;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="250"
height="500"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient4457">
<stop
id="stop4459"
style="stop-color:#0000ff;stop-opacity:1"
offset="0" />
</linearGradient>
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-552.36218)"
id="layer1">
<rect
width="223.08398"
height="373.08401"
rx="40.059196"
ry="46.087463"
x="13.458"
y="665.82019"
id="rect2995"
style="opacity:0.87999998;fill:#46b8da;fill-opacity:0;stroke:#000000;stroke-width:26.91600037;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:35.90000153;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="250"
height="500"
id="svg2">
<defs
id="defs4">
<linearGradient
id="linearGradient4457">
<stop
id="stop4459"
style="stop-color:#0000ff;stop-opacity:1"
offset="0" />
</linearGradient>
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(0,-552.36218)"
id="layer1">
<rect
width="223.08398"
height="373.08401"
rx="40.059196"
ry="46.087463"
x="13.458"
y="665.82019"
id="rect2995"
style="opacity:0.87999998;fill:#46b8da;fill-opacity:1;stroke:#000000;stroke-width:26.91600037;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:35.90000153;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,109 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Home Temperature</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel='shortcut icon' type='image/x-icon' href='favicon.ico' />
<style type="text/css">
body { padding-top: 70px; }
</style>
<!-- Font Awsome -->
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<!--page content-->
<body>
<div class='container'>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-brand">
<p>AC Control</p>
</div>
<p class="navbar-text navbar-right sr-only" id="spinner"><i class="fa fa-circle-o-notch fa-spin fa-lg"></i></p>
</div>
</nav>
<div class="alert alert-danger sr-only" id="alert">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<p></p>
</div>
<div class="container-fluid">
<div class="row">
<!-- ON/OFF -->
<div class="col-sm-offset-10 col-sm-2 pull-right">
<a id="power-btn" class="btn btn-default" onclick='power_onclick();'><i class="fa fa-power-off" style="font-size:1.6em;color:black;"></i><b style="font-size:1.5em;" id="power"> OFF</b></a>
</div>
</div>
<br>
<div class="row">
<div class="col-md-4 col-sm-6">
<!-- Mode -->
<h4>Mode</h4>
<div class="btn-group">
<a class="btn btn-default mode-btn" id="mode_cooling" onclick='mode_onclick(1);'><i class="fa fa-asterisk fa-2x"></i></a>
<a class="btn btn-default mode-btn" id="mode_dehum" onclick='mode_onclick(2);'><i class="fa fa-tint fa-2x"></i></a>
<a class="btn btn-default mode-btn" id="mode_heating" onclick='mode_onclick(3);'><i class="fa fa-sun-o fa-2x"></i></a>
<a class="btn btn-default mode-btn" id="mode_fan" onclick='mode_onclick(4);'><i class="fa fa-retweet fa-2x"></i></a>
<a class="btn btn-default mode-btn" id="mode_auto" onclick='mode_onclick(0);'><i class="fa fa-font fa-2x"></i></a>
</div>
</div>
<div class="col-md-4 col-sm-6">
<!-- Fan -->
<h4>Fan</h4>
<div class="btn-group">
<a class="btn btn-default fan-btn" id="fan_auto" onclick='fan_onclick("0");'><i class="fa fa-font fa-2x"></i></a>
<a class="btn btn-default" onclick='fan_onclick(1);'><img src="level_1_off.svg" height="29px" id="fan_lvl_1"></a>
<a class="btn btn-default" onclick='fan_onclick(2);'><img src="level_2_off.svg" height="29px" id="fan_lvl_2"></a>
<a class="btn btn-default" onclick='fan_onclick(3);'><img src="level_3_off.svg" height="29px" id="fan_lvl_3"></a>
</div>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-md-4 col-sm-6" id="target_temp_col">
<!--Target temperature-->
<h4>Target temperature</h4>
<div class="btn-group" >
<a class="btn btn-default" style="font-size:2.2em;padding-top:12px;padding-bottom:12px;"><b id="target_temp"> ~ C</b></a>
</div>
<div class="btn-group-vertical">
<a class="btn btn-default wing-btn" id="target_temp_up" onclick='temp_onclick(1);' style="font-size:1.7em;padding-top:0px;padding-bottom:0px;"><i class="fa fa-chevron-up"></i></a>
<a class="btn btn-default wing-btn" id="target_temp_down" onclick='temp_onclick(-1);' style="font-size:1.7em;padding-top:0px;padding-bottom:0px;"><i class="fa fa-chevron-down"></i></a>
</div>
</div>
</div>
</div>
</div>
<br>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="ui.js"></script>
</body>
</html>

View File

@@ -0,0 +1,132 @@
var state = {}
function updateStatus() {
$.ajax({
type: 'GET',
url: "state",
dataType: "json",
data: [{
name: "light",
value: "1"
}, ],
success: function(data) {
if (!data) {
return;
}
state = data;
if (state["power"] === true) {
$("#power").text(" ON");
$("#power-btn").addClass("btn-info");
$("#power-btn").removeClass("btn-default");
} else {
$("#power").text(" OFF");
$("#power-btn").addClass("btn-default");
$("#power-btn").removeClass("btn-info");
}
$("#target_temp").text(state["temp"] + " C");
setModeColor(state["mode"]);
setFanColor(state["fan"]);
},
error: function() {
console.log('error getting state');
},
timeout: 1000
});
}
updateStatus();
function postData(t) {
var e = new XMLHttpRequest;
e.timeout = 2000;
e.open("PUT", "state", !0);
e.setRequestHeader("Content-Type", "application/json");
console.log(JSON.stringify(t)), e.send(JSON.stringify(t));
}
function mode_onclick(mode) {
state["mode"] = mode;
setModeColor(mode);
postData(state);
}
function setModeColor(mode) {
$(".mode-btn").addClass("btn-default");
$(".mode-btn").removeClass("btn-info");
if (mode === 0) {
$("#mode_auto").removeClass("btn-default");
$("#mode_auto").addClass("btn-info");
setFanColor(0);
state["fan"] = 0;
} else if (mode === 1) {
$("#mode_cooling").removeClass("btn-default");
$("#mode_cooling").addClass("btn-info");
} else if (mode === 2) {
$("#mode_dehum").removeClass("btn-default");
$("#mode_dehum").addClass("btn-info");
} else if (mode === 3) {
$("#mode_heating").removeClass("btn-default");
$("#mode_heating").addClass("btn-info");
} else if (mode === 4) {
$("#mode_fan").removeClass("btn-default");
$("#mode_fan").addClass("btn-info");
}
}
function setFanColor(fan) {
if (fan == 0) {
$("#fan_auto").removeClass("btn-default");
$("#fan_auto").addClass("btn-info");
} else {
$("#fan_auto").removeClass("btn-info");
$("#fan_auto").addClass("btn-default");
}
for (var i = 1; i <= 3; ++i) {
if (i <= fan) {
$("#fan_lvl_" + i).attr("src", "level_" + i + "_on.svg");
} else {
$("#fan_lvl_" + i).attr("src", "level_" + i + "_off.svg");
}
}
}
function fan_onclick(fan) {
if (state["mode"] !== 0) {
state["fan"] = fan;
setFanColor(fan);
postData(state);
}
}
function power_onclick(power) {
if (state["power"]) {
state["power"] = false;
$("#power").text(" OFF");
$("#power-btn").removeClass("btn-info");
$("#power-btn").addClass("btn-default");
} else {
state["power"] = true;
$("#power").text(" ON");
$("#power-btn").addClass("btn-info");
$("#power-btn").removeClass("btn-default");
}
postData(state);
}
function temp_onclick(temp) {
state["temp"] += temp;
if (state["temp"] < 17) {
state["temp"] = 17;
}
if (state["temp"] > 30) {
state["temp"] = 30;
}
$("#target_temp").text(state["temp"] + " C");
postData(state);
}