RobotDyn UNO+WiFi... can't get Blynk.config working

Good evening everyone… I’m still playing around with the RobotDyn UNO+WiFi.
I was able to make it work with the Blynk.begin(auth, ssid, pass); way, and now i’m working to have a more … in-depth control of the connection.

I was able to connect the board to WiFi via the WiFiesp lib i’m using now but i am unable, then, to connect to the Blynk server. That i know, there SHOULD be two ways:
1) Blynk.config(auth); and then Blynk.connect();
2) Classic if (client.connect(server, 80)) { Serial.println(“Connected to server”);

1)
If i use Blynk.config(auth); , i got the error andidate expects 4 arguments, 1 provided
If i use Blynk.config(auth, “blynk-cloud.com”, 80); it says error: no matching function for call to 'BlynkWifi::config(char [33], const char [16], int)'
Blynk.config(auth, server, port) using const char* and uint isn’t working either…

2)
well i know how to connect to a page, but not how to send the auth stuff…

Put your actual AUTH code in place of the word auth :wink:

http://help.blynk.cc/getting-started-library-auth-token-code-examples/getting-started

oook… tried with
~
Blynk.config(“xxxxxxxxxxxxxxxxxxxxxxxxxxxx”);
and
Blynk.config(“xxxxxxxxxxxxxxxxxxxxxxxxxxxxx”, “blynk-cloud.com”, 80)

~
still nothing…

About the other way. using the “classic” wifi libraries, i can use
client.connect(“blynk-cloud.com”, 80)… and then how can i send the auth code?

Not quite following your intent here… what is client.connect()? This is not a Blynk command.

There is two ways of setting up a typical Blynk sketch… aside from the traditional Blynk.begin() which requires the library to work out all the connection details there is the DIY type method you seem to be using

  1. Connect to the internet/network… how you do this can depend on your hardware, networking needs, etc.

  2. Connect to Blynk across the above pre-connected network… this is where all you really need is the proper AUTH code, Server IP and port (the port needed will depend on the server connected too… Cloud or Local).

Using this 2 part method, you use the Blynk command Blynk.config(AUTH, Server IP, Server Port); optionally but generally followed up with the Blynk.connect(); command (although it will try to connect at first Blynk.run() command as well.

If you are not connecting, even with a properly configured network, then either your AUTH code, IP or port is incorrect.

At this point you need to setup Debug with a separate Serial link to a terminal or IDE display and look at the results of the connection attempt.

For the WIFI connection, i am using WiFiEsp library other than the Blynk ones, which is a bridge between the old arduino wifi library (pretty much the same functions) and the AT commands for the 8266

#include "WiFiEsp.h"
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

so for the WiFi part i have something like this

 // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    // don't continue
    lcd.home(); lcd.clear();
     lcd.print ("   WiFi shield");
     lcd.setCursor (0,1);
     lcd.print ("   NOT present");
    while (true);
  }
  
   // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
  lcd.home(); lcd.clear();
     lcd.print ("Connecting to ");
     lcd.setCursor(0,1);
    lcd.print(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }
  lcd.home(); lcd.clear();
  lcd.print("WiFi: " + (String)ssid);
  lcd.setCursor (0,1);
  long rssi = WiFi.RSSI();
  lcd.print("Strenght " + (String)rssi + " dBm");

it gives me couple more infos i can use. And it actually works.
Now the Blynk.config part… i was digging a bit inside the BlynkSimpleShieldEsp8266.h library, and there you can see:

void begin(const char* auth,
               ESP8266&    esp8266,
               const char* ssid,
               const char* pass,
               const char* domain = BLYNK_DEFAULT_DOMAIN,
               uint16_t    port   = BLYNK_DEFAULT_PORT)

and it is used like Blynk.begin(auth, wifi, ssid, pass);

while for the config

void config(ESP8266&    esp8266,
                const char* auth,
                const char* domain = BLYNK_DEFAULT_DOMAIN,
                uint16_t    port   = BLYNK_DEFAULT_PORT)

so the actual syntax IS NOT Blynk.config(auth); (copy-paste from docs.blynk.cc)
but instead Blynk.config (wifi, auth); and then Blynk.connect (); like you said.

