BlynkEdgent Based Sketch Cannot Connect to Wifi

Hello Everyone,
Still working on non-blocking Edgent code on my chicken coop project, but also working away at another project and running into an unexpected error.

I am getting error 701 when attempting to provision an ESP32 with the sketch shown below.
I can go through the provisioning process, insert my wifi info but the device never joins the network and gives me the following error message:

[37623] WAIT_CONFIG => CONFIGURING
[40155] Sending board info...
[68387] Applying configuration...
[68387] WiFi SSID: "hotchs" Pass: xxxxxxx (I blanked this out, actual output shows password)
[68388] Blynk cloud: 5-0T8m1NBMk4oIIKhFvs6lSsTj1UTNkX @ blynk.cloud:443
[68393] CONFIGURING => SWITCH_TO_STA
[68394] Switching to STA...
[69504] SWITCH_TO_STA => CONNECTING_NET
[69505] Connecting to WiFi: "hotchs"
[99506] Last error code: 701
[99510] Configuration stored to flash

Code:


// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLiTcSd8qR"
#define BLYNK_DEVICE_NAME "ScaleSwitch"
 
#define BLYNK_FIRMWARE_VERSION        "0.1.1"
 
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
 
#define APP_DEBUG
 
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
//#define USE_TTGO_T7
 
#include "BlynkEdgent.h"
 
WidgetLED led1(V1);
WidgetLED led2(V2);
 
BlynkTimer timer;
 
int realSwitch = 0;
const int realSwitchPin = 27;
bool scaleSwitchOn = false;
bool blynkScaleSwitchOn = false; 
bool blynkScaleSwitchFirst = false;
bool scaleOn = false;
bool scaleRunning = false;
int batteryVoltageRaw;
int batteryVoltageMap;
const int batteryVoltagePin = 36;
 
const int output1 = 4;
const int scaleDisplayMOSFET = 16;
const int scaleMOSFET = 17;
const int output4 = 18;
 
 
 
void setup()
{
  Serial.begin(115200);
  delay(100);
  BlynkEdgent.begin();
 
  pinMode(realSwitchPin, INPUT);
  pinMode(batteryVoltagePin, INPUT);
  pinMode(output1, OUTPUT);
  pinMode(scaleMOSFET, OUTPUT);
  pinMode(scaleDisplayMOSFET, OUTPUT);
  pinMode(output4, OUTPUT);
 
  digitalWrite(output1, LOW);
  digitalWrite(scaleDisplayMOSFET, LOW);
  digitalWrite(scaleMOSFET, LOW);
  digitalWrite(output4, LOW);
  Blynk.syncAll();
  timer.setInterval(1000,blynkData);
 
}
 
void realScaleSwitch() {
 realSwitch = digitalRead(realSwitchPin);
 if (realSwitch == 1) {
   scaleSwitchOn = true;
 }
 else if (realSwitch == 0) {
   scaleSwitchOn = false;
 }
}
 
 
void switchState() {
  if ((blynkScaleSwitchOn) || (scaleSwitchOn)) {
    scaleOn = true;
 }
  if ((!scaleSwitchOn) && (!blynkScaleSwitchOn)) {
    scaleRunning = false;
  }
}
 
 
void scaleOperation() {
  realScaleSwitch();
  switchState();
  if (scaleOn) {
    digitalWrite(scaleMOSFET, HIGH);
    digitalWrite(output4, HIGH);
    timer.setTimeout(45000, []() 
    {
      digitalWrite(scaleDisplayMOSFET, HIGH);
      scaleOn = false;
      scaleRunning = true;
    });
  }
  else if ((!scaleOn) && (!scaleRunning)) {
    digitalWrite(scaleDisplayMOSFET, LOW);
    digitalWrite(scaleMOSFET, LOW);
    digitalWrite(output4, LOW);
  }
}
 
 
void blynkData() {
  if (scaleOn) {
    Blynk.virtualWrite(V1, HIGH);
  }
  if (scaleRunning) {
    Blynk.virtualWrite(V1, LOW);
    Blynk.virtualWrite(V2, HIGH);
  }
  if ((!scaleOn) && (!scaleRunning)) {
    Blynk.virtualWrite(V1, LOW);
    Blynk.virtualWrite(V2, LOW);
  }
  batteryVoltageRaw = analogRead(batteryVoltagePin);
  Blynk.virtualWrite(V3, batteryVoltageRaw);

}

BLYNK_WRITE (V0)
{
  if (param.asInt() == 0) {
    blynkScaleSwitchOn = false;
  }
  else if (param.asInt() == 1) {
      blynkScaleSwitchOn = true;
  }
}
 
 
 
void loop() {
  BlynkEdgent.run();
  scaleOperation();
}

I am using Blynk Library 1.1.0

Thanks!

As far as I know, the 701 error means your device was unable to connect to the router.


#define BLYNK_PROV_ERR_NONE     0      // All good
#define BLYNK_PROV_ERR_CONFIG   700    // Invalid config from app (malformed token,etc)
#define BLYNK_PROV_ERR_NETWORK  701    // Could not connect to the router
#define BLYNK_PROV_ERR_CLOUD    702    // Could not connect to the cloud
#define BLYNK_PROV_ERR_TOKEN    703    // Invalid token error (after connection)
#define BLYNK_PROV_ERR_INTERNAL 704    // Other issues (i.e. hardware failure)

Your device can’t connect to your WiFi with the credentials that are being supplied, or your router is rejecting the connection for some other reason.

Is your router offering a 2.4GHz connection on this SSID?
Are your SSID and password correct (note that both are case sensitive).
Have you tried rebooting your router?

