The general problem is my sketch won’t run stand alone. When I compile and upload it to the board, it starts reporting on the Blynk web app as expected. If I unplug the board from USB, plug it back in, it doesn’t start reporting to the web app. Same USB cord is being used. The only difference is I didn’t upload the sketch to it. I tried pressing reset on the board and still not reporting in.
Environment:
Board is an Arduino clone - I have been compiling using LOLIN (WeMos) D1 R1. This is and ESP8622 board communicating via Wifi. The board is stamped with WeMos logo
The server is Blynk servers not local.
My mobile device is an Samsung Note 9 running latest Android build
Getting the same result using multiple mobile devices, so I don’t think it has anything to do with my mobile device.
Blynk Library version 1.1.0
Here is my code:
//River Level indicator
#define BLYNK_TEMPLATE_ID "TMPL3mUxMvMJ"
#define BLYNK_DEVICE_NAME "Creek Meter"
#define BLYNK_AUTH_TOKEN "**********"
// Comment this out to disable prints and save space
// #define BLYNK_PRINT Serial
// Define Physical connection to sensor
#define TRIGPIN 2 // Board pin D4
#define ECHOPIN 0 // Board pin D3
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "DTW";
char pass[] = "************";
BlynkTimer timer;
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
void sensorDataSend()
{
//Initialize measurement variables
float duration = 0; //time between ping and receive on sensor
float distance = 0; //distance calculated in millimeters
int feet = 0;
int inches = 0;
int remainder_inches = 0;
// Set the trigger pin LOW for 2uS to stablized sensor
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
// Set the trigger pin HIGH for 20us to send pulse
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(20);
// Return the trigger pin to LOW
digitalWrite(TRIGPIN, LOW);
// Capture an incoming pulse
duration = pulseIn(ECHOPIN, HIGH);
// Determine distance in meters from duration
// Use 343 metres per second as speed of sound
// Divide by speed of sound by 1000 (.0343) as we result want millimeters
distance = (duration / 2) * 0.343;
//convert to inches
inches = distance/25.4;
//convert to feet
feet = inches/12;
//determine remainder in inches
remainder_inches = inches-(feet*12);
Serial.println(inches);
Blynk.virtualWrite(V3, inches);
}
void setup()
{
// Debug console
Serial.begin(115200);
Serial.println("Running");
Blynk.begin(auth, ssid, pass);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
timer.setInterval(1000L, sensorDataSend);
// intialize physical pins on Arduino
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}
void loop()
{
Blynk.run();
timer.run();
}