That way, (for board: Arduino Uno, Connection: ESP8266 WiFi Board) works without giving any errors, and it connects. Now I’m having some disconnect/connect problems every couple of minutes but as for now the code is really messy 'cause i was just experimenting with that Blynk.config… have to clean it up and work on it.





About the other way ( client.connect(“blynk-cloud.com”, 80) ), that is the code classic arduino wifi libraries use…
As an example (if you want to take a look) https://github.com/bportaluri/WiFiEsp/blob/master/examples/WebClientSSL/WebClientSSL.ino

I was thinking if i could use that instance in some way or another instead of Blynk’s Blynk.config(wifi, auth); and Blynk.connect(); since it does, pretty much, the same thing, but i dont know how to pass the auth code to blynk-cloud

That is becasue the BlynkSimpleShieldEsp8266.h library is meant for use with the independent ESP8266 (like ESP-01) as a shield. Your RobotDyn UNO+WiFi. is a bit of a different beast, using the ESP in a semi-proprietary mode I believe.

You would probably be better using a different Blink library with your independent network connection that links via a Serial connection (that may lead to your WiFi adapter)… perhaps this? It used the basic BlynkSimpleStream.h library

From what i know, the Uno+Wifi is just an UNO board with an ESP chip connected via a DIP SWITCH, so that you don’t have the hassle of cables, connect and disconnect stuff… In fact i think its an excellent board… cheap and you can chose what to do with the ESP/ATMEGA just moving the switches (MCU+WIFI - shield mode, USB+MCU - loading arduino sketches, USB+ESP - AT commands even using Arduino IDE’s serial monitor, and GND-GPIO0 for firmware flashing).

You gave me an interesting tip about the serial connection library… i have to experiment.

Now I came up to another issue… ofc when something goes right, something else HAS to go wrong lol…
I was using the blynktimer to make a call to a function every 60 seconds to check if the hardware was still connected to the blynk server and, in case, reconnect.
Problem is, when i use the timer, whatever it could do, it prevents blynk from connecting.
With this part of code

  Blynk.config(wifi,auth);
  do 
  {
    lcd.setCursor (0,0); lcd.print("Blynk connecting");
    Blynk.connect();
    blynkConnStat = Blynk.connected();
  } while (blynkConnStat == false);
  lcd.setCursor (0,0); lcd.print("Blynk connected!");

