Connection Issues and BlynkTimer

Hello all,

I have had trouble with getting BlynkTimer to work correctly,

I was getting the error…

> Compilation error: 'BlynkTimer' does not name a type; did you mean 'BlynkBitSet'?

I followed some online instructions and deleted and reinstalled the library to the latest version, although I have never installed the library before so I believe it just installed the same version again.

Once I reinstalled the library, this didn’t resolve the BlynkTimer issue, but now there is a new issue where the device won’t connect, I just get this in the serial monitor over and over.

[43075] Connecting to blynk.cloud:8080
[47974] Connecting to blynk.cloud:80
[48076] Connecting to blynk.cloud:8080
[52975] Connecting to blynk.cloud:80
[53077] Connecting to blynk.cloud:8080
[57976] Connecting to blynk.cloud:80
[58078] Connecting to blynk.cloud:8080
[62977] Connecting to blynk.cloud:80
[63079] Connecting to blynk.cloud:8080
[67978] Connecting to blynk.cloud:80
[68080] Connecting to blynk.cloud:8080

Any general advice on way-forward would be great.

Here is my whole code as it stands,

//Spira001

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL2GriGYWFd"
#define BLYNK_TEMPLATE_NAME "Spira Fairy Lights Only"
#define BLYNK_AUTH_TOKEN "xnPhxFufNr8z5yRC7ebn7RGB7Rvz5uvr"
#define WIFI_SSID ""
#define WIFI_PASS ""

BlynkTimer timer;

int C01var = 1;  // Colour Variables
int C02var = 1;
int C03var = 1;
int C04var = 1;
int C05var = 1;
int C06var = 1;
int C07var = 1;
int C08var = 1;
int C09var = 1;
int C10var = 1;
int C11var = 1;
int C12var = 1;
int C13var = 1;
int C14var = 1;
int C15var = 1;
int C16var = 1;
int C17var = 1;
int C18var = 1;
int C19var = 1;
int C20var = 1;
int C21var = 1;
int C22var = 1;
int C23var = 1;
int C24var = 1;
int C25var = 1;
int C26var = 1;
int C27var = 1;
int C28var = 1;
int C29var = 1;
int C30var = 1;
int C31var = 1;
int C32var = 1;
int C33var = 1;
int C34var = 1;
int C35var = 1;
int C36var = 1;
int C37var = 1;
int C38var = 1;
int C39var = 1;
int C40var = 1;
int C41var = 1;
int C42var = 1;
int C43var = 1;
int C44var = 1;
int C45var = 1;
int C46var = 1;
int C47var = 1;
int C48var = 1;
int C49var = 1;
int C50var = 1;

int P01var = 1;  //power variable

int E01var = 1;     //select effect
int E02var = 1000;  //effect delay

int T01var = 0;  //Temperature
int T02var = 0;  //Humidity

int A01var = 0;  //CT1
int A02var = 0;  //CT2
int A03var = 0;  //CT3
int A04var = 0;  //CT4

int L01var = 0;  //Light Level LUX / 10

int V01var = 0;  //PSU Voltage
int V02var = 0;  //Mains detection

int R01var = 1;  //Relay control

#include <MKRNB.h>
#include <BlynkSimpleMKRNB.h>

NBClient client;
GPRS gprs;
NB nbAccess;

char pin[] = "";

BLYNK_WRITE(V50) { //P01var
  P01var = param.asInt();
  Serial.print("P01var = ");
  Serial.println(P01var);
}

BLYNK_WRITE(V53) { //R01var
  R01var = param.asInt();
  Serial.print("R01var = ");
  Serial.println(R01var);
}

BLYNK_WRITE(V18) { //C19var
  C19var = param.asInt();
  Serial.print("C19var = ");
  Serial.println(C19var);
}

BLYNK_WRITE(V20) { //C21var
  C21var = param.asInt();
  Serial.print("C21var = ");
  Serial.println(C21var);
}

BLYNK_WRITE(V22) { //C23var
  C23var = param.asInt();
  Serial.print("C23var = ");
  Serial.println(C23var);
}

BLYNK_WRITE(V24) { //C25var
  C25var = param.asInt();
  Serial.print("C25var = ");
  Serial.println(C25var);
}

