BLYNK_WRITE not triggering - stuck

Setup:
Adafruit Feather Huzzah ESP8266
ADS1015
Blynk Lib: 0.6.1
App Ver: IOS 2.26.1(9)

Here is my issue. I’m not new to using blynk or building projects but I’m stuck at this problem. My two BLYNK_WRITE functions will not trigger. When you move the slider or press the button in the app nothing happens. The serial debug info shows nothing. It doesn’t get the command/trigger/whatever you wanna call it. Interesting thing is when I hard reset my board the slider in the app always jumps back to 3.25. I’ve been staring at this code for over a day and at a loss. I’m using the Arduino IDE to upload (tried both OTA and serial) and I have tried reinstalling the Blynk library and refreshing my auth token. No luck. I realize the two while loops add delay to Blynk.run() but have done longer delays in while loops and not had issues.
I even changed the while loops to only 500ms with no change. What am I missing? Thanks


#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>

const byte alertPin = 13;
const byte redPin = 0;
const byte bluePin = 2;
const int i2caddress = 0x48;
volatile byte readDone = 0;

char auth[] = "tokentokentoken";
char ssid[] = "IoT";
char pass[] = "passwrd";

int transducer1Reading = 0;
int transducer2Reading = 0;
int transducer1Max = 0;
int transducer2Max = 0;
float dataRate = 500;
float transducer1Amps = 0.0;
float transducer2Amps = 0.0;

unsigned long timer1 = 0;
unsigned long timer2 = 0;
unsigned long timer3 = 0;

uint16_t config1 = 0x0002 | // Disable comparator and set ALERT/RDY pin to high-impedance (default)
                   0x0000 | // non-latching Comparator
                   0x0000 | // Alert/Rdy active low   (default)
                   0x0000 | // Traditional comparator (default)
                   0x00A0 | // 2400 samples per second
                   0x0000 | // cont mode
                   0x0000 | // +/-6.144V range
                   0x4000 | // Single-ended AIN0
                   0x8000;  // Set 'start single-conversion' bit

uint16_t config2 = 0x0002 | // Disable comparator and set ALERT/RDY pin to high-impedance (default)
                   0x0000 | // non-latching Comparator
                   0x0000 | // Alert/Rdy active low   (default)
                   0x0000 | // Traditional comparator (default)
                   0x00A0 | // 2400 samples per second
                   0x0000 | // cont mode
                   0x0000 | // +/-6.144V range
                   0x5000 | // Single-ended AIN1
                   0x8000;  // Set 'start single-conversion' bit

void setup()
{
  pinMode(alertPin, INPUT);
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  Wire.begin();
  Wire.setClock(400000);

  Blynk.begin(auth, ssid, pass);

  wifi_station_set_hostname("ESP-Whole House Monitor");
  ArduinoOTA.setHostname("ESP-Whole House Monitor");
  ArduinoOTA.begin();

  Wire.beginTransmission(i2caddress);
  byte error = Wire.endTransmission();

  if (error != 0)
  {
    digitalWrite(redPin, HIGH);
  }

  attachInterrupt(digitalPinToInterrupt(alertPin), conversionDone, FALLING);
}

void loop()
{
  Blynk.run();
  ArduinoOTA.handle();

  if (millis() - timer2 > 10000)
  {
    sendRSSI();
    timer2 = millis();
  }

  if (millis() - timer3 > dataRate)
  {
    getCurrent();
    timer3 = millis();
  }
}

/////////////////////////////////////////

void getCurrent()
{
  digitalWrite(bluePin, LOW);
  transducer1Max = 0;
  write_register_ADC(i2caddress, config1);
  delay(5);
  timer1 = millis();

  while (millis() - timer1 < 1000)
  {
    while (readDone)
    {
      delayMicroseconds(1);
    }

    readDone = 0;

    transducer1Reading = (read_ADC(i2caddress, 0x00) >> 4);

    if (transducer1Reading > transducer1Max)
    {
      transducer1Max = transducer1Reading;

      if (transducer1Reading == 0)
      {
        transducer1Max = 0;
      }
    }
  }

  transducer2Max = 0;
  write_register_ADC(i2caddress, config2);
  delay(5);
  timer1 = millis();

  while (millis() - timer1 < 1000)
  {
    while (readDone)
    {
      delayMicroseconds(1);
    }

    readDone = 0;

    transducer2Reading = (read_ADC(i2caddress, 0x00) >> 4);

    if (transducer2Reading > transducer2Max)
    {
      transducer2Max = transducer2Reading;

      if (transducer1Reading == 0)
      {
        transducer1Max = 0;
      }
    }
  }

  transducer1Amps = (((float)transducer1Max / 2048) * 6.144) / .05;
  transducer2Amps = (((float)transducer2Max / 2048) * 6.144) / .05;

  float totalAmps = transducer1Amps + transducer2Amps;

  Blynk.virtualWrite(V0, transducer1Amps);
  Blynk.virtualWrite(V1, transducer1Reading);
  Blynk.virtualWrite(V2, transducer1Max);
  Blynk.virtualWrite(V4, transducer2Amps);
  Blynk.virtualWrite(V5, totalAmps);
  digitalWrite(bluePin, HIGH);
}