usually it takes 10-15 seconds to connect (-> Blynk connected! and the rest), but when i activate the timer, it gets stuck inside the loop (->Blynk connecting). I have to comment ( //) everything about it to make it work again

//BlynkTimer timer; 
[...]
//timer.setInterval(60000L, checkForDisconnect);
[...]
// timer.run();

I tried to use the timer.setInterval function right before the end of void setup() or at the beginning, same problem
I wonder if it has something to do with my alternative WiFi management, but i doubt so…

Since we’re here… the latest working sketch (with disabled timer function)

    // Libreria WiFiEsp
    #include <WiFiEsp.h>
    #include <WiFiEspClient.h>
    #include <WiFiEspServer.h>
    #include <WiFiEspUdp.h>

    // Blynk ESP8266 (WiFi + Internet)
    #include <ESP8266_Lib.h>
    #include <BlynkSimpleShieldEsp8266.h>

    // Display
    #include <Wire.h>
    #include <LiquidCrystal_PCF8574.h>

    char auth[] = "xxxxxxxx";
    char ssid[] = "xxxxx";
    char pass[] = "xxxxx";

    #define EspSerial Serial
    //#include <SoftwareSerial.h>
    //SoftwareSerial EspSerial(3, 4); // RX, TX

    // PIN connections
    const byte intLed = 13;               // Internal blue Led
    const byte displayBrightnessPin = 11; // Pin for Display Backlight
    WidgetTerminal terminal(V1);          // Attach virtual serial terminal to Virtual Pin V1

    // Variables and Constants
    boolean ledState = 0;    
    byte displayBrightness = 0;    
    int status = WL_IDLE_STATUS;          // the Wifi radio's status   
    bool blynkConnStat = 0;
    int disconnected = 0;                 // count how many times it disconnected from blynk

    // Objects
    ESP8266 wifi(&EspSerial);
    LiquidCrystal_PCF8574 lcd(0x27);      // set the LCD address to 0x27 for a 16 chars and 2 line display                        
    //BlynkTimer timer;                   // Create a Timer object called "timer"

    void setup()
    {
      EspSerial.begin(115200);
      pinMode(intLed, OUTPUT);
      pinMode(displayBrightnessPin,OUTPUT);
      digitalWrite (intLed, ledState);
      
      WiFi.init(&EspSerial);
      Wire.begin();
      
      lcd.begin(16, 2);                             // initialize the lcd
      lcd.setBacklight(255);                        // Backlight function must be always on (255)
      analogWrite (displayBrightnessPin, 255);      // Display Full brightness
      lcd.home(); lcd.clear();
      lcd.print("LCD 16x2 @ 0x27");
      lcd.setCursor (0, 1);
      lcd.print("    STARTING    ");
      delay(3000);
      analogWrite (displayBrightnessPin, 10);       // Display Night Mode
      
      // Everything about connections
      checkForDisconnect();
      
      //  timer.setInterval(60000L, checkForDisconnect);                               //  Check Blynk connection every minute
      disconnected = 0;
      lcd.setCursor (13,1); lcd.print (disconnected);
    }

    void loop()
    {
    if (WiFi.status() == WL_CONNECTED)
      {
        Blynk.run();
      }
      else
      {
        checkForDisconnect();
      }
    // timer.run();    // BlynkTimer is working...
    }

    BLYNK_CONNECTED() {
    lcd.setCursor (0,0); lcd.print("Blynk connected!");
    }

    // You can send commands from Terminal to your hardware. Just use
    // the same Virtual Pin as your Terminal Widget
    BLYNK_WRITE(V1)
    {
      String writing = param.asStr();
      if (String("Marco") == writing) 
      {  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
        terminal.println("You said: 'Marco'") ;
        terminal.println("I said: 'Polo'") ;
      }else if (String("l") == writing) 
      {  // typing "l" will change the internal led (pin13) status
        ledState = !ledState;
        digitalWrite(intLed, ledState);
      }else if (String("w") == writing) 
      {  // typyng "w" checks the wifi signal strenght
        WifiStrenght();
      } else
      {
        // Send it back
        terminal.print("You said:");
        String writing = param.asStr();
        terminal.println(writing);
        terminal.println();
        lcd.home(); lcd.clear();
        lcd.print ("You said " + writing);
      }
      // Ensure everything is sent
      terminal.flush();
    }

    void WifiStrenght() 
    {
      lcd.setCursor (0,1);
      long rssi = WiFi.RSSI();
      lcd.print("RSSI " + (String)rssi + " dBm");
    }


    void checkForDisconnect()
    {
    disconnected ++;
    lcd.setCursor (13,1); lcd.print (disconnected);
       // check for the presence of the shield
      if (WiFi.status() == WL_NO_SHIELD) 
      {          // don't continue
        lcd.home(); lcd.clear();
        lcd.print ("WiFi shield");
        lcd.setCursor (0,1);
        lcd.print ("NOT present");
        while (true);
      }
      
        // attempt to connect to WiFi network
      while ( status != WL_CONNECTED) 
      {
        lcd.home(); lcd.clear();
        lcd.print ("Connecting to ");
        lcd.setCursor(0,1);
        lcd.print(ssid);
        // Connect to WPA/WPA2 network
        status = WiFi.begin(ssid, pass);
      }
      lcd.home(); lcd.clear();
      lcd.print("WiFi: " + (String)ssid);
      lcd.setCursor (0,1);
      long rssi = WiFi.RSSI();
      lcd.print("RSSI " + (String)rssi + " dBm");
      delay (3000);
        
       // blynk config and connection
      Blynk.config(wifi,auth);
      lcd.setCursor (0,0); lcd.print("Blynk connecting");
      Blynk.connect();

      terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
      terminal.println(F("-------------"));
      terminal.println(F("Type 'Marco' and get a reply, or type"));
      terminal.println(F("anything else and get it printed back."));
      terminal.println(F("Type l to change led status"));
      terminal.println(F("Type w to check wifi signal"));
      terminal.flush();
    }

The problem here is that it will try to run that function thousands of times a second when it IS disconnected… this is typically where a timer is used to periodically check for, and if necessary, run a reconnect routine.

I use this in my MEGA/ESP-01 sketch…

void loop() {
  timer.run();
  timer2.run();
  CNTR++;
  digitalWrite(HTB, !digitalRead(HTB));

  if (Blynk.connected()) {  // If connected run as normal
    Blynk.run();
  } else if (ReCnctFlag == 0) {  // If NOT connected and NOT already trying to reconnect, set timer to try to reconnect in 30 seconds
    ReCnctFlag = 1;  // Set reconnection Flag
    Serial.println("Starting reconnection timer in 30 seconds...");
    timer.setTimeout(30000L, []() {  // Lambda Reconnection Timer Function
      ReCnctFlag = 0;  // Reset reconnection Flag
      ReCnctCount++;  // Increment reconnection Counter
      Serial.print("Attempting reconnection #");
      Serial.println(ReCnctCount);
      wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
      Blynk.config(wifi, auth, server, port);
      Blynk.connect();  // Try to reconnect to the server
      if (Blynk.connectWiFi(ssid, pass)) {
        Blynk.connect();
      }
    });  // END Timer Function
  }
}

Not perfect, but effective in keeping the rest of the sketch running until re-connection.

That’s a smart piece of code… some questions about it:
CNTR++ in your void loop… what do you use that for? count for how long the code has been running?

timer.setTimeout(30000L, []() { // Lambda Reconnection Timer Function so when the code gets here, it waits 30secs and then call everything inside the function (ReCnctFlag = 0; ReCnctCount++; etc. ). Kinda like a delay(30000) that doesnt stop running the rest, right? I always used setInterval, didn’t notice this one

back to my code, just as a test, i tried to leave my void loop as simple as

void loop()
{
 Blynk.run();
 timer.run();    // BlynkTimer is working...
}

still, if i use the timer function (1 sec, 30 sec, 5 minutes) the result is always the same, blynk gets disconnected every couple of seconds (10-15 looking at the app). I’m not flooding since im not sending pretty much anything (and anyway, as i said, without the timer function, it works flawlessy… just couple of disconnects in a day, but i think that is due to the poor internet connection i’m using now). I will try without calling the function, manual mode, like “Blink without delay”

// constants won't change. Used here to set a pin number:
const int ledPin =  LED_BUILTIN;// the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

as for now i dont understant how the timer function messes with the code

It was for tracking how many loops per second the void loop() runs… as it can vary due to other actions.

It is NON-blocking unlike a delay, but is a countdown trigger, whatever code was included in that Lambda Function would not run until the timer has finished counting.

BlynkTimer is based on SimpleTimer… best understood with lots of experimenting :stuck_out_tongue_winking_eye:

https://playground.arduino.cc/Code/SimpleTimer#Functions

Ok back to the basics, “Year: Zero”… i’m starting again from scratch aiming to use the serial library you suggested.
The code i’m using now (working)

// WLAN
#include "WiFiEsp.h"

// Display
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>

// Software Serial
//#include "SoftwareSerial.h"
#define EspSerial Serial

// Blynk Serial Library
#include <BlynkSimpleStream.h>

// Variables and Constants
boolean iLedStat = 0;            // internal led status
byte displayBrightness = 0;      // analogWrite display brightness
//SoftwareSerial ESPserial(0, 1);  // Comms to ESP8266, RX, TX
int status = WL_IDLE_STATUS;     // the Wifi radio's status

// WLAN Settings
char ssid[] = "aaaaaaaa";
char pass[] = "bbbbbbbb";
char auth[] = "ccccccccccccccccccccccccccccccc";

// PIN connections
const byte iLedPin = 13;                   // Internal blue Led pin 13
const byte displayBrightnessPin = 11;      // Pin for Display Backlight
LiquidCrystal_PCF8574 lcd(0x27);           // set the LCD library to address 0x27

void setup()
{
  Serial.begin(9600);                    // initialize serial for ESP module @ 9600 baud
  WiFi.init(&Serial);                    // initialize ESP module
  pinMode(iLedPin, OUTPUT);                 // Pin settings
  pinMode(displayBrightnessPin,OUTPUT);
  digitalWrite (iLedPin, iLedStat);
  
  // Initializing and starting LCD
  Wire.begin();
  lcd.begin(16, 2);                             // initialize the lcd for a 16 chars and 2 line display
  lcd.setBacklight(255);                        // library backlight must be always ON (255)
  analogWrite (displayBrightnessPin, 255);      // Display Full brightness
  lcd.home(); lcd.clear();
  lcd.print("LCD 16x2 @ 0x27");
  lcd.setCursor (0, 1);
  lcd.print("    STARTING    ");
  delay(2000);
  analogWrite (displayBrightnessPin, 10);       // Display Night Mode

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) 
  {
     lcd.home(); lcd.clear();
     lcd.print ("WiFi shield");
     lcd.setCursor (0,1);
     lcd.print ("NOT present");
    while (true);                               // don't continue
  }

  while ( status != WL_CONNECTED)               // attempt to connect to WiFi network
  {
     lcd.home(); lcd.clear();
     lcd.print ("Connecting to");
     lcd.setCursor (0,1);
     lcd.print (ssid);  
     status = WiFi.begin(ssid, pass);            // Connect to WPA/WPA2 network
  }
  lcd.home(); lcd.clear();
  lcd.print ("NetworkConnected");
  lcd.setCursor (0,1);
  IPAddress ip = WiFi.localIP();
  lcd.print (ip);  
  delay (5000);
  
  if (status == WL_CONNECTED)
  {
  lcd.home(); lcd.clear();
  lcd.print ("Connecting Blynk");
 // Blynk.begin(Serial, auth);
  lcd.home(); lcd.clear();
  lcd.print ("Blynk Connected");
  }
}

void loop()
{
//Blynk.run();  
digitalWrite(iLedPin,(!digitalRead(iLedPin)));  // "I'm alive" led
// print the network connection information
  printCurrentNet();
  printWifiData();
}

void printWifiData()
{
  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  lcd.home(); lcd.clear();
  lcd.print ("Arduino IP Add.");
  lcd.setCursor (0,1);
  lcd.print (ip);  
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));  // "I'm alive" led
  delay (2000);

  // print your MAC address
  byte mac[6];
  WiFi.macAddress(mac);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
  lcd.home(); lcd.clear();
  lcd.print ("Arduino MAC Add.");
  lcd.setCursor (0,1);
  lcd.print (buf);
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));  
  delay (2000);
}

