Have searched for this and cannot find any info on this particular error. Maybe I am not doing something right.
My sketch works great, however, when this command is inserted, the serial monitor and blynk IoT stops working. I see the seconds in Blynk count up for a couple seconds, then everything stops.
if ( Percent / 1000 <= 25 && millis() > 60000 ) {
Blynk.logEvent("low_water","Please add water to Piney!")
Serial.println("add water to tree");
}
The if condition is not even met, yet it stops the entire thing.
But if I just comment out that one line as so…
if ( Percent / 1000 <= 25 && millis() > 60000 ) {
// Blynk.logEvent("low_water","Please add water to Piney!");
Serial.println("add water to tree");
}
then the rest of the program and I see the rest of the data on Blynk.
I do have the event setup in Blynk.
EDIT: any instance of Blynk.logEvent(“eventname”) causes entire program to not run on Blynk. I have tried it many ways.
FYI… full code here: (please excuse sloppy code, I am beginner )
/*************************************************************
WARNING!
It's very tricky to get it working. Please read this article:
http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware
You’ll need:
- Blynk IoT app (download from App Store or Google Play)
- Arduino Uno board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "redacted"
#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "redacted"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "redacted";
char pass[] = "redacted";
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
const int OUT_PIN = A2;
const int IN_PIN = A4;
//Capacitance between IN_PIN and Ground
//Stray capacitance value will vary from board to board.
//Calibrate this value using known capacitor.
const float IN_STRAY_CAP_TO_GND = 24.48;
const float IN_CAP_TO_GND = IN_STRAY_CAP_TO_GND;
//Pullup resistance will vary depending on board.
//Calibrate this with known capacitor.
const float R_PULLUP = 34.8; //in k ohms
const int MAX_ADC_VALUE = 1023;
float capacitance;
#include <Smoothed.h> // Include the library
Smoothed <float> mySensor;
Smoothed <float> mySensor2;
int full = 1100;
int empty = 400;
int freq = 100;
int momentTime = 1000;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, millis() / 1000);
}
void waterLevel()
{
float smoothedSensorValueAvg = mySensor.get();
//Capacitor under test between OUT_PIN and IN_PIN
//Rising high edge on OUT_PIN
pinMode(IN_PIN, INPUT);
digitalWrite(OUT_PIN, HIGH);
int val = analogRead(IN_PIN);
digitalWrite(OUT_PIN, LOW);
//Big capacitor - so use RC charging method
//discharge the capacitor (from low capacitance test)
pinMode(IN_PIN, OUTPUT);
while (millis() % (1000) != 0) //Default 1000
;
//Start charging the capacitor with the internal pullup
pinMode(OUT_PIN, INPUT_PULLUP);
unsigned long u1 = micros();
unsigned long t;
int digVal;
//Charge to a fairly arbitrary level mid way between 0 and 5V
//Best not to use analogRead() here because it's not really quick enough
do
{
digVal = digitalRead(OUT_PIN);
unsigned long u2 = micros();
t = u2 > u1 ? u2 - u1 : u1 - u2;
} while ((digVal < 1) && (t < 400000L));
pinMode(OUT_PIN, INPUT); //Stop charging
//Now we can read the level the capacitor has charged up to
val = analogRead(OUT_PIN);
//Discharge capacitor for next measurement
digitalWrite(IN_PIN, HIGH);
int dischargeTime = (int)(t / 1000L) * 5;
delay(dischargeTime); //discharge slowly to start with
pinMode(OUT_PIN, OUTPUT); //discharge remainder quickly
digitalWrite(OUT_PIN, LOW);
digitalWrite(IN_PIN, LOW);
//Calculate and print result
capacitance = -(float)t / R_PULLUP
/ log(1.0 - (float)val / (float)MAX_ADC_VALUE);
capacitance = capacitance*1000;
// Read the value from the sensor
float currentSensorValue = capacitance;
// Add the new value to both sensor value stores
mySensor.add(currentSensorValue);
// Get the smoothed values
//float smoothedSensorValueAvg = mySensor.get();
// Output the smoothed values to the serial stream. Open the Arduino IDE Serial plotter to see the effects of the smoothing methods.
float Percent = constrain(map(smoothedSensorValueAvg,empty,full,0,100000),0,100000);
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V6, Percent/1000);
Blynk.virtualWrite(V7, smoothedSensorValueAvg);
if ( Percent / 1000 <= 25 && millis() > 60000 ) {
Blynk.logEvent("low_water","Please add water to Piney!");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Serial.println("baud rate set complete!");
Blynk.begin(auth, wifi, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);
Serial.println("connected to Blynk complete!");
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
timer.setInterval(2000L, waterLevel);
Serial.println("timer interval set complete!");
//Serial.println("initializing pinmodes 1...");
pinMode(OUT_PIN, OUTPUT);
//digitalWrite(OUT_PIN, LOW); //This is the default state for outputs
//Serial.println("initializing pinmodes 2...");
pinMode(IN_PIN, OUTPUT);
//digitalWrite(IN_PIN, LOW);
//Serial.println("initializing smoothed...");
mySensor.begin(SMOOTHED_AVERAGE, 25); //Default 50
//Serial.println("initializing sensor clear...");
mySensor.clear();
Serial.println("Setup loop complete!");
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}