Need help troubleshooting blynk notifications

I am attempting to display a notification when the touchSensor = LOW in line 200. When the touch sensor goes low line 201 serial prints what I want so I know the sensor is working. Currently when I test the system no notifications show up when the sensor goes to LOW. I am uploading this code to an ESP32.


#define BLYNK_USE_DIRECT_CONNECT

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "YourTemplateID"

//NOW ADDING THE NEOPIXELS
#include <Adafruit_NeoPixel.h>
#define PIN            12
#define numberOfNeopixels      1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numberOfNeopixels, PIN, NEO_GRB + NEO_KHZ800);


#include <BlynkSimpleEsp32_BLE.h>
#include <BLEDevice.h>
#include <BLEServer.h>


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "k8t7775-TEekudSjR4MBou34JI0SwCH0";
/*int LED = 2;
int data;
int r,g,b;*/
int Brightness = 1000; // variable to change brightness
int ColourNumber; 
int red;   //
int green; // variables for custom colour
int blue;  //
BlynkTimer timer;
char devicename1[] = "Bracelet01";
int touchSensor;
int range = 0;
int alertMode;
int myInterval = 1000;
const int TOUCH_SENSOR_PIN = 15; // Arduino pin connected to touch sensor's pin
const int BUZZER_PIN = 13; //Buzzer's pin
const int motorPin = 14;
int freq = 2000;
int resolution = 8;
int channel = 0;
int colorR;
int check = 1;

void setup()

{
  // Debug console
  Serial.begin(9600);

  Serial.println("Waiting for connections...");

  Blynk.setDeviceName(devicename1);
  
  Blynk.begin(auth);

  timer.setInterval(1000L, sendValue);
  //timer.setInterval(5000L, alertM);
  //timer.setInterval(600L, blinkColor);
  timer.setInterval(1000L, emergencyAlert);

  //pinMode(LED, OUTPUT);
  //pixels.begin();
  strip.begin(); //start neopixels
  strip.show(); //set all to 'off'
  ledcSetup(channel, freq, resolution);
  ledcAttachPin(13, channel);//Setting my esp gpio and pwm 
  pinMode(TOUCH_SENSOR_PIN, INPUT);//Setting arduino pin to input mode
  pinMode(motorPin, OUTPUT);
}