/////////////////////////////////////////

ICACHE_RAM_ATTR void conversionDone()
{
  readDone = 1;
}

/////////////////////////////////////////

void write_register_ADC(uint8_t address, uint16_t regis)
{
  Wire.beginTransmission(address);
  Wire.write(0x01);
  Wire.write((uint8_t)(regis >> 8));
  Wire.write((uint8_t)(regis & 0xFF));
  Wire.endTransmission();
}

/////////////////////////////////////////

uint16_t read_ADC(uint8_t address, uint8_t reg1)
{
  Wire.beginTransmission(address);
  Wire.write(reg1);
  Wire.endTransmission();
  Wire.requestFrom(address, (uint8_t)2);
  return ((Wire.read() << 8) | Wire.read());
}

/////////////////////////////////////////

void sendRSSI()
{
  int cumRssi = 0;
  int rssi = 0;

  for (int i = 0; i < 3; i++)
  {
    rssi = wifi_station_get_rssi();
    cumRssi += rssi;
    delay(5);
  }
  rssi = cumRssi / 3;

  Blynk.virtualWrite(V3, rssi);
}

/////////////////////////////////////////

BLYNK_CONNECTED()
{
  Blynk.syncAll();

  for (int i = 0; i < 5; i++)
  {
    digitalWrite(bluePin, HIGH);
    delay(50);
    digitalWrite(bluePin, LOW);
    delay(50);
  }
}

/////////////////////////////////////////

BLYNK_WRITE(V10)
{
  int restartChip = param.asInt();

  if (restartChip == 1)
  {
    ESP.restart();
  }
}

/////////////////////////////////////////

BLYNK_WRITE(V11)
{
  dataRate = param.asFloat();

  dataRate *= 1000;
}

Do you have multiple devices in your app project?
If so, are you 100% sure that the widgets on V10 and V11 are connected to the correct device (the one that uses the Auth code that’s in your sketch?)

What happens if you comment-out both of the if statements in your void loop?
Have you tried defining a serial output and adding some serial.print statements into your BLYNK.WRITE callbacks?

Is there any reason why you’re not using timers to call your RSSI and other functions?

Pete.

Thanks for the reply! To answer your questions, there is only one device in the project.
I commented out both the timer/if statements so only Blynk.run and OTA are called in the loop. That didn’t make a difference. I also commented out the OTA next just to be sure. Same result. I also added print statements to the BLYNK_WRITE functions and they do not print.

There isn’t a reason why I don’t use the timers options. I just like the “millis() - timer” etc…

Let me know if you think of anything else. Thanks

One interesting thing I thought of is that in the app I didn;t create a new project. I deleted the widgets, changed the hardware and name of a old nt used project and repurposed it for this project. Maybe I should try completely creating a new project in the app…

Or re-generate a new auth code.

Now that you have a serial monitor set up, what does it show when you boot the device?

Pete.

I fixed the issue. It must be a bug in the app or something. I had already tried refreshing the auth token and that didn’t work. What I did to fix it is just deleting the project and creating a new one. Now it works perfectly and all I changed was the auth token in the sketch.

The project I had before was using bluetooth as the connection. Well when I repurposed the existing project I changed the connection to WIFI and ESP8266 for hardware type and re added all the widgets. Works great now. Hopefully this can help someone else who has a similar issue. Thanks again for you input and troubleshooting. I appreciate it!

BLYNK_WRITE doesn’t work with Bluetooth, so maybe that was the source of the problem.

Glad it’s fixed, you can sort-out those timers now :grinning:

Pete.