void printCurrentNet()
{
  // print the SSID of the network you're attached to
  lcd.home(); lcd.clear();
  lcd.print ("SSID");
  lcd.setCursor (0,1);
  lcd.print (WiFi.SSID());
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));
  delay (2000);

  // print the MAC address of the router you're attached to
  byte bssid[6];
  WiFi.BSSID(bssid);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
  lcd.home(); lcd.clear();
  lcd.print ("Router MAC Add.");
  lcd.setCursor (0,1);
  lcd.print (buf);  
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));
  delay (2000);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  lcd.home(); lcd.clear();
  lcd.print ("RSSI " + (String)rssi);
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));
  delay (2000);
}

I’ve also changed the UART speed of the ESP8266 to 9600 just to be sure (was 115200).
Now, if i comment the two function calls

printCurrentNet();
printWifiData();

so to not have all those delays around, and i un-comment the Blynk functions

//Blynk.begin(Serial, auth);
//Blynk.run();

so to start the Blynk connection, it gets stuck with the Blink.begin
I tried both hardware serial (this board uses the same 0-1 that USB uses, that’s why i need a LCD) and softwareSerial (using pin 0 and 1),and in both cases the ESP connects and all, but it doesnt pass the Blynk.begin

Any idea on this?

Updating… I’ve (FINALLY) found a timer library that is working for me.
From what i’ve read around was made under ESP8266 specs, so maybe that’s why.

