Unstable connection to server

Hello everyone!
I have a piece of code that used to run perfectly on blynk. I tried going back to it today to make some changes and suddenly it could not keep a stable connection to the server anymore. After some testing (mainly comparing it to the quickstart template which connected fine to the server and then porting it into the quickstart code little by little to see which piece of code made the connection to the server fail) i figured out that the issue is in the setup function. Namely, the pinMode declarations, as that is the only piece of code that, once ported into the quickstart template, causes the connection to become unstable. However, i have no idea why this even happens. Has anyone else experienced this and/or sees the issue with the code?
TIA!

#define BLYNK_TEMPLATE_ID "***"
#define BLYNK_TEMPLATE_NAME "***"
#define BLYNK_AUTH_TOKEN "***"


#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>


char ssid[] = "***";
char pass[] = "***";

BlynkTimer timer;

int blinkLed=0;
int value=0;
unsigned long UnlockCheckM;
unsigned long LockCheckM;
unsigned long proximityM =0;
int proximityCounter=0;

int bck = 18; 
int fwd = 5; 
int pirsensor=25; 
int bckswtch=32; 
int fwdswtch=33;
int chrgprt=2; 
int light = 19;
int chargelvl;
int blink = 13;
int emglock=35;

double lon=11.631249708439752;
double lat=44.385188154128755;

BLYNK_WRITE(V0)
{
  int value = param.asInt();

  Blynk.virtualWrite(V1, value);
}

void myTimerEvent()
{
  Blynk.virtualWrite(V2, millis() / 1000);
}

void setup()
{
  Serial.begin(115200);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  pinMode(fwd,OUTPUT);
  pinMode(bck,OUTPUT);
  pinMode(chrgprt,OUTPUT);
  pinMode(light,OUTPUT);
  pinMode(blink,OUTPUT);
  pinMode(chargelvl,INPUT);
  pinMode(emglock,INPUT_PULLUP);
  pinMode(bckswtch,INPUT_PULLUP);
  pinMode(fwdswtch,INPUT_PULLUP);
  pinMode(pirsensor,INPUT_PULLUP);
}

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

}

This is what the serial monitor looks like when the above code is uploaded to the board. It just keeps going:

When you post serial output please copy and paste the text from your serial monitor, with triple backticks, rather than a screenshot.

You’re initialising chargelvl without assigning a value to it, to it will have the value of zero.
You’re then assigning pin zero as an input.

GPIO0 is a strapping pin, and could be causing you issues by doing this with it.

Pete.

Hi Pete,
oh my bad, sorry, will be sure to do that going forward.
Managed to solve the issue!
Thank you!

1 Like