Blynk example- trouble with connect

Hello. I’m just testing examples and I’ve encountered some problems.
I use arduino uno and ESP8266-01.
I’ve uploaded the terminal example. Works great. Then I added elements from the Get Data ‘(BLYNK_WRITE(V1))’ and Push Data (Blynk.virtualWrite(V5, millis() / 1000):wink: with Blynk timer examples. All these elements separatly work well. However, after the merger I can not get a connection with Blynk. (internet works). any help?

and a question. functions such as Blynk.connect or Blynk.syncAll (); can only be called from setup after reset board? or from anywhere after ESP power restore?

Thank you


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

#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
ESP8266 wifi(&Serial1);
BlynkTimer timer;
char ssid[] = "NA****";            // your network SSID (name)
char pass[] = "**GFia***t";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char auth[] ="e933****6b0755295e8efa";
bool Connected2Blynk;


WidgetTerminal terminal(V1);

BLYNK_WRITE(V10)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("V10 Slider value is: ");
  Serial.println(pinValue);

}



BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
	String strin=param.asStr();
	Serial.println(strin);
  if (strin==("Marco"))  {
    terminal.println("You said: 'Marco'") ;
    terminal.println("I said: 'Polo'") ;
    digitalWrite(13,HIGH) ;
  }

  else if (strin==("ela")){
        terminal.println("You said: 'ela'") ;
        digitalWrite(13,LOW);
       // digitalWrite(13,HIGH) ;
      }

    else if(strin==("ala")){
        Serial.println("odebrałem 'ala'");
        digitalWrite(13,HIGH);
      }

    if (strin==("ewa"))  {
        terminal.println("You said: 'ewa'") ;
        digitalWrite(13,LOW) ;
      }

  // Ensure everything is sent
  terminal.flush();
}



void zegar10()
{
	Blynk.virtualWrite(V3, millis() / 1000);
}

void printWifiData()
{
  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // 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]);
  Serial.print("MAC address: ");
  Serial.println(buf);
}

void printCurrentNet()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // 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]);
  Serial.print("BSSID: ");
  Serial.println(buf);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI): ");
  Serial.println(rssi);
}





void setup()
{
  // initialize serial for debugging
  Serial.begin(9600);
  // initialize serial for ESP module
  Serial1.begin(9600);
  // initialize ESP module
  WiFi.init(&Serial1);

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  Serial.println("You're connected to the network");
  Blynk.config(wifi,auth);
  Serial.println("Attempting to BLYNK");
  Blynk.connect();
  Connected2Blynk = Blynk.connected();
if(Connected2Blynk){
	Serial.println("połączone z BLYNK");}
else{
	Serial.println("NIEEEEEEE połączone z BLYNK");
}

Serial.println();
 printCurrentNet();
 printWifiData();
 
 timer.setInterval(5000L, zegar10);

 pinMode(13,OUTPUT);
 pinMode(8,INPUT);

} //setup end

void loop()
{

	Connected2Blynk = Blynk.connected();
	if(Connected2Blynk){
	Blynk.run();}
	
	 
	  	    }
	 

 

	  timer.run();

} //loop end

this simple code does not work either:

#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial


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

char auth[] = "e933e7c5dafswert5295e8efa";
int a0;
long a1;
long a2;
String strin = "";
char ssid[] = "NAxGA";            // your network SSID (name)
char pass[] = "Kxxat";        // your network password
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BlynkTimer timer;

WidgetTerminal terminal(V1);

void terminCzytaj(){
	if (strin==("Marco"))  {
	    terminal.println("You said: 'Marco'") ;
	    terminal.println("I said: 'Polo'") ;
	    digitalWrite(13,HIGH) ;
	  }

	  else if (strin==("ela")){
	        terminal.println("You said: 'ela'") ;
	        digitalWrite(13,LOW);
	       // digitalWrite(13,HIGH) ;
	      }

	    else if(strin==("ala")){
	        Serial.println("odebrałem 'ala'");
	        digitalWrite(13,HIGH);
	      }

	    else if (strin==("ewa"))  {
	        terminal.println("You said: 'ewa'") ;
	        digitalWrite(13,LOW) ;
	        int u=13;
	        terminal.print("flaga SW :");
	        terminal.println(u,BIN);
	        terminal.flush();
	      }

}
BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
 strin=param.asStr();

  // Ensure everything is sent
  terminal.flush();
  terminCzytaj();
}

// 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(V3,a1);
  Blynk.virtualWrite(V4,a2);

 //Blynk.virtualWrite(V11, a0);
}

BLYNK_WRITE(V10)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("V10 Slider value is: ");
  Serial.println(pinValue);
}
BLYNK_WRITE(V9)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("V9 button value is: ");
  Serial.println(pinValue);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(3000L, myTimerEvent);
  pinMode (13,OUTPUT);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
  a0=analogRead(A0);
  a1=millis() / 1000;
  a2=millis() / 2000;
}

@wiktol: Without seeing the code it will be hard to tell what goes wrong …

For Blynk.connect() or Blynk.syncAll () etc. check the documetation.

1 Like