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>