Hi,
I've been using the Arduino Nano version of myFP2 for quite some time now, and I'm now migrating to the ESP32 version.
I had to create some patches to enable some features I needed, firstly I managed to get it running on an ESP32-S2 mini without any issues (I can send a patch if interested, but it involves defining a new custom board with my own pinout, not sure if it's of interest for general audience), but more importantly I added a method for using WiFi multi (allowing an undefined number of stations), plus AP+STA mode (useful if no APs are found).
In short, this will allow to define an indefinite (more or less, memory constraints apply) number of access points the firmware will try to connect to. Additionally, a flag can be set so that the firmware will run its own access point, in case none of the preconfigured access points is available.
CONTROLLERMODE needs to be set to STATIONMODE in controller_config.h
If the custom configuration file is not present, the firmware will work using the regular workflow.
This is the new method I implemented (add before the setup method):
#include <WiFiMulti.h>WiFiMultiwifiMulti;boolwifiMultiSuccessful(){constStringfilename="/wifimulticonfig.jsn";if(filesystemloaded==false)//checkifSPIFFSwasstarted{returnfalse;}Filef=SPIFFS.open(filename,"r");if(!f){DEBUG_println("wifiMulti() file not found");}else{//UsingJSONassistant-https://arduinojson.org/v5/assistant///188*2DynamicJsonDocumentdoc(2000);DeserializationErrorjerror=deserializeJson(doc,f);f.close();if(jerror){DEBUG_println("wifiMulti() deserialise error");DEBUG_println(jerror.c_str());returnfalse;}boolap_sta=doc["ap_sta"]|true;if(ap_sta){WiFi.mode(WIFI_MODE_APSTA);WiFi.softAP(ControllerData->get_devicename().c_str(),doc["ap_sta_psk"]|"");}else{WiFi.mode(WIFI_MODE_STA);}autoaccessPoints=doc["APs"].as<JsonArray>();for(JsonVariantaccessPoint:accessPoints){DEBUG_print("Adding accessPoint: SSID=");DEBUG_print(accessPoint["ssid"].as<String>());DEBUG_print(", psk=");DEBUG_println(accessPoint["psk"].as<String>());wifiMulti.addAP(accessPoint["ssid"],accessPoint["psk"]);}autoresult=wifiMulti.run();DEBUG_print("WiFiMulti success=");DEBUG_println(result==WL_CONNECTED);if(result==WL_CONNECTED){DEBUG_print("Connected to SSID=");DEBUG_println(WiFi.SSID());}returnresult==WL_CONNECTED||ap_sta;}returnfalse;}
In setup(), this line
//------------------------------------------------- // STATIONMODE START // Setup Stationmode, as a station connecting to an existing wifi network //------------------------------------------------- if (myfp2esp32mode == STATIONMODE)
becomes
//------------------------------------------------- // STATIONMODE START // Setup Stationmode, as a station connecting to an existing wifi network //------------------------------------------------- if (myfp2esp32mode == STATIONMODE && ! wifiMultiSuccessful())
Finally, you need to upload a wifimulticonfig.jsn in the data partition, with this format:
{
"ap_sta":true,//TrueforAP+STAmode,falseotherwise"ap_sta_psk":"My AP Password",
"APs":[
{
"ssid":"My First AP",
"psk":"My First AP psk"},
{
"ssid":"My Second AP",
"psk":"My Second AP psk"},
.........
]
}
I've estimated the DynamicJSONDocument size for roughly 10 APs, I guess it could be increased further.
To save memory, it's suggested to compact the configuration json.
Hope it's useful.
Marco
Last edit: Marco Gulino 2022-11-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
// Select EITHER of the following WiFi Config types, READWIFICONFIG or MULTIAP// Or you can leave both commented out// To enable reading SSID and PASSWORD from file wificonfig.json at// boot time, uncomment the following file#defineWIFICONFIGTYPEREADWIFICONFIG// To enable a multi-ap controller, uncomment the following line//#define WIFICONFIGTYPE MULTIAP
is in the next release 306-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
// Select EITHER of the following WiFi Config types, READWIFICONFIG or MULTIAP// Or you can leave both commented out// To enable reading SSID and PASSWORD from file wificonfig.json at// boot time, uncomment the following file#define WIFICONFIGTYPE READWIFICONFIG
// To enable a multi-ap controller, uncomment the following line//#define WIFICONFIGTYPE MULTIAP
Hi Marco
Finally got back to reading this, I do have a question though, why is there a need for multiple AP's or stations? What scenario would make this a requirement?
Regards
Robert
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Well, the first answer that comes to mind is, "why not?" If you can have
this capability, without adding much in term of complexity, I'd say it's
just a bonus.
In my scenario, I have several wifi APs, depending on where the telescope
is (main one indoors for testing, garden repeater, portable repeater if I'm
further back in the garden, or if I'm outdoors, phone hotspot) so it's
convenient to have all of them already preconfigured for all necessities
Hi Marco
Finally got back to reading this, I do have a question though, why is
there a need for multiple AP's or stations? What scenario would make this a
requirement?
Hi,
I've been using the Arduino Nano version of myFP2 for quite some time now, and I'm now migrating to the ESP32 version.
I had to create some patches to enable some features I needed, firstly I managed to get it running on an ESP32-S2 mini without any issues (I can send a patch if interested, but it involves defining a new custom board with my own pinout, not sure if it's of interest for general audience), but more importantly I added a method for using WiFi multi (allowing an undefined number of stations), plus AP+STA mode (useful if no APs are found).
In short, this will allow to define an indefinite (more or less, memory constraints apply) number of access points the firmware will try to connect to. Additionally, a flag can be set so that the firmware will run its own access point, in case none of the preconfigured access points is available.
CONTROLLERMODE needs to be set to STATIONMODE in controller_config.h
If the custom configuration file is not present, the firmware will work using the regular workflow.
This is the new method I implemented (add before the setup method):
In setup(), this line
becomes
Finally, you need to upload a wifimulticonfig.jsn in the data partition, with this format:
I've estimated the DynamicJSONDocument size for roughly 10 APs, I guess it could be increased further.
To save memory, it's suggested to compact the configuration json.
Hope it's useful.
Marco
Last edit: Marco Gulino 2022-11-26
Confirming that support for
is in the next release 306-02
Hi,
That's great, thank you very much!
Kind regards,
Marco
On Mon, 17 Jul 2023 at 14:34, brownrb brownrb@users.sourceforge.net wrote:
Hi Marco
Finally got back to reading this, I do have a question though, why is there a need for multiple AP's or stations? What scenario would make this a requirement?
Regards
Robert
Hi,
Well, the first answer that comes to mind is, "why not?" If you can have
this capability, without adding much in term of complexity, I'd say it's
just a bonus.
In my scenario, I have several wifi APs, depending on where the telescope
is (main one indoors for testing, garden repeater, portable repeater if I'm
further back in the garden, or if I'm outdoors, phone hotspot) so it's
convenient to have all of them already preconfigured for all necessities
Thanks,
Marco
On Fri, 17 Feb 2023 at 10:56, brownrb brownrb@users.sourceforge.net wrote: