Here’s my setup.
- I’ve got Blynk running on an M5Stack - works great.
- The connection between my phone and the M5Stack is via BLE - works great.
- I have a Toshiba FlashAir card in my DSLR camera. I’m trying to initiate a WiFi connection from the Arduino Blynk board to the FlashAir card to pull data and execute scripts.
- In isolation (a non-Blynk sketch) this works like a champ. Inside a Blynk sketch, no dice.
The WiFi.h here refers to ESP8266WiFi.h.
Here’s my isolated test code (sourced from other people’s examples) that works without Blynk:
#include <ArduinoHttpClient.h>
#include <WiFi.h>
#include <M5Stack.h>
#include "FileHelpers.h"
char ssid []= "flashair_001";
char pass [] = "12345678";
const char* host = "192.168.0.1";
// Use WiFiClient class to create TCP connections
WiFiClient wifi;
HttpClient client = HttpClient(wifi, host, 80);
int status = WL_IDLE_STATUS;
String response;
int statusCode = 0;
void setup()
{
M5.begin(); //specific init for this board.
M5.Lcd.setBrightness(200);
Serial.begin(115200);
delay(10);
listNetworks();
while (status != WL_CONNECTED) {
Serial.print(status + " : Attempting to connect to Network named: ");
Serial.println(ssid); // print the network name (SSID);
// Connect to WPA/WPA2 network:
delay(1000);
status = WiFi.begin(ssid, pass);
}
Serial.println("Connected!");
}
void loop()
{
}
void listNetworks() {
// scan for nearby networks:
Serial.println("** Scan Networks **");
int numSsid = WiFi.scanNetworks();
if (numSsid == -1) {
Serial.println("Couldn't get a wifi connection");
while (true);
}
// print the list of networks seen:
Serial.print("number of available networks:");
Serial.println(numSsid);
// print the network number and name for each network found:
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
Serial.print(thisNet);
Serial.print(") ");
Serial.print(WiFi.SSID(thisNet));
}
}
That routine connects to the FlashAir wifi network just fine and I get to “Connected” without a problem.
Here are the relevant parts of my sketch with Blynk, where I never manage to get to status == WL_Connected:
#include <BlynkSimpleEsp32_BLE.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <ETH.h>
#include <M5Stack.h>
#include <ArduinoHttpClient.h>
#include <WiFi.h>
//a bunch of blah blah blah and other irrelevant code
char ssid[] = "flashair_001";
char pass[] = "12345678";
void setup()
{
Serial.begin(115200);
Blynk.begin(auth);
M5.begin();
ConnectToFlashAir();
}
void ConnectToFlashAir() {
//WiFi.disconnect();
listNetworks();
status = WiFi.begin(ssid, pass);
BlynkDelay(500);
while (status != WL_CONNECTED) {
Serial.print(String(status) + " : Attempting to connect to Network named: ");
Serial.println(ssid); // print the network name (SSID);
// Connect to WPA/WPA2 network:
BlynkDelay(500);
status = WiFi.begin(ssid, pass);
}
Serial.println("Connected!")
}
The output is:
** Scan Networks **
E (1617) wifi: esp_wifi_scan_start 967 wifi not start
number of available networks:-2
6 : Attempting to connect to Network named: flashair_001
6 : Attempting to connect to Network named: flashair_001
…and so on.
The value of 6 corresponds to status WL_DISCONNECTED.
Interestingly, if I uncomment WiFi.disconnect() at the beginning (recommended on another thread, I get the following behavior:
** Scan Networks **
number of available networks:2
0) flashair_001 Signal: -16 dBm 1) CGNVM-ADD0 Signal: -57 dBm
6 : Attempting to connect to Network named: flashair_001
6 : Attempting to connect to Network named: flashair_001
6 : Attempting to connect to Network named: flashair_001
…and on and on for ever.
So a little closer, but still no connection.
I can tell that the hardware can see the WiFi network. I know that the password is correct. My other devices can connect just fine, including the very same hardware loaded with my isolated test sketch.It seems like somehow including the Blynk libraries is conflicting with the way WiFi should function.
Any ideas of the root cause, a workaround, or more steps to take to debug?
Thanks in advance, awesome Blynk community!