Hi Pete,
You are right, took me some “readings” to understand. The Edgent was a evolution from the first example, now I have patched yours with my beginners one 
BUT my DASHBOARD is not updating…everything works on the Serial
NOW, after this weekend I took over your
Deep_Sleep_Now(float sleep_time_minutes)
void WiFi_Connect(ssid, passw, wifi_connect_max_retries),
also the Case structure for the Wifi connect which is in the SETUP (all yours)
Within the Setup and the case structure you have
Blynk.config(auth); // Initialise the Blynk connection settings → works fine Blynk.config(auth," blynk,cloud", 443);–> does not connect
Blynk.connect(); → works only with first Blynk.config
See the BOLD in the serial ouput for the two cases:
8:52:36.823 →
18:56:09.420 → Wi-Fi connection - attempt number 1
18:56:09.904 → Wi-Fi connection - attempt number 2
18:56:10.384 → Wi-Fi connection - attempt number 3
18:56:10.901 → Wi-Fi connection - attempt number 4
18:56:11.386 → Wi-Fi connection - attempt number 5
18:56:12.666 → Wi-Fi connection - attempt number 6
18:56:13.199 → Wi-Fi connection - attempt number 7
18:56:13.681 → Wi-Fi connection - attempt number 8
18:56:14.163 → Wi-Fi connection - attempt number 9
18:56:14.683 → Wi-Fi connection - attempt number 10
18:56:15.176 → Wi-Fi connection - attempt number 11
18:56:15.176 → Wi-Fi CONNECTED
18:56:15.176 →
18:56:15.176 → YS:If we managed to connect to Wi-Fi then try to connect to Blynk, else go to sleep
18:56:15.176 → [6440]
18:56:15.176 → ___ __ __
18:56:15.216 → / _ )/ /_ _____ / /__
18:56:15.216 → / _ / / // / _ / '/
18:56:15.216 → ///_, /////_
18:56:15.216 → // v1.0.0-beta.3 on NodeMCU
18:56:15.216 →
18:56:15.216 → [6454]Connecting to blynk.cloud:443
18:56:20.427 → [11698] Connecting to blynk.cloud:443
18:56:25.650 → [16916] Connecting to blynk.cloud:443
18:56:30.865 → [22133] Connecting to blynk.cloud:443
18:56:33.182 → YS:Succeed to return from Blynk.Connect()
18:56:33.222 → FALSE from Blynk.connected(), failed - going to sleep
18:56:33.222 → >>>>>>>>>>>>>>>>>>>>> Going to sleep for 1.00 minutes
18:56:33.222 →
18:57:48.632 → Wi-Fi connection - attempt number 1
18:57:49.117 → Wi-Fi connection - attempt number 2
18:57:49.614 → Wi-Fi connection - attempt number 3
18:57:50.139 → Wi-Fi connection - attempt number 4
18:57:50.622 → Wi-Fi connection - attempt number 5
18:57:51.904 → Wi-Fi connection - attempt number 6
18:57:52.397 → Wi-Fi connection - attempt number 7
18:57:52.917 → Wi-Fi connection - attempt number 8
18:57:53.411 → Wi-Fi connection - attempt number 9
18:57:53.902 → Wi-Fi connection - attempt number 10
18:57:54.418 → Wi-Fi connection - attempt number 11
18:57:54.418 → Wi-Fi CONNECTED
18:57:54.418 →
18:57:54.418 → YS:If we managed to connect to Wi-Fi then try to connect to Blynk, else go to sleep
18:57:54.418 → [6439]
18:57:54.418 → ___ __ __
18:57:54.418 → / _ )/ / _____ / /_
18:57:54.418 → / _ / / // / _ / '/
18:57:54.418 → ///_, /////_
18:57:54.418 → /__/ v1.0.0-beta.3 on NodeMCU
18:57:54.418 →
18:57:54.418 → [6453] Connecting to blynk.cloud:80
18:57:54.858 → [6910] Ready (ping: 220ms).
18:57:55.018 → YS:Succeed to return from Blynk.Connect()
18:57:55.018 → YS:On Setup(), TRUE from Blynk.connected()
18:57:55.018 → Boot number: 1
18:57:55.018 → Wake Time = 0.06 seconds
18:57:55.059 → A0 read → 13.63
18:57:55.139 → RSSI:-80.00
18:57:55.219 → 28.94ºC
18:57:55.219 → Begin SRF
18:57:55.259 → distance [cm]–>: 160
18:57:55.259 → end Iterations: 0
18:57:55.379 → >>>>>>>>>>>>>>>>>>>>> Going to sleep for 10.00 minutes
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLRwKDdSO8"
#define BLYNK_DEVICE_NAME "ESP8266"
#include <BlynkSimpleEsp8266.h>
//#define APP_DEBUG
// -----------------------------Global Variables ---------------------------------
#define TRIGGER 13 // NodeMCU Pin D7=io13 for SFR
#define ECHO 14 // NodeMCU Pin D5=io14 for SFR
//#define TEMP 12 // NodeMCU Pin D6 for TempSensor
const int TEMP = 12;
#include <OneWire.h> // for Temp Diode
#include <DallasTemperature.h> // for Temp Diode
OneWire oneWire(TEMP); // TEMP=Temperature=io 12 Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature sensor
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-";
char ssid[] ="ssid";
char passw[] ="passw";
float wake_time = (float)millis()/float(1000); // Find out how long since the ESP rebooted
int bootCount = 0;
float sleep_time_minutes =0.5;
int CounterIn = 0;
int CounterOut = 0;
void setup()
{
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(TEMP, INPUT); //Temp Sensor
pinMode(4,OUTPUT); // Led Output switch
Serial.begin(115200);
sensors.begin(); // Start the DS18B20 sensor
WiFi_Connect(ssid,passw,50); // Attempt to connect to Wi-Fi
if (WiFi.status() == WL_CONNECTED) // If we managed to connect to Wi-Fi then try to connect to Blynk, else go to sleep
{
Serial.println("YS:If we managed to connect to Wi-Fi then try to connect to Blynk, else go to sleep");
Blynk.config(auth); // Initialise the Blynk connection settings
//Blynk.config(auth, blynk_server, blynk_port);
Blynk.connect(); // Attempt to connect to Blynk
Serial.println("YS:Succeed to return from Blynk.Connect()");
}
else
{
Serial.println ("Wi-Fi connection failed - going to sleep");
sleep_time_minutes = sleep_time_minutes * 2; // If you enable this line of code the it will make the device go to sleep for twice as long before trying again. Changing to 0.5 would make it try again sooner than normal
Deep_Sleep_Now(sleep_time_minutes);
}
if (Blynk.connected()) //= is Boolean TRUE, If we manages to connect to Blynk then carry-on as normal, else go to sleep
{
Serial.println ("YS:On Setup(), TRUE from Blynk.connected()");
}
else
{
sleep_time_minutes = sleep_time_minutes * 2; // If you enable this line of code the it will make the device go to sleep for twice as long before trying again. Changing to 0.5 would make it try again sooner than normal
Serial.println("FALSE from Blynk.connected(), failed - going to sleep");
Deep_Sleep_Now(sleep_time_minutes);
}
++bootCount;
Serial.println("Boot number: " + String(bootCount));
// the above is instead the Blynk.begin(auth,ssid ,passw );
}
void loop()
{
Serial.print("Wake Time = ");
Serial.print(wake_time);
Serial.println(" seconds");
BatteryLevel();
SignalStrenght();
TempValue();
SensorValue();
Blynk.run(); // Needed to ensure that the Wake Time value is always uploaded to Blynk before going to sleep
delay(100);
//digitalWrite (transistorPin, LOW); // turn off the supply
Deep_Sleep_Now(10);
}
BLYNK_CONNECTED() //sets the LED button to OFF at beginning
{
Blynk.syncVirtual(V0); // will cause BLYNK_WRITE(V0) to be executed
}
////------------------------------------------------- LED Switch On/Off on GPIO 4/D2--------------------------------------------------------
BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
digitalWrite(4,HIGH); // Set digital pin 2 HIGH
Serial.println("Set digital pin D2 HIGH");
}
else
{
// execute this code if the switch widget is now OFF
digitalWrite(4,LOW); // Set digital pin 2 LOW
Serial.println("Set digital pin D2 LOW");
}
}
//---------------------------------------------------- ANALOG READ Battery ---------------------------------------------
void BatteryLevel()
{
int sensorPin = A0; // select the input pin for the potentiometer
double sensorValue = 0; // variable to store the value coming from the sensor
double VoltageRead = 0;
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// MCU has 10 bits precision: 2^10= 1024 --> 1-1024 values where 3.3 V ~ 1024 (board!) (chip only to 1V).
VoltageRead= sensorValue/1024 *13.63;
Blynk.virtualWrite(V4,VoltageRead);
Serial.print("A0 read --> ");
Serial.println(VoltageRead);
}
//------------------------------------------------- Sensor Function ------------------------------------------------------------
// Function that does the SFR Sensing
void SensorValue(){
long duration;
int distance;
Serial.println("Begin SRF");
digitalWrite(TRIGGER, LOW);
delayMicroseconds(5);
// Trigger the sensor by setting the trigPin high for 10 microseconds:
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
// Read the echoPin. pulseIn() returns the duration (length of the pulse) in microseconds:
duration = pulseIn(ECHO, HIGH);
// Calculate the distance:
distance = duration*0.034/2;
//distance = (duration/2) / 29.1;
if (distance>0)
{
Blynk.virtualWrite(V3,distance); // sends the "distance" value to virtualPin V3
Serial.print("distance [cm]-->: ");
Serial.println(distance);
}
// Print the distance on the Serial Monitor (Ctrl+Shift+M):
//Serial.print("duration is the ECHO high :");
// Serial.println(duration);
Serial.print("end Iterations: ");
Serial.println(CounterIn);
CounterIn=CounterIn+1;
}
//------------------------------------------------- Temperature Function ------------------------------------------------------------
void TempValue()
{
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
if (temperatureC > -127)
{
Blynk.virtualWrite(V1,temperatureC);
}
Serial.print(temperatureC);
Serial.println("ºC");
}
//------------------------------------------------------ RSSI-----------------------------------------
void SignalStrenght()
{
float rssi = WiFi.RSSI();
Blynk.virtualWrite(V2,rssi);
Serial.print("RSSI:");
Serial.println(rssi);
}
/*---------------------------------DEEP SLEEP -----------------------------
* Function that performs deep sleep
* INPUT: Time to sleep in min
*
* ----------------------------------------------------------------
*/
void Deep_Sleep_Now(float sleep_time_minutes)
{
Serial.print(">>>>>>>>>>>>>>>>>>>>> Going to sleep for ");
Serial.print(sleep_time_minutes);
Serial.println(" minutes");
Serial.println();
ESP.deepSleep(sleep_time_minutes *60e6); // Deep Sleep time is specified in micros
delay(2000);
}
/*--------------------------------------------------------------
* Function that performs Wifi access tries
* INPUT: SSID - name in string
* PASSWORD in String
* Time of retries in INT
*
* GLOBAL PARAMETERS : Boolean WiFi.status() != WL_CONNECTED)
* need to #include <BlynkSimpleEsp8266.h>
* ----------------------------------------------------------------
*/
void WiFi_Connect(char ssid[],char passw[],int wifi_connect_max_retries) // New functon to handle the connectuon to the Wi-Fi network
{
int wifi_connect_count = 0; // New variable to keep track of how manty times we've tried to connect to the Wi-Fi
Serial.println(F("Printout from function Wifi_Connect(): Connecting to Wi-Fi"));
//WiFi.config(device_ip, dns, gateway, subnet); // Not needed if you just want to have a DHCP assigned IP address. If you diont use this then delete the device_ip, dns, gateway & subnet declarations
if (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, passw); // connect to the network
}
while (WiFi.status() != WL_CONNECTED && wifi_connect_count < wifi_connect_max_retries) // Loop until we've connected, or reached the maximum number of attemps allowed
{
delay(500);
wifi_connect_count++;
Serial.print(F("Wi-Fi connection - attempt number "));
Serial.println(wifi_connect_count);
}
if (WiFi.status() == WL_CONNECTED)
{
WiFi.mode(WIFI_STA);
Serial.println(F("Wi-Fi CONNECTED"));
Serial.println();
}
} //------------------------------------------ End of void WiFi_Connect trial