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
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?