I need a pretty simple example of tzapu wifimanager

Hi all…!!!

I’m almost done with my project using Blynk… I love it… Is amazing…!!!

I want to take a step forward now, add tzapu wifimanager to avoid ssid, pass and token hardcoded.

Where I can find a template or terrible simple example how to implement wifimanager ???

I’m working with a NodeMCU if that info is needed.

Thanks…!
Javier.

I have never used it myself, but I recommend you start by searching this forum for all the other references to that code…

https://community.blynk.cc/search?q=tzapu%20wifimanager

I believe that Blynk as made it’s own method called WiFi provisioning… again another thing I haven’t ever needed to learn much about :blush: but you might want to search for it as well

1 Like

https://github.com/tzapu/WiFiManager, as simple as it can be.

3 Likes

Thanks Zodiac…!

But I can’t see the Blynk usage in that example… and how to input the token there…?

Maybe I still have “concept” gaps about the whole Blynk environment… I’m almost sure of that…

In a different topic, for example, I’m not clear about how to publish, if I need a different token for each device, and so on… I have many “holes” in the Blynk idea…

Maybe I’m still in the RTFM stage… :wink:

P.S.: I’m surprised I can’t find a simple “.ino” with ONLY the connection logic, with Wifimanager and Blynk…

I used the Autoconnect example code. Just put Blynk.config(Auth); Directly after WiFi.autoConnect line in setup. Then Blynk.run() in main loop like normal.

1 Like

Thanks Amorphous…!

I will follow that advice too…

What about asking the token in wifimanager ? or there is another way ?

I need a token for each device, right ?

Great, Gunner… just read your answer (missed it before)… :smiley:

I will search fot that…!!!

You should not expect out of the box solution without reading or learning anything, at least not here. I’m using tzapu’s wifi manager combined with other code and Blynk, and I got it on Github, at the same address from link I have posted. There’s a lot of examples for various scenarios so use them, it’s simple. If you don’t know how to use examples and you don’t want to learn, then wifi manager is not for you.

1 Like

hahahaha… I know, I know… just looking for a “clean” example… :smiley:

There are many commands and combinations and looking to basic examples helps to the learning curve.

I have many years in IT (I’m an antiquity, +38 years in the business, and still kicking), designing big systems and programming in a lot of languages… but I’m a rookie in the arduino and apps world… :stuck_out_tongue:

Thanks again for pointing me to the right direction…!!! :muscle::+1:

This is an active and helpful community…!!!

I believe there is a way of inputting the Auth code in wifi manager. I haven’t tried that method yet so I couldn’t comment.

1 Like

Would you believe if I told you that there is wifi manager Blynk optimized code posted in this community?

2 Likes

yeah… I saw some screenshoots, but still can’t find a simple example… :frowning:

Sure… i can believe that… but can’t find it… :roll_eyes:

I was seeking the suggestet by @Gunner , the “WiFi provisioning” by Blynk in the MyPlant example… looks “promising” for my quest… :smiley:

Still at work, I wiil take a deeper look later…!

I like others, have spent hours looking for it, but find results of sketches with other complex stuff in them and I don’t know what parts I need and what parts I don’t need. If such exists, could someone please point me to a simple example that:
has wifimanager auto connect feature, and also gets the Blink Auth code? Thanks so much.

I know for a fact it is out there. I posted it.

1 Like

Hi. Thanks so much!!! At first it didn’t work, but I uncommented the two lines
//wifiManager.resetSettings();
//SPIFFS.format();
And ran that sketch once and then commented them out again, and it worked! wifi manger worked, and also my blynk auth code, and blynk connected!
thanks again.
This seems like such an important thing, it should be somewhere on the headings page.
Cheers

Oh NO! All of a sudden my Wemos D1 Pro Mini stopped working. I was adding in some lines in my code to save settings to EEPROM, I added lines like this:
void factoryReset() {
Serial.println(F(“Resetting EEPROM to factory settings”));
s.aggKp = 8;
s.aggKi = 0.2;
s.aggKd = 1;
s.consKp = 2;
s.consKi = 0.1;
s.consKd = .5;
EEPROM.put(0, s);
}

And I noticed it wasn’t saving the values when I powered down the unit, so I searched a little more and found this command in setup()
EEPROM.begin(512);
(I’ve never had to use that with an UNO)
but right after this change, my wemos ESP8266 quit working. So I went back and tried this basic wifimanager sketch, and it doesn’t work either. But it was working. I turned my router off, and after a bit the Wemos would go into access point mode and I could put in my ssid, etc. But now this very code that worked won’t work anymore. :frowning:
I tried uncommenting the lines
//wifiManager.resetSettings();
//SPIFFS.format();
and under the Arduino IDE /Tools/Erase Flash/ I’ve chosen just the sketch, sketch and wifi, and erase all. Nothing seems to make it work again. So I tried rebooting my Mac, and loading it on the 2nd Wemos I have, and now it won’t connect either. !
Is there something simple I’m missing?

I’m using Arduino 1.8.5, and all the libraries in the manager are updated.
this is my code that used to work.
and this is as far as the Serial monitor goes:
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

#include <FS.h>                   //this needs to be first, or it all crashes and burns...
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <SimpleTimer.h>
#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson


#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
char blynk_token[34] = "YOUR_BLYNK_TOKEN";
//flag for saving data
bool shouldSaveConfig = false;

//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

void setup() {
  Serial.begin(115200);
  Serial.println();

  //clean FS, for testing
  SPIFFS.format();

  //read configuration from FS json
  Serial.println("mounting FS...");

  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");
          strcpy(blynk_token, json["blynk_token"]);
        } else {
          Serial.println("failed to load json config");
        }
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
  //end read

  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 33);

  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //add all your parameters here
  wifiManager.addParameter(&custom_blynk_token);

  //reset settings - for testing
  wifiManager.resetSettings();

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("autoconnect")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");

  //read updated parameters
  strcpy(blynk_token, custom_blynk_token.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["blynk_token"] = blynk_token;
    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }
    json.printTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

  //Serial.println("local ip");
  //Serial.println(WiFi.localIP());

  Blynk.config(blynk_token);
  bool result = Blynk.connect();

  if (result != true)
  {
    Serial.println("BLYNK Connection Fail");
    Serial.println(blynk_token);
    wifiManager.resetSettings();
    ESP.reset();
    delay (5000);
  }
  else
  {
    Serial.println("BLYNK Connected");
  }
}

void loop() {

  Blynk.run();

}
1 Like

I just loaded the sketch to the same type of board, and it works as it should.