Converting legacy code to Blynk 2.0

I have a project which has run fine in legacy Blynk. When trying to covert to Blynk 2, my code causes a hiccup when entering certain pinmodes in the setup section.
I am using a Wemos D1 mini.

void setup() {
Serial.begin(19200);
delay(100);
BlynkEdgent.begin();
pinMode(18, OUTPUT);  //alarm bell relay
pinMode(17, OUTPUT);  //switch 1
pinMode(19, OUTPUT);  //switch 2
pinMode(20, OUTPUT);  //switch 3
//pinMode(6,INPUT_PULLUP);  // Door sensor
//pinMode(7,INPUT_PULLUP);  // PIR sensor
pinMode(5,INPUT_PULLUP);  // Deck sensor
timer.setInterval(1000L, myTimerPIR);
timer.setInterval(1000L, myTimerDoor);
timer.setInterval(1000L, myTimerDeck);
timer.setInterval(1000L, myTimerBell);
timer.setInterval(1000L, myStatusCheck);
}

The two lines commencing with ‘//’ are the lines causing the issue. When I run the code with either of these lines included, Blynk fails to connect through the internet. Without these two lines, Blynk connects up fine ( but does require that I re-configure the wifi name and password again!).

Is there any rational explanation for this?

I can post debug code if required.

@nikki-m please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Sorry. Done.
N.

What hardware are you using?

Pete.

Wemos D1 mini.

This code wont work on a D1 Mini, as GPIOs 6 & 7 are reserved, and GPIOs 17-20 don’t exist.

Pete.

My original code from the legacy vesion (which DOES work) is this:

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8080);
  pinMode(D3, OUTPUT);  //alarm bell relay
  pinMode(D4, OUTPUT);  //switch 1
  pinMode(D2, OUTPUT);  //switch 2
  pinMode(D1, OUTPUT);  //switch 3
//  pinMode(D6,INPUT_PULLUP);  // Door sensor
//  pinMode(D7,INPUT_PULLUP);  // PIR sensor
  pinMode(D5,INPUT_PULLUP);  // Deck sensor
  
  timer.setInterval(1000L, myTimerPIR);
  timer.setInterval(1000L, myTimerDoor);
  timer.setInterval(1000L, myTimerDeck);
  timer.setInterval(1000L, myTimerBell);
}

For some reason, the legacy code also ran happily with the "D " designations. It appears perhaps that Blynk 2.0 is not happy with them.
The two lines that failed on Blynk 2 are currently marked with ‘//’.

I think I have used the wrong chart for my conversions. Eg D3 in my chart says 18, but I understand should be 0.

I have 4 outputs and 3 inputs on this project? As this project runs in legacy, surely there are enough IO ports in Blynk 2.0?? Many many user-friendly ports are there actually available on this chip?

N.

It’s not the Blynk library that decides that’ it’s the board type you select in the Arduino IDE.
I guess you selected “Generic ESP8266” instead of “LOLIN(WEMOS) D1 RS & Mini”

That’s correct…

Blynk doesn’t have any I/O ports, its the board that has the ports.

The D1 Mini has sufficient suitable GPIO pins for this, but your original choice of pins probably wasn’t as well informed as it could have been, you should read this…

Also, your decision to have 54 timers all being called simultaneously every 1000ms isn’t a great idea…

You should read the “Staggering Timers” section of this post for more info…

Pete.

Sorry, I meant to say IO ports in the D1 mini, but my fingers decided to type something else.

I was just reading the very article about the IO ports of the device when you replied. So I will replan these port allocations.
As regards the timers - the legacy project was from when I was just learning about programming. I was planning to change that part of the code after It got it running on Blynk 2.

So it looks like I need a bit of a re-write on this project. Luckily, most of my others seem to be converting nicely. Well, as nicely as Blynk 2 will allow. Why, when the rest of the world is adding ‘dark mode’, does Blynk decide to take it away? I [used to] run all my projects in dark mode.

Thank you for your time and assistance.

You should also be aware that GPIO2 is the pin that the onboard LED of the D1 Mini is attached to.
It is used in the settings.ini tab of the ESP8266 Edgent example to give feedback during the provisioning process, so you should avoid using it for anything else.

I think aesthetics gets a lower priority than functionality at the moment.

Pete.

Pete, I have resolved the issue with GPIO ports.