void loop()
{
  Blynk.run();
  timer.run();
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

//ADDDING NEW CODE FOR COLOR PICKIING

BLYNK_WRITE(V0) //read menu value
{
   colorR = param.asInt();
   switch (colorR) {
    case 1: {
        ColourNumber = 1;
        colorWipe(strip.Color(Brightness, 0, 0), 50); // Green
        Serial.println("1");
        break;
      }
    case 2: {
        ColourNumber = 2;
        colorWipe(strip.Color(0, 0, Brightness), 50); // Blue
        Serial.println("2");
        break;
      }
    case 3: {
        ColourNumber = 3;
        colorWipe(strip.Color(Brightness, Brightness, 0), 50); // Yellow
        Serial.println("3");
        break;
      }
    case 4: {
        ColourNumber = 4;
        colorWipe(strip.Color(143, 54, 173), 50); // Purple
        Serial.println("4");
        break;
      }
    case 5: {
        ColourNumber = 5;
        colorWipe(strip.Color(0, Brightness, Brightness), 50); // Turquiose
        Serial.println("5");
        break;
      }
    case 6: {
        ColourNumber = 6;
        colorWipe(strip.Color(Brightness,118,5), 50); // Lime Green
        Serial.println("6");
        break;
      }
    case 7: {
        ColourNumber = 7;
        colorWipe(strip.Color(0, 0, 0), 50); // Off
        Serial.println("7");
        break;
      }
   }
}
void returnColor()
{
  switch (colorR) {
    case 1: {
        ColourNumber = 1;
        colorWipe(strip.Color(Brightness, 0, 0), 50); // Green
        Serial.println("1");
        break;
      }
    case 2: {
        ColourNumber = 2;
        colorWipe(strip.Color(0, 0, Brightness), 50); // Blue
        Serial.println("2");
        break;
      }
    case 3: {
        ColourNumber = 3;
        colorWipe(strip.Color(Brightness, Brightness, 0), 50); // Yellow
        Serial.println("3");
        break;
      }
    case 4: {
        ColourNumber = 4;
        colorWipe(strip.Color(143, 54, 173), 50); // Purple
        Serial.println("4");
        break;
      }
    case 5: {
        ColourNumber = 5;
        colorWipe(strip.Color(0, Brightness, Brightness), 50); // Turquiose
        Serial.println("5");
        break;
      }
    case 6: {
        ColourNumber = 6;
        colorWipe(strip.Color(Brightness,118,5), 50); // Lime Green
        Serial.println("6");
        break;
      }
    case 7: {
        ColourNumber = 7;
        colorWipe(strip.Color(0, 0, 0), 50); // Off
        Serial.println("7");
        break;
      }
  }
}

void sendValue()
{
  
//  Prints Bracelet ID to V5 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  Blynk.virtualWrite(V5, devicename1);
  
// Prints touch sensor Connection Status to V1 /////////////////////////////////////////////////////////////////////////////////////////////
  
  int touchState = digitalRead(TOUCH_SENSOR_PIN); // read new state
  if (touchState == LOW) {
    Blynk.notify("Bracelet has been removed");
    Serial.println("The sensor is being untouched");
    touchSensor = 0;
    colorWipe(strip.Color(0, Brightness, 0), 50); //Red
    delay(100);
    colorWipe(strip.Color(0, 0, 0), 50); 
    delay(100);
    Blynk.virtualWrite(V1, "Disconnected");
    digitalWrite(BUZZER_PIN,HIGH);//Turn off Piezo Buzzer
    ledcWriteTone(channel, 2000);
    ledcWrite(channel, 250);//Setting up dutyCycle
    delay(1000);
    colorWipe(strip.Color(0, Brightness, 0), 50); //Red blink
    delay(100);
    colorWipe(strip.Color(0, 0, 0), 50); 
    delay(100);
    ledcWriteTone(channel, 2005);//Setting up frequency
    delay(1000);
    colorWipe(strip.Color(0, Brightness, 0), 50); //Red
    delay(100);
    colorWipe(strip.Color(0, 0, 0), 50); 
    delay(100);
    //Start Vibrator motor
    digitalWrite(motorPin, HIGH);
    delay(1000);
    digitalWrite(motorPin, LOW);
    delay(1000);
    colorWipe(strip.Color(0, Brightness, 0), 50); //Red
    delay(500);
    colorWipe(strip.Color(0, 0, 0), 50); 
    delay(500);
  }
  else
    if(touchState == HIGH) {
      Serial.println("The sensor is touched");
      touchSensor = 1;
      Blynk.virtualWrite(V1, "Connected");
      digitalWrite(BUZZER_PIN, LOW);//Turn on Piezo Buzzer
      digitalWrite(motorPin, LOW);
      delay(1000);
      ledcWriteTone(channel, 0);
      ledcWrite(channel, 0);
      returnColor();
  }
    if (touchSensor == 1){
      Blynk.virtualWrite(V1, "Connected");
  }
    else if (touchSensor = 0){
      Blynk.virtualWrite(V1, "Disconnected");
  }

// Prints Range Detector to V2 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  if (range == 1){
    Blynk.virtualWrite(V2, "In Range");
  }
  else if (range == 0){
  Blynk.virtualWrite(V2, "Out Of Range");
  }
  
  delay(100);
}


BLYNK_WRITE(V3){
    alertMode = param.asInt(); 
    if(alertMode == 1){
      Serial.println(alertMode);
    }
    else if(alertMode == 0){
      Serial.println(alertMode);
    }
  }
