I am trying to migrate old code into the new Blynk and now Edgent and so far have organized and compiled the sketch, however, I cannot fathom how this ESP8266 can find it’s way onto the internet without wifi credentials. Reading a recent thread, it was suggested that the OP follow THIS provisioning process to link the running device to the app, however the operation was not successful for me. My phone tried to connect, but for reasons I do not know, it failed. Is there some way that I can add the wifi credentials somewhere in the sketch, or perhaps one of the header files? What other course of action can I take if the automated process does not connect?
Post you sketch please.
If provisioning fails, it’s usually because you’ve chosen a Template name that’s too long.
The Template name has additional hardware specific info added to it to form the SSID that the device uses when communicating with the app during the provisioning process.
If the SSID is longer than the maximum allowed length for the ESP device then provisioning can’t work.
It’s also possible that you’ve used a GPIO that clashes with the BOARD_BUTTON_PIN
assigned in Settings.h, which is causing the board to stay in provisioning mode.
Details of what you see in the serial monitor during the provisioning process would be useful.
Pete.
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLWzp-xxYx"
#define BLYNK_DEVICE_NAME "Relays"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"
WidgetTerminal terminal(V10);
BlynkTimer timer;
#define TURN_ON HIGH // TURN_ON and TURN_OFF are defined to account for Active LOW relays
#define TURN_OFF LOW // Used to switch relay states for on/off of 120VAC~ devices
#define feedPumpState TURN_OFF
#define feedRelay 4 //Digitial Pin
#define ROrelay 5 //Digitial Pin
#define RelayPin3 2 //Digitial Pin
#define RelayPin4 16 //Digitial Pin
//----- Feed Pump time
long previousMillis = 0;
long MINUTE = 60000;
long onTime = MINUTE * 1;
long offTime = MINUTE * 119;
//------ RO pump increment of quarts
boolean runningRO = false;
int msPerQuart = 6000; //ms per Quart
int ROstart; //Start of count
int countQuarts; //Total Quarts from Blynk times msPerQuart
int button; //V0
int ROpumpOn; //V1
int totalQuarts; //V2
int feedPumps; //V3
BLYNK_WRITE(V0) { //Test red LED on ESP8266
button = param.asInt();
}
BLYNK_WRITE(V1) { //triggers the RO countdown
ROpumpOn = param.asInt(); // ROpump remote
}
BLYNK_WRITE(V2) { //number of quarts ordered from app
totalQuarts = param.asInt(); // ROpump remote
}
BLYNK_WRITE(V3) { //button to activate all feed pumps
feedPumps = param.asInt();
}
/*
void feedTime()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > onTime) {
if (feedPumpState == LOW)
feedPumpState = HIGH;
else
feedPumpState = LOW;
digitalWrite(feedRelay, feedPumpState);
}
}
*/
void ROcheck() //RO Pump = 34 seconds on time per gallon
{
if (ROpumpOn == 1 && runningRO == false) // Activates when Blynk button is toggled
{
Serial.println("First IF statement");
digitalWrite(ROrelay, TURN_ON);
runningRO = true;
ROstart = millis();
countQuarts = msPerQuart * totalQuarts; // Calculates length of runtime for pump
terminal.print("Pumping:");
terminal.print(totalQuarts);
terminal.println(" Quarts of RO");
}
if (millis() - ROstart > countQuarts && runningRO == true) // Determines when runtime ends
{
runningRO = false;
countQuarts = 0;
ROstart = 0;
digitalWrite(ROrelay, TURN_OFF);
Blynk.virtualWrite(ROpumpOn, 0);
Blynk.virtualWrite(totalQuarts, 0);
Serial.println("Second IF Statement");
terminal.print("Finished Pumping:");
terminal.print(totalQuarts);
terminal.println(" Quarts of RO");
}
terminal.flush();
}
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
pinMode(feedRelay, OUTPUT);
pinMode(ROrelay, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
digitalWrite(ROrelay, TURN_OFF);
Blynk.virtualWrite(V0, 0); //button
Blynk.virtualWrite(V1, 0); //ROpump
Blynk.virtualWrite(V2, 0); //Number of Quarts
timer.setInterval(1000L, ROcheck);
//timer.setInterval(1000L, feedTime);
}
void loop() {
BlynkEdgent.run();
timer.run();
}
I tried commenting the line that was on D pin 2, but still unable to connect. Here is the Serial print.
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.0.1 on ESP8266
[381] --------------------------
[384] Product: Relays
[386] Firmware: 0.1.0 (build Jan 28 2022 06:35:18)
[390] Token: ...nkpC
[393] Device: ESP8266 @ 80MHz
[395] MAC: EC:FA:BC:05:61:AF
[398] Flash: 4096K
[400] ESP core: 3.0.2
[402] ESP SDK: 2.2.2-dev(38a443e)
[406] Boot Ver: 31
[407] Boot Mode:1
[409] FW info: 469008/1626112, MD5:b9e32223816a421c00a7d9ef97d5570a
[591] Free mem: 30504
[591] --------------------------
[591] INIT => CONNECTING_NET
[593] Connecting to WiFi: Mike
[30603] CONNECTING_NET => ERROR
Is your WiFi network that’s called “Mike” a 2.4GHz or 5GHz network?
Pete.
I believe Mike-N is 2.4 and Mike-AC is 5G. My sketches prior to Edgent connected to the Mike-N and I’ve confirmed data sent and received from app to board.
Edit - oh sorry, I just noticed that the Serial print is not sharing which of the 2 networks it is trying to connect, so in that regard, I suppose Edgent is trying maybe both.
The ESP8266 can only connect to 2.4GHz.
Edgent will only “try” the network that you tell it to during the provisioning process, with the WiFi password that you enter during that process.
Pete.
I am not able to get to the point where I can enter a password. Is there a contingency to enter the wifi credentials into the sketch, or is Edgent entirely reliant on being able to connect on it’s own?
It sounds like it’s already provisioned with incorrect info then.
Press the button connected to the pin defined in Settings.h for 10 seconds to clear the existing credentials and try again.
Pete.
I pressed the reset button on the ESP for 10+ seconds, but that proved unsuccessful as well. Though IDK if the ESP has that button assigned to pin0 as defined in Settings.h and the datasheet doesn’t specify which GPIO the reset is assigned to.
In that case, re-upload the sketch, but choose Tools > Erase Flash > All Flash Contents, then re-provision the board.
If you are using a standard NodeMCU then the button labelled “Flash” should be connected to GPIO0 and the onboard LED connected to GPIO2.
Some NodeMCU’s also have an additional LED connected to GPIO16.
The onboard LED should flash quickly when it’s ready to be provisioned, and pulse slowly when it’s in normal running mode.
Pressing the button should produce a message in the serial monitor that says:
Hold the button for 10 seconds to reset configuration…
continuing to hold the button will produce these messages:
RUNNING => RESET_CONFIG
Resetting configuration!
Configuration stored to flash
RESET_CONFIG => WAIT_CONFIG
and the device will be in provisioning mode again.
If you aren’t seeing this behaviour then you need to look at your Settings.h file and your other code to see if you have pin conflicts.
Pete.
Thank you Pete, the Erase Flash tip did the trick and I was able to provision successfully.