Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there any way to Integrate beginSmartConfig with this library? #429

Open
bkrajendra opened this issue Sep 25, 2017 · 21 comments
Open

is there any way to Integrate beginSmartConfig with this library? #429

bkrajendra opened this issue Sep 25, 2017 · 21 comments
Labels
Branch This applies to a branch enhancement Feature Request
Milestone

Comments

@bkrajendra
Copy link

is there any way to Integrate beginSmartConfig with this library?

@tablatronix
Copy link
Collaborator

Can you link to some reference for me?

@bkrajendra
Copy link
Author

Sorry for incomplete info.
Expressif has something called ESPtouch for ESP8266 and ESP32

http://espressif.com/en/products/software/esp-touch/overview

Its very easy to configure ESP8266 or ESP32 through it.

WiFi.mode(WIFI_AP_STA);
  delay(500);
  WiFi.beginSmartConfig();
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    Serial.println(WiFi.smartConfigDone());
  }
  Serial.println("WiFi connected");  
  Serial.println(WiFi.localIP());

There is simple Android Java Library provided by expressif which is very easy to use from Android App or cordova library. With this there is no need of WiFi Manager as such, But as it has its limitation we can keep both WiFi manager captive portal and SmartConfig side by side.

It should be made available on press of some button or on some event.
If it fails we can go for captive portal.

I've modified WiFimanager code for it but it does not looks like standard solution.
Its better if its implemented by someone who already known WiFiManager better.

@tablatronix
Copy link
Collaborator

Yeah ok this is the thing that sniffs data and pairs the ap using that credential, I do not have android to test this. Does it work well, i thought it was flaky.

@bkrajendra
Copy link
Author

Works Excellent.
Its working fine for me. I tested it on ESP8266 and ESP32. Even tested it with multiple devices to send SmartConfig packets at a time.... it works.

Looks ok. People are talking about its issue with not compatible with 5GHz wifi channel.
But its good to have it as option 1 and if does not work we can go for captive portal.

@tablatronix
Copy link
Collaborator

Ahh I see ill look at the examples

@bkrajendra
Copy link
Author

I've created this cordova plugin.
Locally i've tested it working fine. Git version not tested yet.

https://github.com/IOCare/cordova-plugin-smartconfig

@tablatronix
Copy link
Collaborator

tablatronix commented Sep 27, 2017

There seems to be a few espressif IOS apps , but they do not appear to work.

And my esp keeps throwing exceptions running this

@bkrajendra
Copy link
Author

bkrajendra commented Sep 28, 2017

Try this. Actually its just single line but i tried to make it more useful for me.
Change include header file for ESP8266 wifi.

#include "WiFi.h"
unsigned long _connectTimeout         = 0;
boolean       _tryWPS                 = false;

void setup() {
  Serial.begin(115200);
  //Init WiFi as Station, start SmartConfig
  WiFi.mode(WIFI_AP_STA);
  if (connectWifi("", "") == WL_CONNECTED)   {
    Serial.println("IP Address:");
    Serial.println(WiFi.localIP());
    //connected
  }
}

void loop() {
}

int connectWifi(String ssid, String pass) {
  Serial.println("Connecting as wifi client...");

  //fix for auto connect racing issue
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("Already connected. Bailing out.");
    return WL_CONNECTED;
  }
  //check if we have ssid and pass and force those, if not, try with last saved values
  if (ssid != "") {
    WiFi.begin(ssid.c_str(), pass.c_str());
  } else {
    if (WiFi.SSID()) {
      Serial.println("Using last saved values, should be faster");
      //trying to fix connection in progress hanging
      //ETS_UART_INTR_DISABLE();
      //wifi_station_disconnect();
      //ETS_UART_INTR_ENABLE();

      WiFi.begin();
    } else {
      Serial.println("No saved credentials");
      //Added Smart config by ioCare
      WiFi.beginSmartConfig();
      //Wait for SmartConfig packet from mobile
      Serial.println("Waiting for SmartConfig.");
      while (!WiFi.smartConfigDone()) {
        delay(500);
        Serial.print(".");
      }
      //Wait for WiFi to connect to AP
      Serial.println("Waiting for WiFi");
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }

      Serial.println("WiFi Connected.");

      Serial.print("IP Address: ");
      Serial.println(WiFi.localIP());

    }
  }

  int connRes = waitForConnectResult();
  Serial.println ("Connection result: ");
  Serial.println ( connRes );
  //not connected, WPS enabled, no pass - first attempt
  if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
    //startWPS();
    //should be connected at the end of WPS
    connRes = waitForConnectResult();
  }
  return connRes;
}