BLYNK_WRITE(V26) { //C27var
  C27var = param.asInt();
  Serial.print("C27var = ");
  Serial.println(C27var);
}

BLYNK_WRITE(V28) { //C29var
  C29var = param.asInt();
  Serial.print("C29var = ");
  Serial.println(C29var);
}

BLYNK_WRITE(V30) { //C31var
  C31var = param.asInt();
  Serial.print("C31var = ");
  Serial.println(C31var);
}

BLYNK_WRITE(V32) { //C33var
  C33var = param.asInt();
  Serial.print("C33var = ");
  Serial.println(C33var);
}

BLYNK_WRITE(V34) { //C35var
  C35var = param.asInt();
  Serial.print("C35var = ");
  Serial.println(C35var);
}

BLYNK_WRITE(V36) { //C37var
  C37var = param.asInt();
  Serial.print("C37var = ");
  Serial.println(C37var);
}

BLYNK_WRITE(V38) { //C39var
  C39var = param.asInt();
  Serial.print("C39var = ");
  Serial.println(C39var);
}

BLYNK_WRITE(V40) { //C41var
  C41var = param.asInt();
  Serial.print("C41var = ");
  Serial.println(C41var);
}

BLYNK_WRITE(V42) { //C43var
  C43var = param.asInt();
  Serial.print("C43var = ");
  Serial.println(C43var);
}

void updateTimer() 
{

Blynk.virtualWrite(V54, T01var); 
  Serial.print("T01var = ");
  Serial.println(T01var);

Blynk.virtualWrite(V55, T02var);  
  Serial.print("T02var = ");
  Serial.println(T02var);

}

void setup() {
  // Debug console
  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, nbAccess, gprs, client, pin);
}

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


You need to move these libraries to the top of the sketch above the Blynktimer line.

and these lines need to be the first lines in your sketch
#define BLYNK_TEMPLATE_ID “TMPL2GriGYWFd”
#define BLYNK_TEMPLATE_NAME “Spira Fairy Lights Only”
#define BLYNK_AUTH_TOKEN “xnPhxFufNr8z5yRC7ebn7RGB7Rvz5uvr”

billd

Without seeing the serial output that appears when you first boot the board its difficult to say, but it looks like a GPRS connectivity issue to me.

I don’t understand why you have WiFi credential in your sketch when you’re connecting via GPRS…

Have you successfully connected to a mobile network using the SIM card you have installed in your board?

Pete.

Hello Bill,

Thank you so much for this, so obvious now that you say this, of course the library needs to be included first!

Best,

M

Hi @PeteKnight,

I started with an example sketch I found online, I am guessing that these were present and I haven’t removed them, I couldn’t find an example sketch for the Arduino MKR 1500 NB in the example browser.

Can I safely remove these, anything else I need to do?

Best,

M

Yes.

Taking onboard my comments about serial monitor output would be a start.

Pete.

Hi @PeteKnight,

The board is now connecting properly, with the occasional disconnect and reconnect after following the advice of @Bill_Donnelly.

This is a pretty standard start up output, ping does vary a little.

[12274] Connecting to  ...
[13797] Connected to GPRS
[13798] Connecting to blynk.cloud:80
[15044] Ready (ping: 352ms).

Thank you,

M

Hello @Bill_Donnelly @PeteKnight,

My connection issues have reared their ugly heads again.

I am not able to connect to the cloud, I have tried existing code that I know that works (and is on deployed devices that are working).

I have stripped it right back to this code.

