MKR1000 Idiosyncratic Wifi Connectivity

I am having issues w/ the MKR1000 board in the Blynk environment. Below pls find a test sketch I ran successfully multiple times about a month or so ago, which no longer works reliably. Upon running the sketch now, connection to Blynk establishes successfully may be 1 in 10 tries. I am unclear why it doesn’t work reliably now.

The Wifi is robust (my computer is attached to it as well), and I tried this on two different Wifi networks with the same results. An Arduino example sketch scanning networks successfully picks these up. I believe the Wifi functionality is fine/operational. This behavior seems idiosyncratic.

Has anybody observed this? What are suitable troubleshooting strategies?
Thanks in advance.


Supporting information:
Serial port read-back when it doesn’t work:

[5001] Connecting to
[25002] Connecting to
[45003] Connecting to
[65004] Connecting to
[85005] Connecting to
[105006] Connecting to
This keeps going on indefinitely.

The few times it works, after the 1st attempt at connecting serial port read-back:
ready (ping: 36ms)

Blynk version 0.4.7., Arduino 1.8.2, Wifi101 0.14.2

Test sketch code:

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space

#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>

const int testpin = A0;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxx"; //  your network SSID (name)
char pass[] = "xxxxxxxxxxxxxx"; // your network password

unsigned long currenttime; // Variables needed to trigger timed event
unsigned long previoustime = 0; // Variables needed to trigger timed event
unsigned long interval = 10000; // Variables needed to trigger timed event

void setup() {
Blynk.begin(auth, ssid, pass);
  // Or specify server using one of those commands:
  //Blynk.begin(auth, ssid, pass, "", 8442);
  //Blynk.begin(auth, ssid, pass, server_ip, port);

void loop()

////// function outside of loop to capture and upload data to Blynk

void test(){

int measurement = analogRead(testpin);

//Every 10 seconds, print some BS
  currenttime = millis();
  if(currenttime - previoustime > interval){
    Serial.println("Timed event every 10 sec"); //embed code to send data to Thingspeak here
    Blynk.virtualWrite(V5, measurement);
    Blynk.virtualWrite(V6, measurement);
    previoustime = currenttime;

I’m having connection issues also (see Project stays offline on ALL mobile devices). The only thing in your code that I notice many other users commenting on is the use of delay in the main loop. Yours is pretty small so I don’t know if it should be suspect. I’ll let more experienced users than me comment…

Thanks for your note, DesertDrummer. This is a good point. I had actually played around with delays (minimum 100, maximum 250ms), and this hadn’t made a difference, so I left this as is. What is so strange is that this sketch worked without any problems about a month ago.

Yes, strange. Mine worked up until about 8:00 last night. :confused:

The use of delay is just a no go. Use BlynkTimer to kick off time related things. It’s non-blocking so the command is the only thing in the loop.

I also added three backticks before and after your code so it makes it look good :slight_smile:

Thanks, Lichtsignaal, for your suggestion and the “beautification” of my post. Looks a lot better :slight_smile:
Per your suggestion, I removed the delay step altogether, but this did not fix the connectivity issue. If I judge execution of the program properly, it never makes it to the loop, and gets hung up in the set-up step trying to connect to the server.
I have to admit that I’m very much a novice at this stuff, and so I am a bit stumped at this point.

It looks very basic to me. Can you try and comment out the test() from the loop and see what happens?

I disabled the test() function, and uploaded the sketch 4 times, it worked on the first occasion [getting ping ready feedback), and then again didn’t connect on the next three attempts. This is the idiosyncratic behaviour I was referring to. On occasion, it will work, more than 90% of the time it will not. When I first wrote and tested the sketch a month or so ago, the code I posted worked reliably. Is there anything that has changed since then?
Thanks again for your very helpful input.

Well, Wifi could be the problem. For example, neighbours setting up a new router and messing with the channels so you get interference, nearby airports (radar is also 2.4 Ghz). Where is the device located physically in relation to the accesspoint or router? It could make a difference.

You’re right, this is definitely a possible cause. I tried to hedge against this by testing my system on two different Wifi networks. Same troubles. For my tests, I am currently about 4 feet from the router, and the Arduino test sketch shows a signal strength of b/w -35 dBm and -42 dBm. My laptop is connected to the same Wifi as well, no issues at all.

While I haven’t been able to fix this, here are a few more bits of information that may help to narrow the cause of this issue:

–> Using a slightly changed test sketch on the MKR1000, I can connect wirelessly to Thingspeak and upload data. This to me verifies that the wireless connection is not the issue.

–> I can connect to Blynk using an Uno board and a wired connection. This to me indicates that I don’t have a systematic problem with Blynk.

Consequently, a plausible rationale would be that there is some sort of incompatibility specifically b/w the MKR1000 and Blynk in my set-up. Have others observed this, and if so, how has that been fixed?