You’re calling the scaleOperation function every time your void loop executes. You are then doing some other very cumbersome stuff, calling other functions, setting flags and clearing them with a anon-blocking timer.

I’d suggest that a you use a BlynkTimer to call a function which simply does everything needed in one location. Your code will then execute better, and be easier to follow and debug.

Pete.

Hey Pete, thanks for the quick reply.

I’ll switch that over to a BlynkTimer function. I’ve had other projects work fine utilizing that method as long as I don’t use any blocking code and everything operates quickly but I’ll switch it over and see if that helps.

I have tried to connect to multiple 2.4GHZ networks and no luck on any of them with the same error so it isn’t an issue regarding that, the SSID (which I don’t get to input during provisioning, I simply select a network during that process) or the password as I have confirmed correct passwords for all networks tried so far.

I’ll re-do the code utilizing BlynkTimers only and see if that helps.

Thanks!

Pete.

Sorry, forgot to add that to my last post.
Yes I have tried rebooting the router.

Is your router configured to use a very small pool of IP addresses in its DHCP settings?
Is it possible that you’ve simply run-out of available IP addresses to be allocated?

Pete.

I don’t believe that to be the issue. I’ve tried it on 4 different networks at this point with the exact same error. I’ve rebooted all routers as well on all 4 networks.

On the off chance all those networks have run out of available IP’s… how would I even check that?

You’d need to check the DHCP pool range in the router config, then run an IP address scan tool to check which addresses are used. This would tell you if all the available addresses are used.

Seems more likely that your board’s WiFi circuitry is dead, or you have a power supply issue.
Have you tested with a simple (non Edgent) sketch?

Pete.

Hmmm, I’ll try another board.
I’ve tried mutiple power supplies as well with no difference.

I would have thought a board with a bad wifi circuit wouldn’t generate a “setup” network that my phone connects to when trying to provision the board but stranger things have happened I suppose.

I have a spare board at home I can try. I’ll update you this evening on my findings.

Actually, I’ll try a non-edgent sketch and see if it connects with that as you suggested, that way we will know if it is a circuit issue with the board for sure.

1 Like

So it isn’t wifi circuitry, a standard “non-edgent” sketch connects no problem.

Actually, I just migrated the exact same code to a non-edgent Blynk Example and it’s connected to my blynk cloud and visible.

Okay, you don’t have a board type un-commented, and you’re using GPIO0 for something.

Presumably the custom board configuration section of Settings.h looks like this…

#else

  #warning "Custom board configuration is used"

  #define BOARD_BUTTON_PIN            0                     // Pin where user button is attached
  #define BOARD_BUTTON_ACTIVE_LOW     true                  // true if button is "active-low"

  //#define BOARD_LED_PIN             4                     // Set LED pin - if you have a single-color LED attached
  //#define BOARD_LED_PIN_R           15                    // Set R,G,B pins - if your LED is PWM RGB
  //#define BOARD_LED_PIN_G           12
  //#define BOARD_LED_PIN_B           13
  //#define BOARD_LED_PIN_WS2812      4                     // Set if your LED is WS2812 RGB
  #define BOARD_LED_INVERSE           false                 // true if LED is common anode, false if common cathode
  #define BOARD_LED_BRIGHTNESS        64                    // 0..255 brightness control

#endif

So GPIO0 is being used by Edgent as your credentials reset pin. You should read this…

Pete.

I’m using a custom board that I have working perfectly with 2 other edgent based sketches.
That variable is actually for the pin state, not the pin itself. the pin for the switch can be seen on following line as:

const int realSwitchPin = 27;

I use GPIO 0 for my credential reset pin which has always worked flawlessly in the past and is the default credential reset pin used by the custom board setting.

Quick update. Tried an Edgent sketch with no modifications and no change. Still will not connect.

Just want to make a quick update, or more a lack of update.
I’ve uninstalled and re-installed the Blynk app on my phone. I’ve tried multiple boards and I can’t get any “new” sketches to connect to wifi through Edgent, same error as above.

What I find strange is that any of my currently functioning projects will update no issue OTA, or even over USB if I accidentally brick them so I can’t access over wifi anymore. They will accept the new firmware and boot back up on wifi no problem.

Any thoughts, is this worth submitting an issue on github at this point?

Have you tried enabling the “Erase All Flash Before Sketch Upload” option in the IDE (requires latest ESP32 core version I think).

Pete.

Hey Pete,

I can’t find that option in the IDE however I do have esptool.py installed and I just used it to wipe one of my boards (successfully according to the esptool.py output).

I then tried to upload a blank Edgent example with only the needed template id and device token.

Same result. Accepts the credentials during provisioning and then hangs before re-booting itself and spitting out this on the serial monitor (wifi credentials removed for security):

[37745] WAIT_CONFIG => CONFIGURING
[37745] Sending board info...
[70245] Applying configuration...
[70246] WiFi SSID: "xxxxxx" Pass: xxxxx
[70246] Blynk cloud: 44umGRSLrh_beEJmSOWFj8ebNME0vrhi @ blynk.cloud:443
[70250] CONFIGURING => SWITCH_TO_STA
[70252] Switching to STA...
[71363] SWITCH_TO_STA => CONNECTING_NET
[71363] Connecting to WiFi: "hotchs"
[121364] Last error code: 701

One more thing I tried to isolate the issue from the board or network:
I flashed Tasmota firmware to the device and successfully connected to a wifi network.
The same device will not connect to the same network using Blynk.Edgent provisioning.

You aren’t doing anything weird with template or device names, such as editing them after they’ve been assigned, are you?

Pete.