Im using nodeMCU and connected to 2 buttons and 2-channel relay module to control 2 loads for home automation projects. When I compile the code the Arduino IDE displays "#error “Old version of Blynk library is in use. Please replace it with the new one.”
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define USE_NODE_MCU_BOARD
// define the GPIO connected with Relays and switches
#define RelayPin1 14
#define RelayPin2 12
#define SwitchPin1 16
#define SwitchPin2 5
#define wifiLed 2
#define VPIN_BUTTON_1 V1
#define VPIN_BUTTON_2 V2
// Relay State
bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay 1
bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay 2
#include "BlynkEdgent.h"
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(VPIN_BUTTON_1);
Blynk.syncVirtual(VPIN_BUTTON_2);
}
// When App button is pushed - switch the state
BLYNK_WRITE(VPIN_BUTTON_1) {
toggleState_1 = param.asInt();
if(toggleState_1 == 1){
digitalWrite(RelayPin1, LOW);
}
else {
digitalWrite(RelayPin1, HIGH);
}
}
BLYNK_WRITE(VPIN_BUTTON_2) {
toggleState_2 = param.asInt();
if(toggleState_2 == 1){
digitalWrite(RelayPin2, LOW);
}
else {
digitalWrite(RelayPin2, HIGH);
}
}
void setup()
{
Serial.begin(115200);
delay(100);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(wifiLed, OUTPUT);
pinMode(SwitchPin1, INPUT_PULLUP);
pinMode(SwitchPin2, INPUT_PULLUP);
//During Starting all Relays should TURN OFF
digitalWrite(RelayPin1, HIGH);
digitalWrite(RelayPin2, HIGH);
digitalWrite(wifiLed, HIGH);
BlynkEdgent.begin();
Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
}
void loop() {
BlynkEdgent.run();
manual_control(); //Manual Switch Control
}
extern "C" {
#include "user_interface.h"
void app_loop();
void restartMCU();
}
#include "Settings.h"
#include <BlynkSimpleEsp8266_SSL.h>
#ifndef BLYNK_NEW_LIBRARY
#error "Old version of Blynk library is in use. Please replace it with the new one."
#endif
#if !defined(BLYNK_TEMPLATE_ID) || !defined(BLYNK_DEVICE_NAME)
#error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME"
#endif
BlynkTimer edgentTimer;
#include "BlynkState.h"
#include "ConfigStore.h"
#include "ResetButton.h"
#include "ConfigMode.h"
#include "Indicator.h"
#include "OTA.h"
#include "Console.h"
inline
void BlynkState::set(State m) {
if (state != m && m < MODE_MAX_VALUE) {
DEBUG_PRINT(String(StateStr[state]) + " => " + StateStr[m]);
state = m;
// You can put your state handling here,
// i.e. implement custom indication
}
}
void printDeviceBanner()
{
Blynk.printBanner();
DEBUG_PRINT("--------------------------");
DEBUG_PRINT(String("Product: ") + BLYNK_DEVICE_NAME);
DEBUG_PRINT(String("Firmware: ") + BLYNK_FIRMWARE_VERSION " (build " __DATE__ " " __TIME__ ")");
if (configStore.getFlag(CONFIG_FLAG_VALID)) {
DEBUG_PRINT(String("Token: ") +
String(configStore.cloudToken).substring(0,4) +
" - •••• - •••• - ••••");
}
DEBUG_PRINT(String("Device: ") + BLYNK_INFO_DEVICE + " @ " + ESP.getCpuFreqMHz() + "MHz");
DEBUG_PRINT(String("MAC: ") + WiFi.macAddress());
DEBUG_PRINT(String("Flash: ") + ESP.getFlashChipRealSize() / 1024 + "K");
String coreVer = ESP.getCoreVersion();
coreVer.replace("_", ".");
DEBUG_PRINT(String("ESP core: ") + coreVer);
DEBUG_PRINT(String("ESP SDK: ") + ESP.getSdkVersion());
DEBUG_PRINT(String("Boot Ver: ") + ESP.getBootVersion());
DEBUG_PRINT(String("Boot Mode:") + ESP.getBootMode());
DEBUG_PRINT(String("FW info: ") + ESP.getSketchSize() + "/" + ESP.getFreeSketchSpace() + ", MD5:" + ESP.getSketchMD5());
DEBUG_PRINT(String("Free mem: ") + ESP.getFreeHeap());
DEBUG_PRINT("--------------------------");
}
void runBlynkWithChecks() {
Blynk.run();
if (BlynkState::get() == MODE_RUNNING) {
if (!Blynk.connected()) {
if (WiFi.status() == WL_CONNECTED) {
BlynkState::set(MODE_CONNECTING_CLOUD);
} else {
BlynkState::set(MODE_CONNECTING_NET);
}
}
}
}
class Edgent {
public:
void begin()
{
indicator_init();
button_init();
config_init();
printDeviceBanner();
console_init();
if (configStore.getFlag(CONFIG_FLAG_VALID)) {
BlynkState::set(MODE_CONNECTING_NET);
} else if (config_load_blnkopt()) {
DEBUG_PRINT("Firmware is preprovisioned");
BlynkState::set(MODE_CONNECTING_NET);
} else {
BlynkState::set(MODE_WAIT_CONFIG);
}
}
void run() {
app_loop();
switch (BlynkState::get()) {
case MODE_WAIT_CONFIG:
case MODE_CONFIGURING: enterConfigMode(); break;
case MODE_CONNECTING_NET: enterConnectNet(); break;
case MODE_CONNECTING_CLOUD: enterConnectCloud(); break;
case MODE_RUNNING: runBlynkWithChecks(); break;
case MODE_OTA_UPGRADE: enterOTA(); break;
case MODE_SWITCH_TO_STA: enterSwitchToSTA(); break;
case MODE_RESET_CONFIG: enterResetConfig(); break;
default: enterError(); break;
}
}
} BlynkEdgent;
void app_loop() {
edgentTimer.run();
edgentConsole.run();
}