Arduino mkr 1010 rimane nel setup - Troubles using Blynk.config()

Arduino mkr1010 se non si connette al server di blynk rimane nel setup
e non va nel loop.

That’s because Blynk.begin is a blocking function. If it doesn’t connect then the execution of your code is stopped.
You can use Blynk.config and Blynk.connect instead if you need a non-blocking connection routine.

https://docs.blynk.cc/#blynk-firmware-configuration

Pete.

Check this post it will be clearer what Pete ment…

Scusa ma non parlo inglese .
Premetto che il programma funziona bene quando si connette al server.
La mia domanda e se posso eseguire lo sketch di arduino anche se non si connette a server di blynk.

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
char auth[] = "4136235385";
char ssid[] = "Vo71";
char pass[] = "N5";
WidgetLCD blynk_lcd(V31);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
//#include <EEPROM.h>



#define BANCONOTA5    5
#define BANCONOTA10   6
#define BANCONOTA20   7
#define BANCONOTA50   8
#define BANCONOTA100  9
#define RESET         10
int key[6] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};
int pin[6]= {BANCONOTA5,BANCONOTA10, BANCONOTA20, BANCONOTA50,BANCONOTA100,RESET, };
int  banconota5  = 0;
int  banconota10  = 0;
int  banconota20  = 0;
int  banconota50  = 0;
int  banconota100  = 0;

int  sommapar = 0;
int addr_c = 30;
void setup()
{
  Blynk.begin(auth, ssid, pass);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(1,0);
  lcd.print("WIN GAMES");
  lcd.setCursor(0,1);
  lcd.print("TOTALI");
  blynk_lcd.clear();
  blynk_lcd.print(1, 0,sommapar );
  blynk_lcd.print(1, 1, "TOTALI1");
  blynk_lcd.clear(); 
  
 // EEPROM.get  (addr_c,sommapar); 

  for (int i= 0;i<6 ; i++)
  {
    pinMode(pin[i],INPUT_PULLUP);
  }
  Serial.begin(9600);
   Blynk.begin(auth, ssid, pass);
}

void loop() 
{
  int k;
  
  for (int i= 0;i<6 ; i++)
  {
    k = digitalRead(pin[i]);
    if ( key[i] != k ) 
    { 
      if ( key[i] == HIGH && k == LOW )
      {
        Serial.print("PIN");
        Serial.print(pin[i]);

        switch (pin[i]) 
       {
        case BANCONOTA5:
          banconota5 = banconota5 + 5;
          sommapar = banconota5 +  banconota10 + banconota20 + banconota50 + banconota100;
         // EEPROM.put(addr_c,sommapar);
          Serial.println(" BANCONOTA 5");
          break;
        case BANCONOTA10:
          banconota10 = banconota10 + 10;
         sommapar = banconota5 +  banconota10 + banconota20 + banconota50 + banconota100;
         
          Serial.println(" BANCONOTA 10");
          break;
        case BANCONOTA20:
          banconota20 = banconota20 + 20;
         sommapar = banconota5 +  banconota10 + banconota20 + banconota50 + banconota100;
          Serial.println(" BANCONOTA 20");
          break;
        case BANCONOTA50:
          banconota50 = banconota50 + 50;
          sommapar = banconota5 +  banconota10 + banconota20 + banconota50 + banconota100;
          Serial.println(" BANCONOTA 50");
          break;
        case BANCONOTA100:
          banconota100 = banconota100 + 100;
          sommapar = banconota5 +  banconota10 + banconota20 + banconota50 + banconota100;
          Serial.println(" BANCONOTA 100");
          break;
        case RESET:
        banconota5   = 0;
        banconota10  = 0;
        banconota20  = 0; 
        banconota50  = 0; 
        banconota100 = 0;
        sommapar     = 0;
          Serial.println(" AZZERAMENTO TOTALI");
          break;  
        }
        Serial.print("Totale = ");
        Serial.println(sommapar);
         blynk_lcd.print(4, 0,sommapar ); 
          blynk_lcd.print(4, 1, " TOTALI ");    
      }
      key[i] = k;
    }

  lcd.setCursor(8, 1);  
  lcd.print(sommapar); 
  }
  Blynk.run();
}

As I said before, if you use Blynk.begin and it can’t connect to the Blynk server then your void loop will never be executed.

If you use Blynk.config and Blynk.connect then if you can’t connect to the Blynk server then the code will carry-on without being connected to Blynk and will execute your void loop.

Pete.

come ti ha detto Pete, usa prima Blynk.config e poi Blynk.connect invece di Blynk.begin(). In questo modo non si blocca nell setup se il MKR resta senza connessione. Prova a vedere come viene usato nel link che ti ho dato io (scusa il mio italiano, pero’ sono un po arrugginito :nerd_face: )

Grazie domani provo devo andare a lavoro buona serata.

1 Like

Yes… as stated above. And here is an example…

Grazie a tutti per i consigli ma non riesco a modificare il mio codice che ho postato
potreste cortesemente modificare il mio codice ?
Vi ringrazio anticipatamente:pleading_face:

buona sera a tutti ho modificato il codice ma si blocca tutto errore usb

salve con arduino mkr1010 mi sembra che la funzione Blynk.config() funziona anche se dopo qualche ora si disconnette .
Ora sto provando con arduino yun ma non funziona con Blynk.config()

cosi si connette .

 #define BLYNK_PRINT Serial
#include <Bridge.h>
#include <BlynkSimpleYun.h>
char auth[] = "413f5b4a3a7535385"; 

void setup()
{
 Serial.begin(9600);

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

void loop()
{
  Blynk.run();
}

invece cosi non funziona.

#define BLYNK_PRINT Serial
#include <Bridge.h>
#include <BlynkSimpleYun.h>
char auth[] = "4136"; 

void setup()
{
 Serial.begin(9600);
     Blynk.config(auth);
     Blynk.connect();
  //Blynk.begin(auth);
  // You can also specify server:
 // Blynk.begin(auth, "blynk-cloud.com", 80);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  Blynk.run();
}

Unless someone has the same board type as you, to test your code with, all we can to is guess.

Salve non riesco a far funzionare arduino yun con la funzione
Blynk.config()
cioè se non si connette al server continua ad eseguire lo sketck

Please don’t create new topics when you already have a related topic going. I merged your post back here.

As stated in the Docs, Blynk.config() assumes you have ALREADY connected your device to your network by whatever means it can (not Blynk related). So figure out how that needs to be done… and the Blynk connection will follow.

Dove posso trovare un esempio funzionante sono 2 mesi che non riesco a far funzionare
arduino in assenza di connessione .
ho provato con arduino mkr1010,arduino yun’,arduino mega con ethernet w5100
ma niente non riesco a proseguire.
Se cortesamente potreste consigliarmi uno skecth giĂ  fatto solo da copia e incolla .

If you want to use Blynk.config() you will need to set-up your network connection manually before you call Blynk.connect().
How you do that will depend on the specific hardware (shield and Ethernet/Wi-Fi adaptor) you are using.

You will need to be clearer about EXACTLY which hardware you plant to test this with.

Pete.

@Wingames Since you already have a topic about this, I merged them together.

This is not always possible… each type of hardware device has a different way of connecting… not to mention your networking will be different then others, etc.

Blynk.config() examples are seemingly more for WiFi connections as that is the most commonly used for IoT, but it can often be used with other methods as well… But as already referenced in this topic, for someone to assist with your particular hardware, they probably need the same hardware to test… and thus provide requested code.

1 Like