Multiple controllers set as Access Points from WifiManager_nina

Hi,

Please excuse the newbie question.

I am working on a project that will include multiple microcontrollers (either Nano's or Wemos D1's) and have been looking at the OTA and WifiManager_NINA software so that the devices can be updated 'Over The Air' and also reconnect to a Wifi when the underlying wifi has changed, or during initial configuration.

I have managed to get a single test system to work with the initial configuration being done via the Access Point running as a webserver.

When multiple of these boards fire up initially they are all going to have the same AP address (as I don't want to have seperate code for each device to confiqure unique AP addresses). I can get around this within my code by not starting a new access point if it can see a device with the same network name that it is going to use already live (basically CSMA/CA). This should enable me to only have one configurable AP available at a time. I can then login to it and setup the SSID and password of the network it is going to connect to.

As I am inherently lazy I would like to know if it is possible to 'send' this configuration information via code from an Arduino based microcontroller to set the SSID and password that the Access Point would normal get via a browser page. This is for 2 reasons firstly, entering configuration settings manually is prone to error and secondly there could be a large (8) amount of them to do.

I have tried writing the data directly, using the HTTP POST function (code snippet below from google search), but I think that the stummbling block is that the webpage is expecting a 'click' on the submit button to fire the necessary procedure, which I have not been able to find out how to do. If anyone could point me in the correct direction of how to 'simulate' the click on a webpage in code, that would be great.

The other option that I can think of is the 'WIFIManager_NINA' code to have the ability to also receive HTTP post commands (or other instructions) directly (as well as webpage responses), so if you know the correct format of your request it can be written directly. Unfortunately this is beyond my level of knowledge.

I would be greatful for any help, or other suggestions as to how to solve this.

TIA,

Graham.

<code

   private void submitdata()
    {

        var url = "http://192.168.4.1/";

        var encoding = new ASCIIEncoding();
        //var postData = "userid=" + strId;
        //postData += ("&username=" + strName);

        String postData = "id=xxxxxxx&pw=xxxxxxxx";
        byte[] data = encoding.GetBytes(postData);

        var myRequest = (HttpWebRequest)WebRequest.Create(url);
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.ContentLength = data.Length;
        var newStream = myRequest.GetRequestStream();
        newStream.Write(data, 0, data.Length);
        newStream.Close();

        var response = myRequest.GetResponse();
        var responseStream = response.GetResponseStream();
        var responseReader = new StreamReader(responseStream);
        var result = responseReader.ReadToEnd();

        responseReader.Close();
        response.Close();
    }

code>

I add the Chip-ID to the AP-name to give them a unique name.

You could setup a separate unit that connects to any AP with a name that falls within certain specifications, and send the 'form-data' from there.
Best practice regardless is that once a unit has received the information, it stores it in EEPROM, and at startup checks to see if the network is present using a network scan, and logs into that.

This does require a fair bit of coding and testing to get this to work properly.

It is possible to communicate through Serial and transfer the information that way as well of course, and then store it in EEPROM after.
Doing it wireless seems like a better solution though.

If you start out with a netscan and get a list of ssid's to chose from, then all is required is to add the password. If you change the form to a 'GET' request, you can just bookmark the request and submit it like that after connecting to any unit.
8 is not a large amount.

Hi @Deva_Rishi, thanks for the reply.

I had not thought about adding the ChipID to the AP name to make it unique. Thanks :slight_smile:

'You could setup a separate unit that connects to any AP with a name that falls within certain specifications, and send the 'form-data' from there.' I was coming to the conclusion that a separate board for connecting to the AP units would be best. Excuse my ignorance, but how do I send the 'form data'. I have been struggling with how to simulate the 'click' on button on the WIFIManager webserver page.

Thanks,
Graham.

Oh i never use the wifimanager, since it doesn't really allow for true dual mode (AP & STA) to access the server, and i prefer my own GUI of course.
hmm let me have a look.
OK, the basic procedure to find out has 2 options.

  • You can dig through the library and see if you can find the code responsible.
  • You can load the page and use the browsers 'development tools' to find what is actually in the form that is submitted, and that is what i did.

For the form that is submitted when you click 'save' i think it is named 'wifisave' and uses 'POST' method
the name for the ssid parameter is simply 's' a nd for the password simply 'p' , so doing something like 192.168.4.1/wifisave/?s=network&p=password as a POST request should do the trick. May even work as a 'GET' request, that depends on the code.