other than this, i tried updating the ESP firmware with one of the latest, and they do not work, i had to go back to the previous one.

old firmware (working) esp8266_nonos_sdk_v154 (+ patch 1541)
new firmware (NOT working) esp8266_nonos_sdk-221

last WORKING sketch (which means it connects to blynk, it STAYS connected and it uses two timers)… (HURRAY!!!)
(yes the code is a mess i know that already :stuck_out_tongue: but as i said it’s still a test bench)

#include <Ticker.h>
void contatore ();
void signal ();




/* 
*       NETWORK CHECKER
*       10 / 10 / 2018
*
*   Hardware Needed:
*   - RobotDyn UNO+WiFi
*   - Display LCD w/ Controller (A4-SDA, A5-SCL, 11-Backlight Control)
*
*
*
*/

// WLAN
#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <WiFiEspServer.h>
#include <WiFiEspUdp.h>

// Display
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>

// Software Serial
#include "SoftwareSerial.h"

//#include <BlynkSimpleStream.h>

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// Variables and Constants
boolean iLedStat = 0;            // internal led status
byte displayBrightness = 0;      // analogWrite display brightness
SoftwareSerial ESPserial(0, 1);  // Comms to ESP8266, RX, TX
int status = WL_IDLE_STATUS;     // the Wifi radio's status
int counter = 0;
int reconnect = -1;

