I need to control my air conditioner, I have the IR codes, but blynk is offline (local server)
My code:
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleEthernet.h>
#include <Ethernet.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <IRremote.h>
/*DHT*/
#define DHTPIN 2
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
/*BLYNK*/
char auth[] = "2e633e295fbxxxxxxxxxxxxx";
/*INTERNET*/
IPAddress server_ip (xxx,xxx,xxx,xxx);
EthernetClient client;
byte arduino_mac[] = { 0xFE, 0xD7, 0xDF, 0xA2, 0xA5, 0xBE };
IPAddress arduino_ip (xxx,xxx,xxx,xxx);
IPAddress dns_ip (xxx,xxx,xxx,xxx);
IPAddress gateway_ip (xxx,xxx,xxx,xxx);
IPAddress subnet_mask(xxx,xxx,xxx,xxx);
/*IR*/
int khz = 38;
IRsend irsend;
unsigned int irON[] = {3000,9800, 400,1650, 350,650, 350,700, 300,700, 350,1600, 400,700, 300,700, 350,650, 350,650, 350,650, 350,700, 350,650, 350,650, 350,700, 300,700, 300,700, 350,1650, 350,650, 350,1700, 350,1700, 300,700, 300,700, 350,650, 350,650, 350,1700, 300,700, 300,1700, 350,1650, 350};
unsigned int irOFF[] = {3000,9700, 400,1700, 350,750, 250,700, 300,750, 300,1750, 250,600, 450,700, 300,700, 300,1750, 250,1700, 350,750, 250,750, 250,750, 300,700, 300,700, 300,650, 400,650, 350,650, 350,650, 350,600, 400,750, 250,1700, 350,700, 300,1700, 350,650, 350,750, 250,750, 250,1700, 350};
unsigned int irTEMPUP[] = {3008, 9812, 424, 1704, 332, 740, 304, 776, 224, 820, 184, 1864, 208, 800, 224, 736, 300, 740, 276, 740, 304, 784, 216, 736, 304, 780, 216, 1784, 272, 612, 432, 656, 364, 656, 364, 1640, 396, 1668, 368, 668, 348, 620, 424, 592, 428, 788, 208, 808, 248, 716, 312, 708, 312, 1820, 184, 820, 204, 812, 248};
unsigned int irTEMPDOWN[] = {3040, 9756, 424, 1608, 456, 584, 436, 584, 432, 584, 436, 1608, 452, 564, 456, 560, 460, 560, 456, 584, 436, 584, 432, 588, 456, 584, 436, 1608, 452, 564, 456, 584, 436, 584, 432, 1608, 428, 584, 460, 1584, 452, 1584, 456, 584, 432, 584, 436, 584, 432, 584, 436, 584, 436, 580, 460, 1584, 456, 1608, 428};
/*CONTROLES*/
BLYNK_WRITE(V1)
{
if (param.asInt()){
irsend.sendRaw(irON, sizeof(irON) / sizeof(irON[0]), khz); // Turn On
delay(40);
}else {
irsend.sendRaw(irOFF, sizeof(irOFF) / sizeof(irOFF[0]), khz); // Turn Off
delay(100);
irsend.sendRaw(irOFF, sizeof(irOFF) / sizeof(irOFF[0]), khz);
delay(100);
}
}
BLYNK_WRITE(V2)
{
if (param.asInt()){
irsend.sendRaw(irTEMPUP, sizeof(irTEMPUP) / sizeof(irTEMPUP[0]), khz); // Up
delay(40);
}
}
BLYNK_WRITE(V3)
{
if (param.asInt()){
irsend.sendRaw(irTEMPDOWN, sizeof(irTEMPDOWN) / sizeof(irTEMPDOWN[0]), khz); // Down
delay(40);
}
}
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
void setup()
{
// Debug console
DebugSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(auth, server_ip, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
}
If I remove this part the code works
BLYNK_WRITE(V2)
{
if (param.asInt()){
irsend.sendRaw(irTEMPUP, sizeof(irTEMPUP) / sizeof(irTEMPUP[0]), khz); // Up
delay(40);
}
}
BLYNK_WRITE(V3)
{
if (param.asInt()){
irsend.sendRaw(irTEMPDOWN, sizeof(irTEMPDOWN) / sizeof(irTEMPDOWN[0]), khz); // Down
delay(40);
}
}
I tried this code but it did not work