uint8_t waitForConnectResult() {
  if (_connectTimeout == 0) {
    return WiFi.waitForConnectResult();
  } else {
    Serial.println("Waiting for connection result with time out");
    unsigned long start = millis();
    boolean keepConnecting = true;
    uint8_t status;
    while (keepConnecting) {
      status = WiFi.status();
      if (millis() > start + _connectTimeout) {
        keepConnecting = false;
        Serial.println("Connection timed out");
      }
      if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) {
        keepConnecting = false;
      }
      delay(100);
    }
    return status;
  }
}

@tablatronix
Copy link
Collaborator

tablatronix commented Sep 28, 2017

if (WiFi.SSID()) {
is wrong
WiFi.SSID() != NULL should work for empty config or erased config

Also you must enter STA mode before starting smart config
WiFi.mode(WIFI_STA);

Those changes should fix that sketch

But i still get wdt resets everytime after it runs for a bit

@tablatronix tablatronix added the enhancement Feature Request label Sep 28, 2017
@tablatronix tablatronix added this to the future milestone Sep 28, 2017
@tablatronix
Copy link
Collaborator

Does anyone know how airkiss works, specifically with wechat? I thought a simple ap qrcode would work , but it must require something special.

@bkrajendra
Copy link
Author

Yes ! you are right it should be WiFi.mode(WIFI_STA);.
Thanks for suggestion (WiFi.SSID() != NULL) .. I'll include it in my code.
Its sad that you are getting error. I'm using ESP-12F - 4MB flash module.
But still it should work as its not hardware dependant. Might be you should check which SDK you are using as it only support latest SDK. Try getting latest from https://github.com/esp8266/Arduino

@tablatronix
Copy link
Collaborator

Its not me,
esp8266/Arduino#3494

@tablatronix
Copy link
Collaborator

Ok i tried this at home and it works, it must be only suitable for soho networks, or it just takes a really long time and the app times out or the esp crashes before it can work in environments with lots of APs, I have over 30 in my testing location,

@bkrajendra
Copy link
Author

I don't know how airkiss works. But it looks like esp has it already as there is a lib file in SDK called libairkiss.a. Or might be smartconfig is using similar library.

@tablatronix
Copy link
Collaborator

tablatronix commented Sep 29, 2017

I think it is essentially the same thing, but airkiss is built into wechat, but the docs are only in chinese, and i have no idea how you initialize the pairing ( using wechat that is )

@tablatronix
Copy link
Collaborator

Do you have any ideas how wm would incorporate this ?
Since it only runs in STA mode, it cannot work along side WM, so not sure how this could even be beneficial unless adding the code and letting user switch it on, but then why even include it at all

@tablatronix tablatronix added the Branch This applies to a branch label Feb 8, 2018
@tablatronix tablatronix added ESP32 Esp 32 related issue and removed ESP32 Esp 32 related issue labels Mar 14, 2018
@dneykov
Copy link

dneykov commented Nov 9, 2019

Hello,

Any news on this? Is it possible to use smart config with WiFiManager? I would like to use it in order to configure my ESP8266 using iOS with ESP-Touch protocol.

Thanks.

@tablatronix
Copy link
Collaborator

I can look at it again, but I don't see a reason to incorporate it, when you can just do it in code as it cannot work with wm ap mode..

@bkrajendra
Copy link
Author

Actually wm and SmartConfig are little different ideas.
While wm gives you complete config portal to configure your device through ap - just like a router, smartconfig provides different approach for device configuration - something like zeroconfig, where you dont need any config portal on device.

There is one big advantage with using wm, which makes it possible to save additional parameters by providing a config portal.

The major challenge with wifi provisioning and device config is the tedious process which makes it difficult for end user to use the device during first time config.

What everyone wants is easy, smooth and one click process to setup wifi on device.
Using SmartConfig does address this issue by some extent, but does not work with all networks.
wm is good but makes it difficult and adds multiple steps for device configuration for end user.

We can some how combine these two advantages together by providing some settings to enable smartconfig at startup, if successful then just bypass wm config if not then enter into wm autoconfig mode. also to add some on-demand way to to start smartconfig again.

Also I'm always in favor of rest api for mobile companion app interface, I understand this is off-topic, but thats all what it comes down eventually for any commercial product.

@tablatronix
Copy link
Collaborator

tablatronix commented Nov 10, 2019

I have not found a decent smartconfig app, has the esp one been improved ? This is why I wanted to get airkiss working, its built into wechat, just not standardized outside of china, and has sparse docs.

@bkrajendra
Copy link
Author

If you work with cordova, I have this small example app.
You need to have all requirements for cordova done before following steps.
Check this out:
https://www.iocare.in/smartconfig

this will create a complete app with smartconfig functionality.

screenshot-1573408192526

Load ESP with example smartconfig sketch.
In app scan your all wifi APs.
Select your local AP from drop down.
Enter password for it.
Click start config to configure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Branch This applies to a branch enhancement Feature Request
Projects
None yet
Development

No branches or pull requests

3 participants