I have loaded the code into a NodeMCU ESP12 module. This connects up and runs fine, producing the following info:
[4829] Using Dynamic IP: 192.168.43.105
[4829] CONNECTING_NET => CONNECTING_CLOUD
[5041] Current time: Thu Jul 8 13:32:25 2021
[5041] Connecting to blynk.cloud:443
[6234] Ready (ping: 12ms).
Alarm Start-up: 1
[8529] CONNECTING_CLOUD => RUNNING

However, when I load the code into a second NodeMCu device or a Wemos D1 mini, these devices does not connect to Blynk. I get the following info:
[820] Connecting to WiFi: Puddlenet 2
[4677] Using Dynamic IP: 192.168.43.39
[4677] CONNECTING_NET => CONNECTING_CLOUD
[4889] Current time: Thu Jul 8 13:34:17 2021
[4889] Connecting to blynk.cloud:443
[6167] Redirecting to lon1.blynk.cloud:443
[6175] Current time: Thu Jul 8 13:34:18 2021
[6175] Connecting to lon1.blynk.cloud:443
[7347] Redirecting to lon1.blynk.cloud:443

Any advice you can offer on why this is so? What is upsetting some devices but not others when running the same code?

Where can I find any pages which provide specific information about points to be aware of when programming code for Blynk2 as opposed to legacy Blynk? This sort of information appears to be sparce. I have several D1 mini boards running legacy code, but need to be aware of parts of the code which might not work with Blynk 2.

Thanks again,
N.

Are you using the same template ID for these devices?

On the Blynk documentation pages, and here on the forum.

Pete.

Yes, Pete, I am using the same template ID. I am loading the same .ino file into each device. Now, I cannot get any newly-loaded devices to connect. The only ones I now have working are ones I loaded yesterday. And yes, from the same .ino file with the same template ID.

I have even tried putting a static Authtoken into the code, but that failed, too. This is all so frustrating.

And the documentation is so poor for folk who do not yet know the new system. Just as an example, if I refer to any help documentation for widgets on the blynk2 mobile app, it still refers to ‘energy’ from the legacy version. This is Blynk2’s own documentation!

Why not try cloning the template and using the new template ID in your sketch for the second device?

Pete.

Just Tried your suggestion. NO change.

[770] INIT => CONNECTING_NET
[781] Connecting to WiFi: Puddlenet 2
[4621] Using Dynamic IP: 192.168.43.122
[4621] CONNECTING_NET => CONNECTING_CLOUD
[4832] Current time: Thu Jul 8 20:16:39 2021
[4832] Connecting to blynk.cloud:443
[6027] Redirecting to lon1.blynk.cloud:443

What exactly do these last two lines mean? These two lines keep repeating until I get a time-out.
N.

@nikki-m i assume that you’re in the UK?
The lon1 server is located in London.

What version of the library are you using now, and are you using dynamic provisioning?

Pete.

No, I am currently in the Netherlands. But my internet service comes through my (UK-based) EE mobile contract (connecting to whichever local service is offered to me as I travel through the country).

I am currently using Blynk v1.0.0. I have previously also used the beta 3 version, with the same results.

I am currently using dynamic provisioning, but have tried (also unsuccessfully) using static provisioning.

The version of code I have successfully loaded onto a NodeMCU is able to be successfully reconfigured for wifi. I have tried this several times and it has reconfigured each time. Surely this suggests that the network internet connection is ok.

N.

And what does your latest sketch look like?

Pete.

This sounds very similar to an issue I have trying to migrate a previously functioning sketch to “Blynk2.0”.

If I add the device template and device name defines and a static auth token.

The device will connect to wifi, and then fail to connect to Blynk in the exact same manner as yours.

I assumed my issue had to do with the fact that I’m using an ESP32-CAM and I have been unable to successfully compile a program when using the Espressif driver combined with BlynkEdgent and was also unable to have a legacy program connect to the new Blynk servers when statically provisioned.

Seems like the issue might be different than I thought.

Peter, I have successfully migrated two sketches from legacy to Blynk 2. One runs on a Wemos D1 mini, the other is running on a NoceMCU.

If I copy either sketch onto other devices, they fail today. They were copying successfully yesterday.

Would you like me to provide a full sketch for you to look at? Do I blank out the auth code before posting?

N.