void emergencyAlert(){
    if(alertMode == 1){
      digitalWrite(BUZZER_PIN,HIGH);//Turn off Piezo Buzzer
      Blynk.notify("Alert Mode On");
      colorWipe(strip.Color(0, Brightness, 0), 50); //Red blink
      delay(300);
      colorWipe(strip.Color(0, 0, 0), 50); 
      delay(300);
      ledcWriteTone(channel, 2000);
      ledcWrite(channel, 250);//Setting up dutyCycle
      delay(1000);
      colorWipe(strip.Color(0, Brightness, 0), 50); //Red blink
      delay(300);
      colorWipe(strip.Color(0, 0, 0), 50); 
      delay(300);
      ledcWriteTone(channel, 2005);//Setting up frequency
      delay(1000);
      colorWipe(strip.Color(0, Brightness, 0), 50); //Red blink
      delay(300);
      colorWipe(strip.Color(0, 0, 0), 50); 
      delay(300);
      //Start Vibrator motor
      digitalWrite(motorPin, HIGH);
      delay(1000);
      digitalWrite(motorPin, LOW);
      delay(1000);
      colorWipe(strip.Color(0, Brightness, 0), 50); //Red blink
      delay(300);
      colorWipe(strip.Color(0, 0, 0), 50); 
      delay(300);
    }
    else if(alertMode == 0){
      Serial.println(alertMode);
      digitalWrite(BUZZER_PIN, LOW);//Turn on Piezo Buzzer
      digitalWrite(motorPin, LOW);
      delay(1000);
      ledcWriteTone(channel, 0);
      ledcWrite(channel, 0);
      returnColor();
    }
}
/*void blinkColor(){
  if (alertMode == 1){
       colorWipe(strip.Color(0, Brightness, 0), 50); //Red blink
       delay(300);
       colorWipe(strip.Color(0, 0, 0), 50); 
       delay(300);
       colorWipe(strip.Color(0, Brightness, 0), 50); //Red blink
       delay(300);
       colorWipe(strip.Color(0, 0, 0), 50); 
       delay(300);
       colorWipe(strip.Color(0, Brightness, 0), 50); //Red blink
       delay(300);
       colorWipe(strip.Color(0, 0, 0), 50); 
       delay(300);
     
  }
}*/
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}


Are you using blynk legacy or blynk iot ?

I am using blynk Legacy

It’s not recommended to use delay with blynk, you should use blynktimer instead. And keep in your mind that there’s a notification limit so you can send 1 notification every 15 seconds I guess

Are you using Library version 0.6.1 ?

Pete.

I have version 1.01 installed currently. Should I go back to version 0.6.1?

Yep with Blynk Legacy you should use 0.6.1.

1 Like

Ok I deleted the Blynk 1.01 library and replaced it with the 0.6.1 library. Now the Blynk.notify lines are all orange which is good as its recognizing the command. However I am still not receiving any notifications. I even tried adding one in the void setup to notify when it has connected and I get nothing. Also turned on notification when disconnected and when I disconnect I still get nothing.

I have seen some people saying to use Blynk.logEvent("") instead. Would that be a good route to take?

That’s when using blynk iot which I highly recommend you to do.

I would like to but I cant seem to find how to connect to a device via bluetooth on the Blynk IOT. Im guessing its not an option yet? My project can only use bluetooth.

May I ask you what are you trying to do exactly ?

I am creating a smart bracelet that can determine how far away the bracelet is from the device with the app on it. It also recognizes when the bracelet has been removed via a touch sensor. It also does some things with a buzzer and an LED. I know bluetooth isn’t great for this but it is a requirement that I cant change. I have the entire app built and functioning except for the notifications. I just cant seem to get any notification to work even on the example code given by Blynk. I do have notification turned on on my phone.

Nice project but the Bluetooth isn’t a good way to measure distance, especially short distances.

Yea I know but this is a group project and that part isn’t my responsibility so I’m not worried about it. That is my group members responsibility to figure out. I am just responsible for the application. Any other tips for why notifications wouldn’t be working at all?

I have gone back to version 0.6.1. and the notifications still don’t work. I cant even get a notification when connected or disconnected. I have notifications turned on as well on my phone. Any ideas as to why they wouldn’t work? Also does Blynk iot have compatibility with bluetooth yet?

I wish you good luck.
Have a nice day.

1 Like

That means nothing, it simply depends what’s in the keywords file for the library.

I don’t think notifications work with BT in Legacy.

Pete.

Ah well that is not good for my project. Thanks for your help. One last question, does the new Blynk iot have bluetooth compatibility? Im guessing it does not.

No it doesn’t, try your luck with MIT app inventor.

1 Like