Hello everybody,
i’m trying to put this sketch on an esp8266 but when i upload the sketch i get this error info on the serial monitor, even though i copied it from my dashboard and pasted it into my sketch i get the error message of:
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.0.1 on NodeMCU
[3437] Using Dynamic IP: 192.168.15.8
[3650] Current time: Tue Sep 6 22:39:34 2022
[3650] Connecting to blynk.cloud:443
[5220] Invalid auth token
What am I doing wrong, could someone help me?
Thanks in advance!
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "xxxx"
#define BLYNK_DEVICE_NAME "DimerControl"
#define BLYNK_AUTH_TOKEN "xxx"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
//#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
#include "BlynkEdgent.h"
#include <AceButton.h>
using namespace ace_button;
// define the GPIO connected with Relays and switches
#define RelayPin1 5 //D1
#define RelayPin2 4 //D2
#define RelayPin3 13 //D7
#define RelayPin4 12 //D6
#define SwitchPin1 10 //SD3
#define SwitchPin2 D3 //D3
#define SwitchPin3 14 //D5
#define SwitchPin4 3 //RX
#define wifiLed 16 //D0
//Change the virtual pins according the rooms
#define VPIN_BUTTON_1 V1
#define VPIN_BUTTON_2 V2
#define VPIN_BUTTON_3 V3
#define VPIN_BUTTON_4 V4
int toggleState_1 = 0; //Define integer to remember the toggle state for relay 1
int toggleState_2 = 0; //Define integer to remember the toggle state for relay 2
int toggleState_3 = 0; //Define integer to remember the toggle state for relay 3
int toggleState_4 = 0; //Define integer to remember the toggle state for relay 4
ButtonConfig config1;
AceButton button1(&config1);
ButtonConfig config2;
AceButton button2(&config2);
ButtonConfig config3;
AceButton button3(&config3);
ButtonConfig config4;
AceButton button4(&config4);
void handleEvent1(AceButton*, uint8_t, uint8_t);
void handleEvent2(AceButton*, uint8_t, uint8_t);
void handleEvent3(AceButton*, uint8_t, uint8_t);
void handleEvent4(AceButton*, uint8_t, uint8_t);
void relayOnOff(int relay){
switch(relay){
case 1:
if(toggleState_1 == 0){
digitalWrite(RelayPin1, LOW); // turn on relay 1
toggleState_1 = 1;
Serial.println("Device1 ON");
}
else{
digitalWrite(RelayPin1, HIGH); // turn off relay 1
toggleState_1 = 0;
Serial.println("Device1 OFF");
}
delay(100);
break;
case 2:
if(toggleState_2 == 0){
digitalWrite(RelayPin2, LOW); // turn on relay 2
toggleState_2 = 1;
Serial.println("Device2 ON");
}
else{
digitalWrite(RelayPin2, HIGH); // turn off relay 2
toggleState_2 = 0;
Serial.println("Device2 OFF");
}
delay(100);
break;
case 3:
if(toggleState_3 == 0){
digitalWrite(RelayPin3, LOW); // turn on relay 3
toggleState_3 = 1;
Serial.println("Device3 ON");
}
else{
digitalWrite(RelayPin3, HIGH); // turn off relay 3
toggleState_3 = 0;
Serial.println("Device3 OFF");
}
delay(100);
break;
case 4:
if(toggleState_4 == 0){
digitalWrite(RelayPin4, LOW); // turn on relay 4
toggleState_4 = 1;
Serial.println("Device4 ON");
}
else{
digitalWrite(RelayPin4, HIGH); // turn off relay 4
toggleState_4 = 0;
Serial.println("Device4 OFF");
}
delay(100);
break;
default : break;
}
}
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(VPIN_BUTTON_1);
Blynk.syncVirtual(VPIN_BUTTON_2);
Blynk.syncVirtual(VPIN_BUTTON_3);
Blynk.syncVirtual(VPIN_BUTTON_4);
}
// 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);
}
}
BLYNK_WRITE(VPIN_BUTTON_3) {
toggleState_3 = param.asInt();
if(toggleState_3 == 1){
digitalWrite(RelayPin3, LOW);
}
else {
digitalWrite(RelayPin3, HIGH);
}
}
BLYNK_WRITE(VPIN_BUTTON_4) {
toggleState_4 = param.asInt();
if(toggleState_4 == 1){
digitalWrite(RelayPin4, LOW);
}
else {
digitalWrite(RelayPin4, HIGH);
}
}
void setup()
{
Serial.begin(115200);
delay(100);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
pinMode(wifiLed, OUTPUT);
pinMode(SwitchPin1, INPUT_PULLUP);
pinMode(SwitchPin2, INPUT_PULLUP);
pinMode(SwitchPin3, INPUT_PULLUP);
pinMode(SwitchPin4, INPUT_PULLUP);
//During Starting all Relays should TURN OFF
digitalWrite(RelayPin1, HIGH);
digitalWrite(RelayPin2, HIGH);
digitalWrite(RelayPin3, HIGH);
digitalWrite(RelayPin4, HIGH);
digitalWrite(wifiLed, HIGH);
config1.setEventHandler(button1Handler);
config2.setEventHandler(button2Handler);
config3.setEventHandler(button3Handler);
config4.setEventHandler(button4Handler);
button1.init(SwitchPin1);
button2.init(SwitchPin2);
button3.init(SwitchPin3);
button4.init(SwitchPin4);
BlynkEdgent.begin();
Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
//timer.setInterval(3000L, checkBlynkStatus); // check if Blynk server is connected every 3 seconds
}
void loop() {
BlynkEdgent.run();
//Manual Switch Control
button1.check();
button2.check();
button3.check();
button4.check();
}
void button1Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT1");
relayOnOff(1);
Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1); // Update Button Widget
}
void button2Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT2");
relayOnOff(2);
Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2); // Update Button Widget
}
void button3Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT3");
relayOnOff(3);
Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3); // Update Button Widget
}
void button4Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT4");
relayOnOff(4);
Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4); // Update Button Widget
}