BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Sending Multiple Values using Blynk Timer - Updated Code

esp8266

#1

I’m working on Smart Energy Meter which can display real time values of Current, Load, Electricity Bill and Carbon Footprint on an LCD and also display them in real-time on my Blynk App. I have added a feature to send a web request to generate an email with the electricity bill when a button is pressed on the Blynk App.
A few points to be noted:

  1. I am not getting any errors when I am displaying just one value in Real Time on the Blynk App.
  2. I have checked for shorting in my circuit and there aren’t any short circuits.
  3. I have not used the GPIOs 0,2,15.
  4. I have also tested with a button to send a web request and display just one value in Blynk App and it works fine.

Problem : ets Jan 8 2013,rst cause:4, boot mode:(1,6)

When I’m firing a web request by pressing the button while displaying 4 real-time values, I’m getting the above error. Note that when I’m sending just one value, the above error is not occurring.

Source Code:

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#include <BlynkSimpleEsp8266.h> // library for connecting to Blynk
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h> // library for setting up the board to connect to Wifi 
#include <ESP8266HTTPClient.h> // library for making a HTTP web request from the board
#include <NTPtimeESP.h>

int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
double kwh = 0;
double rupees = 0;
double Power = 0;
double Energy = 0;
double cfp = 0;
uint32_t start_time;
byte actualHour = 0;
byte actualMinute = 0;
byte actualsecond = 0;

NTPtime NTPch("in.pool.ntp.org");   // Choose server pool as required
LiquidCrystal_I2C  lcd(0x27, 2, 1, 0, 4, 5, 6, 7); // 0x27 is the I2C bus address for an unmodified module
BlynkTimer timer; // creating an instance for BlynkTimer to keep sending data to our Blynk project whenever the timer is running

char auth[] = "4b56bb551dc743ad8163c3f5e7b8d1f4";
char ssid[] = "iBrain_FF";
char pass[] = "lemons@iB";

strDateTime dateTime;

void myTimerEvent()
{
  start_time = millis();
  Voltage = getVPP();
  VRMS = (Voltage / 2.0) * 0.707; //root 2 is 0.707
  AmpsRMS = ((VRMS * 1000) / mVperAmp) - 0.15;
  Power = AmpsRMS * 220;
  kwh = ((Power * start_time) / (3600000));
  rupees = 3 * kwh;
  cfp = ((kwh) * (0.85) / (24 * 365)) * 100000;

  dateTime = NTPch.getNTPtime(4.5, 1);

  if (dateTime.valid)
  {
    actualHour = dateTime.hour;
    actualMinute = dateTime.minute;
    actualsecond = dateTime.second;
  }

  Blynk.virtualWrite(V1, rupees);
  Blynk.virtualWrite(V2, AmpsRMS);
  Blynk.virtualWrite(V3, Power);
  Blynk.virtualWrite(V4, cfp);

  //Serial.print(AmpsRMS);
  //Serial.println(" Amps RMS");

  if ( Power < 0 )
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("No Power Supply");
  }
  else
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(String(AmpsRMS) + String("A"));
    lcd.setCursor(0, 1);
    lcd.print(String("Rs") + String(rupees));
    lcd.setCursor(8, 0);
    lcd.print(String(Power) + String("W"));
    lcd.setCursor(8, 1);
    lcd.print(String(actualHour) + String(":") + String(actualMinute) + String(":") + String(actualsecond));
  }

}


BLYNK_WRITE(V0)
{
  int p;
  p = param[0].asInt(); // the input which we get from the button in the Blynk Project
  if ( p == 1 )
  {
    String s = "https://maker.ifttt.com/trigger/Get_Electricity_Bill/with/key/n37nidc1OYT5j0cijZVH6H5ZumUpZSUkD9_eLULIjzg?value1=" + String(rupees);
    //we convert "rupees" value to string to concatenate with our URL to make a web request
    if ((WiFi.status() == WL_CONNECTED)) {

      HTTPClient http;//creating instance for HTTP

      Serial.print("[HTTP] begin...\n");
      http.begin(s, "c05d085ee13ee066f379271aca1ffc0924116162"); //in http.begin(A,B), A = URL, B(for https) = Certification Thumbprint of the website you're making a request to
      Serial.print("[HTTP] GET...\n");
      int httpCode = http.GET(); // to get a code which tells us the status of transmission
      if (httpCode > 0) {

        Serial.printf("[HTTP] GET... code: %d\n", httpCode);

        if (httpCode == HTTP_CODE_OK) {
          String payload = http.getString();
          Serial.println(payload);
        }
      } else {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }

      http.end();
    }
    Serial.println("Button Pressed");
    Serial.println(s);
    delay(100);
  }

}

float getVPP()
{
  float result;
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;          // store min value here

  uint32_t start_time1 = millis();
  while ((millis() - start_time1) < 1000) //sample for 1 Sec
  {
    readValue = analogRead(A0);
    // see if you have a new maxValue
    if (readValue > maxValue)
    {
      /*record the maximum sensor value*/
      maxValue = readValue;
    }
    if (readValue < minValue)
    {
      /*record the minimum sensor value*/
      minValue = readValue;
    }
  }

  // Subtract min from max
  result = ((maxValue - minValue) * 5.0) / 1024.0;

  return result;
}

void setup()
{
  Serial.begin(115200);
  lcd.setBacklightPin(3, POSITIVE);
  lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it to LOW instead of HIGH
  lcd.begin(16, 2);
  lcd.clear();
  Serial.println();
  Serial.println("Booted");
  Serial.println("Connecting to Wi-Fi");
  WiFi.mode(WIFI_STA);
  WiFi.begin (ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("WiFi connected");
  Blynk.config(auth);
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{

  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}


Error displayed in Serial Monitor when the button on Blynk App is pressed :-

Soft WDT reset

ctx: cont 
sp: 3fff1100 end: 5ccf061a offset: 01b0

>>>stack>>>
3fff12b0:  00000000 00eda996 40201770 00001388  
3fff12c0:  40201786 00001388 00001388 4020177b  
3fff12d0:  00000045 00000000 3fff318c 4020566e  
.
.
.
.
.
.
.
.
3fff4340:  4c370342 d5df88e6 b1f224af b5ccdfc3  
3fff4ÿ
 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

Kindly clarify.


#2

pls properly format your code according to this forums regulations.

and I noticed:

so you might want to read this:


#3

You might want to take a look at the fully functional pre-built energy monitor software from @Costas, which is built around the Blynk platform:
https://peacefairapp.com/

Pete.


#4

@Ramanadh_Reddy I fixed your post as required for pasting code…

[README] Welcome to Blynk Community!

Blynk - FTFC


#5

Thank you!


#6

ah that helps a lot.

@Ramanadh_Reddy first issue is that you’re code structure is not compatible with blynk. When using blynk your void loop should look (roughly) like this:

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

No more (with an occasional exception for e.g. OTA), no less (unless you’re not using timers).
All the other code should be shifted to one or more functions and those functions should be called by timers. So in your setup you will have multiple lines like this one:

 timer.setInterval(1000L, myTimerEvent);

Start there. Also whats this:

    delay(d);

suppose to do?


#7

oh my god the loop !!!

30-021199


#8

I have moved the block of code apart from the two functions you’ve mentioned from the loop to myTimerEvent() function. Now my loop only has blynk.run() and timer.run() functions.
The delay which I gave in the end was for precautionary measure. I was trying to send a limited number of requests from the loop hence I added a delay in the loop. That didn’t work either. I removed the delay as well now.
The problem still persists.


#9

is the error message the ONLY line you get in the serial? nothing else?