// WLAN Settings
char ssid[] = "kkkkkk";
char pass[] = "kvzzzz!";
char auth[] = "asdasdasdas";

// PIN connections
const byte iLedPin = 13;                   // Internal blue Led pin 13
const byte displayBrightnessPin = 11;      // Pin for Display Backlight
LiquidCrystal_PCF8574 lcd(0x27);           // set the LCD library to address 0x27

ESP8266 wifi(&ESPserial);
Ticker timer1 (contatore, 1000); 
Ticker timer2 (signal, 2000);
void setup()
{
  ESPserial.begin(9600);                    // initialize serial for ESP module @ 9600 baud
  WiFi.init(&ESPserial);                    // initialize ESP module
  pinMode(iLedPin, OUTPUT);                 // Pin settings
  pinMode(displayBrightnessPin,OUTPUT);
  digitalWrite (iLedPin, iLedStat);
  
  // Initializing and starting LCD
  Wire.begin();
  lcd.begin(16, 2);                             // initialize the lcd for a 16 chars and 2 line display
  lcd.setBacklight(255);                        // library backlight must be always ON (255)
  analogWrite (displayBrightnessPin, 255);      // Display Full brightness
  lcd.home(); lcd.clear();
  lcd.print("LCD 16x2 @ 0x27");
  lcd.setCursor (0, 1);
  lcd.print("    STARTING    ");
  delay(2000);
  analogWrite (displayBrightnessPin, 10);       // Display Night Mode

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) 
  {
     lcd.home(); lcd.clear();
     lcd.print ("WiFi shield");
     lcd.setCursor (0,1);
     lcd.print ("NOT present");
    while (true);                               // don't continue
  }

  while ( status != WL_CONNECTED)               // attempt to connect to WiFi network
  {
     lcd.home(); lcd.clear();
     lcd.print ("Connecting to");
     lcd.setCursor (0,1);
     lcd.print (ssid);  
    status = WiFi.begin(ssid, pass);            // Connect to WPA/WPA2 network
  }
  lcd.home(); lcd.clear();
  lcd.print ("NetworkConnected");
  delay (2000);
  
 Blynk.config(wifi,auth);
  lcd.setCursor (0,0); lcd.print("Blynk connecting");
  Blynk.connect();
  lcd.setCursor (0,0); lcd.print("Blynk connected ");
  

  timer1.start(); //start the ticker.
  timer2.start();
}

void loop()
{
digitalWrite(iLedPin,(!digitalRead(iLedPin)));  // "I'm alive" led
Blynk.run();
timer1.update();
timer2.update();
  //print the network connection information
  //printCurrentNet();
  //printWifiData();
}