/*************************************************************
  Blynk is a platform with iOS and Android apps to control
  ESP32, Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build mobile and web interfaces for any
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: https://www.blynk.io
    Sketch generator:           https://examples.blynk.cc
    Blynk community:            https://community.blynk.cc
    Follow us:                  https://www.fb.com/blynkapp
                                https://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example shows how to use Arduino MKRNB 1500
  to connect your project to Blynk.
  NOTE: This requires MKRGSM library
    from https://www.arduino.cc/en/Reference/MKRNB
  Feel free to apply it to any other example. It's simple!
 *************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL2zbbw8FHB"
#define BLYNK_TEMPLATE_NAME "Standard Pixel Strip"
#define BLYNK_AUTH_TOKEN "F1dxVBRsxRn8yXMZxAO6QlENzuHAVwyd"

#include <MKRNB.h>
#include <BlynkSimpleMKRNB.h>

NBClient client;
GPRS gprs;
NB nbAccess;

// Your SIM credential
// Leave empty, if missing pin
char pin[]  = "";

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, nbAccess, gprs, client, pin);
}
void loop()
{
  Blynk.run();
}

and this is what I get from the serial monitor… The occasional ‘Cannot init’ then repeated failed attempts to connect.

14:44:27.461 -> [10463] Cannot init
14:44:48.395 -> [10463] Cannot init
14:45:06.356 -> [10463] Cannot init
14:45:27.335 -> [10463] Cannot init
14:45:48.308 -> [10463] Cannot init
14:46:06.128 -> [7349] Connecting to  ...
14:46:07.673 -> [8872] Connected to GPRS
14:46:07.673 -> [8873] Connecting to blynk.cloud:80
14:48:11.427 -> [132626] Connecting to blynk.cloud:8080
14:50:14.329 -> [255503] Connecting to blynk.cloud:80
14:52:17.249 -> [378458] Connecting to blynk.cloud:8080

I don’t really know where to go from here, have tried multiple MKR 1500 NB devices.

Thank you!

Best,

M

I keep saying that it’s the serial output that appears WHEN YOU FIRST BOOT YOUR BOARD that tells us the most, but despite me saying this you haven’t posted this so far.

Also, you should be posting the text from your serial monitor, not a screenshot.

Pete.

Hi @PeteKnight,

This is everything that the board sent to the serial monitor, I am guessing something is being missed as the computer is not ready when the board is sending it’s bootup messages, I will try to use Putty or some other method to capture it.

I just copied the text from the serial monitor into <>, I don’t know why it has formatted it like that.

Best,

M

@PeteKnight,

So weird, I reconnected the device to try and capture the startup messages, and the device connected straight away to Blynk, was there issues with Blynk yesterday?

I had to enter a delay(1000); at the beginning of void setup() to capture this but here it is.

08:49:07.153 -> [1112] 
08:49:07.153 ->     ___  __          __
08:49:07.153 ->    / _ )/ /_ _____  / /__
08:49:07.153 ->   / _  / / // / _ \/  '_/
08:49:07.153 ->  /____/_/\_, /_//_/_/\_\
08:49:07.153 ->         /___/ v1.3.2 on MKR NB 1500
08:49:07.153 -> 
08:49:07.153 ->  #StandWithUkraine    https://bit.ly/swua
08:49:07.153 -> 
08:49:07.153 -> 
08:49:07.153 -> [1113] Modem init...
08:49:15.693 -> [9661] Connecting to  ...
08:49:28.508 -> [7147] Connecting to  ...
08:49:30.034 -> [8671] Connected to GPRS
08:49:30.034 -> [8671] Connecting to blynk.cloud:80
08:49:32.315 -> [10953] Ready (ping: 788ms).

Any idea of what might have been going on?

Best,

Matt

These two messages seem rather odd!

This ping time is very bad. Long pings on GPRS are normally caused by poor signal strength. What sort of antenna do you have connected to your GPRS modem?

Are you in an area of poor cell tower coverage for the mobile provider that you’ve chosen for your data SIM?

Pete.

Hello @PeteKnight,

I have connected a larger antenna than the one that comes with the MKR 1500 NB and I get this.

09:04:49.647 -> [7667] Connecting to  ...
09:04:51.156 -> [9191] Connected to GPRS
09:04:51.156 -> [9191] Connecting to blynk.cloud:80
09:04:52.517 -> [10536] Ready (ping: 353ms).

A little better but not great,

I am in an OK area for coverage, but indoors it is not great here, thick walls etc.

Our devices will be installed all over the country, but always outdoors in plastic enclosures.

I had a message from Dimitry about changing over to the Singapore server but nothing came of that, I will chase that up.

I think the double messages were because when I added the delay(1000); the device would no longer connect, so I removed it and rebooted the board, hence the two messages.

Best,

Matt