Final result !
Why ?
I have ceiling speakers in the kitchen, which I love !
However, I had to either use the remote, or walk up to the wall unit very time I wanted to change the volume or power on/off the speakers.
This got even more annoying when somebody was cooking in the kitchen and the volume had to be increased , or if someone was on the phone, and it had to be muted.
So, I figured, I have the remote for it, Why not try to build a cheap device that can send the IR signals to the remote, and then integrate it with google home J
How ?
So, here are the high level steps that I followed. I will go into more detail later.
1. Figure out the IR codes for the remote using an ESP8266 and IR receiver
2. Test sending the IR codes from the ESP8266
3. Setup wifi on the ESP8266
4. Do IoT integration for the ESP8266 with google home
Here are the parts that I used for this project :
4. 330 ohm resistors and generic LEDs ( I reused what I had)
5. Case LEDs ( I reused what I had)
6. Multimeter ( I reused what I had)
So, here are the detailed steps
· Figure out the IR codes for the remote using an ESP8266 and IR receiver
o Use the IRrecvDumpV2 example sketch that comes with the IRremoteESP8266 library to capture the IR codes for your remote
o Double check your receiver diode type (as the pinouts may be different). I used the standalone diode, so the pinouts are as follows
o Use the IRsendDemo example sketch that comes with the IRremoteESP8266 library to test sending the IR codes to your device
o You can see the details from my sketch as well.
· Setup wifi on the ESP8266
o You can see the details from my sketch as well.
· Do IoT integration for the ESP8266 with google home
o Setup device and variables on remoteme.org
o Enable google assistant extension on iftt.com and then setup applets with triggers and responses on iftt.com
· Final sketch
#include <Arduino.h>
#include <IRsend.h>
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRutils.h>
#include <RemoteMe.h>
#include <RemoteMeSocketConnector.h>
#include <RemoteMeDirectWebSocketConnector.h>
#include <ESP8266WiFi.h>
#include <Pinger.h>
#include <Ticker.h>
#define WIFI_NAME "YOUR-WIFI-SSID"
#define WIFI_PASSWORD "YOUR-WIFI-PASSW)RD"
#define DEVICE_ID 1
#define DEVICE_NAME "YOUR-ESP8266-DEVICE-NAME"
#define TOKEN "YOUR-API-TOKEN-FROM-REMOTEME.ORG"
RemoteMe& remoteMe = RemoteMe::getInstance(TOKEN, DEVICE_ID);
Ticker periodic_checker;
Pinger pinger;
// ==================== start of TUNEABLE PARAMETERS ====================
// GPIO to use to control the IR LED circuit. Recommended: 4 (D2).
// LED minus pin connected to GPIO 4 = D2
// LED plus pin connected to 3.3 V
const uint16_t kIrLedPin = 4;
//const IPAddress remote_ip(8, 8, 8, 8); // Remote host
// GPIO to use to control the hearbeat green LED circuit. Recommended: 15 (D8).
// LED minus pin connected to GPIO 15 = D8 via 470 ohm resistor
// LED plus pin connected to 3.3 V
// GPIO to use to control the error status red LED circuit. Recommended: 13 (D7).
// LED minus pin connected to GPIO 13 = D7 via 470 ohm resistor
// LED plus pin connected to 3.3 V
const uint16_t HearbeatLedPin = 15;
const uint16_t ErrorLedPin = 13;
// kFrequency is the modulation frequency all UNKNOWN messages will be sent at.
const uint16_t kFrequency = 38; // in KHz. e.g. 38kHz.
// The IR transmitter.
IRsend irsend(kIrLedPin);
// Somewhere to store the captured message.
decode_results results;
// First code is with the uno, second code is with the ESP2866
// OnQ remote
//689FA729 = Power toggle = 1E536C0D
//7B8AD561 = Volume up = 91C28805
//2035FA5E = Volume down = F621F31E
//71603D32 = Mute = D678818A
//EBA6D9DE = next source = 1A6C3CDE
//B980E06F = previous source = B7A32C1B
// REPLACE WITH YOUR IR CODES ....
uint16_t power_toggle_button_array[167] = {5962, 1218, 1218, 1168, 1218, 1168, 618, 574, 620, 572, 620, 1170, 618, 574, 620, 1168, 620, 1170, 1214, 572, 1216, 550, 642, 1168, 620, 570, 620, 8958, 3010, 1166, 1216, 1168, 1216, 1168, 620, 574, 618, 574, 618, 1170, 620, 572, 620, 1170, 618, 1170, 1216, 572, 1218, 572, 620, 1170, 618, 572, 618, 8958, 3010, 1166, 1216, 1168, 1218, 1168, 620, 572, 620, 572, 620, 1170, 618, 572, 620, 1168, 620, 1170, 1216, 572, 1216, 572, 620, 1168, 620, 570, 620, 8958, 3010, 1164, 1218, 1168, 1216, 1168, 620, 572, 620, 572, 620, 1168, 620, 572, 620, 1168, 620, 1170, 1216, 572, 1218, 572, 618, 1168, 620, 570, 620, 8958, 3008, 1166, 1216, 1170, 1218, 1168, 618, 574, 618, 574, 618, 1170, 620, 574, 618, 1170, 620, 1168, 1218, 572, 1218, 572, 620, 1170, 620, 570, 620, 8956, 3012, 1164, 1218, 1168, 1216, 1168, 620, 574, 618, 574, 618, 1170, 618, 574, 620, 1170, 618, 1170, 1216, 572, 1216, 572, 620, 1170, 618, 570, 620}; // UNKNOWN A6E38D8B
uint16_t volume_up_button_array[167] = {5960, 1216, 1218, 1168, 1218, 1168, 620, 572, 620, 572, 620, 1168, 620, 574, 620, 1168, 620, 1168, 1218, 1168, 620, 1168, 620, 1168, 1218, 570, 618, 8958, 3010, 1164, 1218, 1166, 1218, 1168, 620, 574, 620, 570, 622, 1168, 622, 572, 622, 1168, 620, 1168, 1220, 1168, 620, 1168, 620, 1168, 1218, 568, 620, 8958, 3012, 1164, 1218, 1166, 1218, 1168, 620, 570, 620, 572, 622, 1168, 620, 572, 620, 1168, 620, 1168, 1218, 1168, 620, 1170, 618, 1168, 1218, 570, 620, 8956, 3012, 1164, 1218, 1168, 1218, 1168, 620, 570, 622, 572, 620, 1168, 620, 572, 620, 1168, 620, 1170, 1218, 1168, 620, 1168, 620, 1168, 1218, 570, 620, 8956, 3012, 1164, 1218, 1168, 1218, 1166, 620, 572, 620, 572, 620, 1168, 620, 572, 620, 1168, 622, 1168, 1218, 1168, 620, 1168, 622, 1168, 1218, 568, 622, 8954, 3012, 1164, 1218, 1168, 1216, 1168, 620, 572, 620, 572, 620, 1170, 618, 570, 622, 1168, 622, 1168, 1218, 1168, 620, 1168, 620, 1170, 1216, 570, 620}; // UNKNOWN 85D38CB
uint16_t volume_down_button_array[167] = {5984, 1192, 1216, 1168, 1218, 1168, 618, 574, 620, 572, 620, 1170, 618, 574, 618, 1170, 1216, 572, 620, 572, 620, 572, 618, 600, 592, 1194, 594, 8956, 3010, 1166, 1218, 1166, 1218, 1168, 620, 600, 594, 572, 618, 1170, 618, 574, 620, 1168, 1218, 572, 620, 572, 620, 572, 620, 572, 618, 1168, 620, 8958, 3010, 1166, 1216, 1168, 1216, 1168, 620, 572, 620, 572, 620, 1170, 618, 598, 594, 1168, 1218, 572, 618, 574, 620, 572, 620, 572, 620, 1166, 620, 8956, 3012, 1166, 1216, 1168, 1218, 1168, 620, 572, 620, 572, 620, 1168, 620, 572, 620, 1168, 1216, 572, 620, 572, 620, 572, 620, 570, 620, 1166, 620, 8958, 3010, 1164, 1218, 1168, 1218, 1168, 620, 572, 620, 572, 620, 1168, 620, 572, 622, 1168, 1218, 570, 620, 572, 620, 572, 620, 572, 620, 1166, 620, 8956, 3010, 1166, 1216, 1168, 1216, 1168, 620, 572, 620, 572, 620, 1170, 620, 572, 620, 1170, 1216, 572, 618, 574, 620, 574, 618, 574, 618, 1168, 620}; // UNKNOWN 75FFD1AF
uint16_t volume_mute_button_array[111] = {5984, 1192, 1216, 1166, 1220, 1168, 620, 600, 594, 572, 618, 1170, 620, 598, 594, 1170, 618, 1170, 1216, 598, 1190, 1168, 618, 1170, 618, 1194, 592, 8958, 3010, 1166, 1216, 1194, 1192, 1194, 594, 598, 594, 574, 618, 1196, 592, 572, 620, 1170, 620, 1168, 1218, 570, 1272, 1114, 618, 1170, 620, 1166, 620, 8958, 3010, 1166, 1216, 1168, 1218, 1168, 620, 574, 618, 598, 594, 1196, 594, 600, 592, 1170, 618, 1170, 1216, 572, 1216, 1168, 618, 1170, 620, 1168, 618, 8958, 3010, 1192, 1192, 1168, 1216, 1170, 618, 600, 592, 574, 618, 1168, 620, 572, 620, 1194, 594, 1170, 1216, 598, 1190, 1194, 594, 1170, 616, 1168, 620}; // UNKNOWN 5F72B567
// ==================== end of TUNEABLE PARAMETERS ====================
//*************** CODE FOR COMFORTABLE VARIABLE SET *********************
inline void setDECREASE_VOLUME(boolean b) {remoteMe.getVariables()->setBoolean("DECREASE_VOLUME", b); }
inline void setINCREASE_VOLUME(boolean b) {remoteMe.getVariables()->setBoolean("INCREASE_VOLUME", b); }
inline void setTURN_OFF(boolean b) {remoteMe.getVariables()->setBoolean("TURN_OFF", b); }
inline void setTURN_ON(boolean b) {remoteMe.getVariables()->setBoolean("TURN_ON", b); }
inline void setMUTE_VOLUME(boolean b) {remoteMe.getVariables()->setBoolean("MUTE_VOLUME", b); }
void heartbeat_check();
//*************** IMPLEMENT FUNCTIONS BELOW *********************
void onDECREASE_VOLUMEChange(boolean b) {
Serial.printf("onDECREASE_VOLUMEChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(volume_down_button_array, 167, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for volume down");
setDECREASE_VOLUME (false);
}
}
void onINCREASE_VOLUMEChange(boolean b) {
Serial.printf("onINCREASE_VOLUMEChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(volume_up_button_array, 167, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for volume up");
setINCREASE_VOLUME (false);
}
}
void onMUTE_VOLUMEChange(boolean b) {
Serial.printf("onMUTE_VOLUMEChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(volume_mute_button_array, 111, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for volume mute");
setMUTE_VOLUME (false);
}
}
void onTURN_OFFChange(boolean b) {
Serial.printf("onTURN_OFFChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(power_toggle_button_array, 167, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for power toggle");
setTURN_OFF (false);
}
}
void onTURN_ONChange(boolean b) {
Serial.printf("onTURN_ONChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(power_toggle_button_array, 167, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for power toggle");
setTURN_ON (false );
}
}
void setup() {
irsend.begin(); // Start up the IR sender.
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
pinMode(HearbeatLedPin, OUTPUT); // Initialize the hearbeat led pin as an output
pinMode(ErrorLedPin, OUTPUT); // Initialize the error led pin as an output
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
digitalWrite(HearbeatLedPin, HIGH); // Turn the LED off by making the voltage HIGH
digitalWrite(ErrorLedPin, LOW); // Turn the LED on (Note that LOW is the voltage level
Serial.begin(9600);
Serial.print("Serial debug started...");
Serial.println();
// Station mode, where the NodeMCU device joins an existing network,
WiFi.mode(WIFI_STA) ;
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
delay(500);
Serial.print("Waiting for wifi connection...");
Serial.println();
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
digitalWrite(HearbeatLedPin, LOW); // Turn the LED on (Note that LOW is the voltage level
digitalWrite(ErrorLedPin, HIGH); // Turn the LED off by making the voltage HIGH
//Setup the listeners on state changes
remoteMe.getVariables()->observeBoolean("DECREASE_VOLUME" ,onDECREASE_VOLUMEChange);
remoteMe.getVariables()->observeBoolean("INCREASE_VOLUME" ,onINCREASE_VOLUMEChange);
remoteMe.getVariables()->observeBoolean("MUTE_VOLUME" ,onMUTE_VOLUMEChange);
remoteMe.getVariables()->observeBoolean("TURN_OFF" ,onTURN_OFFChange);
remoteMe.getVariables()->observeBoolean("TURN_ON" ,onTURN_ONChange);
remoteMe.setConnector(new RemoteMeSocketConnector());
remoteMe.setDirectConnector(new RemoteMeDirectWebSocketConnector());
remoteMe.sendRegisterDeviceMessage(DEVICE_NAME);
//Initialize Ticker every 10 minutes
periodic_checker.attach(600, heartbeat_check);
}
void loop() {
remoteMe.loop();
//heartbeat_check();
}
void heartbeat_check()
{
// Ping
if(pinger.Ping(IPAddress(8,8,8,8)) == true)
{
Serial.println("Success in pinging 8.8.8.8 !!");
digitalWrite(HearbeatLedPin, LOW); // Turn the LED on (Note that LOW is the voltage level
digitalWrite(ErrorLedPin, HIGH); // Turn the LED off by making the voltage HIGH
} else
{
Serial.println("Error in pinging 8.8.8.8 :(");
digitalWrite(HearbeatLedPin, HIGH); // Turn the LED off by making the voltage HIGH
digitalWrite(ErrorLedPin, LOW); // Turn the LED on (Note that LOW is the voltage level
}
}
#include <IRsend.h>
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRutils.h>
#include <RemoteMe.h>
#include <RemoteMeSocketConnector.h>
#include <RemoteMeDirectWebSocketConnector.h>
#include <ESP8266WiFi.h>
#include <Pinger.h>
#include <Ticker.h>
#define WIFI_NAME "YOUR-WIFI-SSID"
#define WIFI_PASSWORD "YOUR-WIFI-PASSW)RD"
#define DEVICE_ID 1
#define DEVICE_NAME "YOUR-ESP8266-DEVICE-NAME"
#define TOKEN "YOUR-API-TOKEN-FROM-REMOTEME.ORG"
RemoteMe& remoteMe = RemoteMe::getInstance(TOKEN, DEVICE_ID);
Ticker periodic_checker;
Pinger pinger;
// ==================== start of TUNEABLE PARAMETERS ====================
// GPIO to use to control the IR LED circuit. Recommended: 4 (D2).
// LED minus pin connected to GPIO 4 = D2
// LED plus pin connected to 3.3 V
const uint16_t kIrLedPin = 4;
//const IPAddress remote_ip(8, 8, 8, 8); // Remote host
// GPIO to use to control the hearbeat green LED circuit. Recommended: 15 (D8).
// LED minus pin connected to GPIO 15 = D8 via 470 ohm resistor
// LED plus pin connected to 3.3 V
// GPIO to use to control the error status red LED circuit. Recommended: 13 (D7).
// LED minus pin connected to GPIO 13 = D7 via 470 ohm resistor
// LED plus pin connected to 3.3 V
const uint16_t HearbeatLedPin = 15;
const uint16_t ErrorLedPin = 13;
// kFrequency is the modulation frequency all UNKNOWN messages will be sent at.
const uint16_t kFrequency = 38; // in KHz. e.g. 38kHz.
// The IR transmitter.
IRsend irsend(kIrLedPin);
// Somewhere to store the captured message.
decode_results results;
// First code is with the uno, second code is with the ESP2866
// OnQ remote
//689FA729 = Power toggle = 1E536C0D
//7B8AD561 = Volume up = 91C28805
//2035FA5E = Volume down = F621F31E
//71603D32 = Mute = D678818A
//EBA6D9DE = next source = 1A6C3CDE
//B980E06F = previous source = B7A32C1B
// REPLACE WITH YOUR IR CODES ....
uint16_t power_toggle_button_array[167] = {5962, 1218, 1218, 1168, 1218, 1168, 618, 574, 620, 572, 620, 1170, 618, 574, 620, 1168, 620, 1170, 1214, 572, 1216, 550, 642, 1168, 620, 570, 620, 8958, 3010, 1166, 1216, 1168, 1216, 1168, 620, 574, 618, 574, 618, 1170, 620, 572, 620, 1170, 618, 1170, 1216, 572, 1218, 572, 620, 1170, 618, 572, 618, 8958, 3010, 1166, 1216, 1168, 1218, 1168, 620, 572, 620, 572, 620, 1170, 618, 572, 620, 1168, 620, 1170, 1216, 572, 1216, 572, 620, 1168, 620, 570, 620, 8958, 3010, 1164, 1218, 1168, 1216, 1168, 620, 572, 620, 572, 620, 1168, 620, 572, 620, 1168, 620, 1170, 1216, 572, 1218, 572, 618, 1168, 620, 570, 620, 8958, 3008, 1166, 1216, 1170, 1218, 1168, 618, 574, 618, 574, 618, 1170, 620, 574, 618, 1170, 620, 1168, 1218, 572, 1218, 572, 620, 1170, 620, 570, 620, 8956, 3012, 1164, 1218, 1168, 1216, 1168, 620, 574, 618, 574, 618, 1170, 618, 574, 620, 1170, 618, 1170, 1216, 572, 1216, 572, 620, 1170, 618, 570, 620}; // UNKNOWN A6E38D8B
uint16_t volume_up_button_array[167] = {5960, 1216, 1218, 1168, 1218, 1168, 620, 572, 620, 572, 620, 1168, 620, 574, 620, 1168, 620, 1168, 1218, 1168, 620, 1168, 620, 1168, 1218, 570, 618, 8958, 3010, 1164, 1218, 1166, 1218, 1168, 620, 574, 620, 570, 622, 1168, 622, 572, 622, 1168, 620, 1168, 1220, 1168, 620, 1168, 620, 1168, 1218, 568, 620, 8958, 3012, 1164, 1218, 1166, 1218, 1168, 620, 570, 620, 572, 622, 1168, 620, 572, 620, 1168, 620, 1168, 1218, 1168, 620, 1170, 618, 1168, 1218, 570, 620, 8956, 3012, 1164, 1218, 1168, 1218, 1168, 620, 570, 622, 572, 620, 1168, 620, 572, 620, 1168, 620, 1170, 1218, 1168, 620, 1168, 620, 1168, 1218, 570, 620, 8956, 3012, 1164, 1218, 1168, 1218, 1166, 620, 572, 620, 572, 620, 1168, 620, 572, 620, 1168, 622, 1168, 1218, 1168, 620, 1168, 622, 1168, 1218, 568, 622, 8954, 3012, 1164, 1218, 1168, 1216, 1168, 620, 572, 620, 572, 620, 1170, 618, 570, 622, 1168, 622, 1168, 1218, 1168, 620, 1168, 620, 1170, 1216, 570, 620}; // UNKNOWN 85D38CB
uint16_t volume_down_button_array[167] = {5984, 1192, 1216, 1168, 1218, 1168, 618, 574, 620, 572, 620, 1170, 618, 574, 618, 1170, 1216, 572, 620, 572, 620, 572, 618, 600, 592, 1194, 594, 8956, 3010, 1166, 1218, 1166, 1218, 1168, 620, 600, 594, 572, 618, 1170, 618, 574, 620, 1168, 1218, 572, 620, 572, 620, 572, 620, 572, 618, 1168, 620, 8958, 3010, 1166, 1216, 1168, 1216, 1168, 620, 572, 620, 572, 620, 1170, 618, 598, 594, 1168, 1218, 572, 618, 574, 620, 572, 620, 572, 620, 1166, 620, 8956, 3012, 1166, 1216, 1168, 1218, 1168, 620, 572, 620, 572, 620, 1168, 620, 572, 620, 1168, 1216, 572, 620, 572, 620, 572, 620, 570, 620, 1166, 620, 8958, 3010, 1164, 1218, 1168, 1218, 1168, 620, 572, 620, 572, 620, 1168, 620, 572, 622, 1168, 1218, 570, 620, 572, 620, 572, 620, 572, 620, 1166, 620, 8956, 3010, 1166, 1216, 1168, 1216, 1168, 620, 572, 620, 572, 620, 1170, 620, 572, 620, 1170, 1216, 572, 618, 574, 620, 574, 618, 574, 618, 1168, 620}; // UNKNOWN 75FFD1AF
uint16_t volume_mute_button_array[111] = {5984, 1192, 1216, 1166, 1220, 1168, 620, 600, 594, 572, 618, 1170, 620, 598, 594, 1170, 618, 1170, 1216, 598, 1190, 1168, 618, 1170, 618, 1194, 592, 8958, 3010, 1166, 1216, 1194, 1192, 1194, 594, 598, 594, 574, 618, 1196, 592, 572, 620, 1170, 620, 1168, 1218, 570, 1272, 1114, 618, 1170, 620, 1166, 620, 8958, 3010, 1166, 1216, 1168, 1218, 1168, 620, 574, 618, 598, 594, 1196, 594, 600, 592, 1170, 618, 1170, 1216, 572, 1216, 1168, 618, 1170, 620, 1168, 618, 8958, 3010, 1192, 1192, 1168, 1216, 1170, 618, 600, 592, 574, 618, 1168, 620, 572, 620, 1194, 594, 1170, 1216, 598, 1190, 1194, 594, 1170, 616, 1168, 620}; // UNKNOWN 5F72B567
// ==================== end of TUNEABLE PARAMETERS ====================
//*************** CODE FOR COMFORTABLE VARIABLE SET *********************
inline void setDECREASE_VOLUME(boolean b) {remoteMe.getVariables()->setBoolean("DECREASE_VOLUME", b); }
inline void setINCREASE_VOLUME(boolean b) {remoteMe.getVariables()->setBoolean("INCREASE_VOLUME", b); }
inline void setTURN_OFF(boolean b) {remoteMe.getVariables()->setBoolean("TURN_OFF", b); }
inline void setTURN_ON(boolean b) {remoteMe.getVariables()->setBoolean("TURN_ON", b); }
inline void setMUTE_VOLUME(boolean b) {remoteMe.getVariables()->setBoolean("MUTE_VOLUME", b); }
void heartbeat_check();
//*************** IMPLEMENT FUNCTIONS BELOW *********************
void onDECREASE_VOLUMEChange(boolean b) {
Serial.printf("onDECREASE_VOLUMEChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(volume_down_button_array, 167, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for volume down");
setDECREASE_VOLUME (false);
}
}
void onINCREASE_VOLUMEChange(boolean b) {
Serial.printf("onINCREASE_VOLUMEChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(volume_up_button_array, 167, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for volume up");
setINCREASE_VOLUME (false);
}
}
void onMUTE_VOLUMEChange(boolean b) {
Serial.printf("onMUTE_VOLUMEChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(volume_mute_button_array, 111, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for volume mute");
setMUTE_VOLUME (false);
}
}
void onTURN_OFFChange(boolean b) {
Serial.printf("onTURN_OFFChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(power_toggle_button_array, 167, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for power toggle");
setTURN_OFF (false);
}
}
void onTURN_ONChange(boolean b) {
Serial.printf("onTURN_ONChange: b: %d\n",b);
if (b)
{
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
irsend.sendRaw(power_toggle_button_array, 167, kFrequency);
delay(2000);
digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW
Serial.println("Sent IR code for power toggle");
setTURN_ON (false );
}
}
void setup() {
irsend.begin(); // Start up the IR sender.
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
pinMode(HearbeatLedPin, OUTPUT); // Initialize the hearbeat led pin as an output
pinMode(ErrorLedPin, OUTPUT); // Initialize the error led pin as an output
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
digitalWrite(HearbeatLedPin, HIGH); // Turn the LED off by making the voltage HIGH
digitalWrite(ErrorLedPin, LOW); // Turn the LED on (Note that LOW is the voltage level
Serial.begin(9600);
Serial.print("Serial debug started...");
Serial.println();
// Station mode, where the NodeMCU device joins an existing network,
WiFi.mode(WIFI_STA) ;
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
delay(500);
Serial.print("Waiting for wifi connection...");
Serial.println();
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
digitalWrite(HearbeatLedPin, LOW); // Turn the LED on (Note that LOW is the voltage level
digitalWrite(ErrorLedPin, HIGH); // Turn the LED off by making the voltage HIGH
//Setup the listeners on state changes
remoteMe.getVariables()->observeBoolean("DECREASE_VOLUME" ,onDECREASE_VOLUMEChange);
remoteMe.getVariables()->observeBoolean("INCREASE_VOLUME" ,onINCREASE_VOLUMEChange);
remoteMe.getVariables()->observeBoolean("MUTE_VOLUME" ,onMUTE_VOLUMEChange);
remoteMe.getVariables()->observeBoolean("TURN_OFF" ,onTURN_OFFChange);
remoteMe.getVariables()->observeBoolean("TURN_ON" ,onTURN_ONChange);
remoteMe.setConnector(new RemoteMeSocketConnector());
remoteMe.setDirectConnector(new RemoteMeDirectWebSocketConnector());
remoteMe.sendRegisterDeviceMessage(DEVICE_NAME);
//Initialize Ticker every 10 minutes
periodic_checker.attach(600, heartbeat_check);
}
void loop() {
remoteMe.loop();
//heartbeat_check();
}
void heartbeat_check()
{
// Ping
if(pinger.Ping(IPAddress(8,8,8,8)) == true)
{
Serial.println("Success in pinging 8.8.8.8 !!");
digitalWrite(HearbeatLedPin, LOW); // Turn the LED on (Note that LOW is the voltage level
digitalWrite(ErrorLedPin, HIGH); // Turn the LED off by making the voltage HIGH
} else
{
Serial.println("Error in pinging 8.8.8.8 :(");
digitalWrite(HearbeatLedPin, HIGH); // Turn the LED off by making the voltage HIGH
digitalWrite(ErrorLedPin, LOW); // Turn the LED on (Note that LOW is the voltage level
}
}