void printWifiData()
{
  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  lcd.home(); lcd.clear();
  lcd.print ("Arduino IP Add.");
  lcd.setCursor (0,1);
  lcd.print (ip);  
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));  // "I'm alive" led
  delay (2000);

  // print your MAC address
  byte mac[6];
  WiFi.macAddress(mac);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
  lcd.home(); lcd.clear();
  lcd.print ("Arduino MAC Add.");
  lcd.setCursor (0,1);
  lcd.print (buf);
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));  
  delay (2000);
}

void printCurrentNet()
{
  // print the SSID of the network you're attached to
  lcd.home(); lcd.clear();
  lcd.print ("SSID");
  lcd.setCursor (0,1);
  lcd.print (WiFi.SSID());
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));
  delay (2000);

  // print the MAC address of the router you're attached to
  byte bssid[6];
  WiFi.BSSID(bssid);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
  lcd.home(); lcd.clear();
  lcd.print ("Router MAC Add.");
  lcd.setCursor (0,1);
  lcd.print (buf);  
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));
  delay (2000);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  lcd.home(); lcd.clear();
  lcd.print ("RSSI " + (String)rssi);
  digitalWrite(iLedPin,(!digitalRead(iLedPin)));
  delay (2000);
}

void contatore () {
counter++;
lcd.setCursor (0,1);
lcd.print (counter);
}

void signal () {
long rssi = WiFi.RSSI();
  lcd.setCursor (7, 1);
  lcd.print (rssi);
}

BLYNK_CONNECTED() {
reconnect++;
counter = 0;
lcd.setCursor (12, 1);
lcd.print (reconnect);
}

BTW… Using a sat internet connection in the middle of nowhere gives me a ping of around 660ms… I think that is the main reason for the random disconnections i’m having (1-2 / hour or so). Do you agree?

FYI, Blynk.begin() is a blocking call… no network/server connection, no further processing. When utilizing your own network connection you should use Blynk.config() as a non-blocking method of starting Blynk.

Who knows… I have never used Ticker, but I have also not had any issues with stability overtime with BlynkTimer (and one project had over a dozen of them), so I haven’t needed to look for alternatives.

It doesn’t help, but those are not drastically bad PING times either… And FYI you can make adjustments to Blynk’s heartbeat.

Blynk.config(wifi,auth);
lcd.setCursor (0,0); lcd.print(“Blynk connecting”);
Blynk.connect();
lcd.setCursor (0,0); lcd.print("Blynk connected ");

That’s what i am already using, but i was hoping to use directly the Serial Blynk Library just like the example

#include <BlynkSimpleStream.h>
[...]
Serial.begin(9600);
Blynk.begin(Serial, auth);

But… oh well, it works anyway so i think i’ll stick with the Blynk.config

Interesting the part about the Heartbeat. Is it the Blynk.run(); the function that pings the server? In that case, standard setting, you could have as much as 10 seconds (and even something more) between .run() and .run… a whole lot.

Apart from everything else, i really have to thank you for all the help you’re giving to me.
I will run another couple of test (more timers, more delay between functions simulating longer sensor acquisition process, ecc) then the part about IF DISCONNECT (taking a look at your code) then i could say I am up and running…
Maybe i could make a post with everything you need to know to run those boards, if anyone else is using them, from firmware flashing to… well everything i’ve discovered in the past days.

1 Like
#include <WiFiEsp.h>
#include <Adapters/BlynkWiFiCommon.h>

WiFiEspClient _blynkWifiClient;
BlynkArduinoClient _blynkTransport(_blynkWifiClient);
BlynkWifiCommon Blynk(_blynkTransport);

in setup()

  int status = WL_DISCONNECTED;
  while ( status != WL_CONNECTED) {
    status = WiFi.begin(ssid, pass);
  }
  Blynk.config(auth, BLYNK_DEFAULT_DOMAIN, BLYNK_DEFAULT_PORT);
  while (!Blynk.connect());
1 Like

awesome! as soon as i have some time, i’ll try that

A post was merged into an existing topic: Problems when the internet disconnects