The WiFi.softAP class appears to need a cont char - how can I feed it one?
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0);
Background and code:
Platform is ESP8266 currently, possibly going to an ESP-WROOM-32
What I want to do.... On device start up:
look at a hex rotary switch (0-f) on four input pins
convert the encoder input to a character
append that character to a default name for the access point
start the access point
serve an HTML page no matter the domain requested
I have been able to get the serving of pages going, with a static AP name: WiFi.softAP("ThisisaStaticName"); The access point SSID appears as expected.
When I try to pass a string that is modified, anything I get to compile only shows the first character of the AP name I want. I have a feeling that there will need to be pointers and referencing/dereferencing done - but I do not have a good handle on the matter.
I have had an error "error: invalid conversion from 'const char*' to 'char' [-fpermissive]" on the WiFi.softAP() line before.
// WiFi libraries
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
const byte DNS_PORT = 53;
IPAddress apIP(192,168,10,1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);
String responseHTML = ""
"<!DOCTYPE html><html><body><p>Some text</p></body></html>";
void setup() {
Wire.begin();
/*Look at address lines, use the 4 to create a letter to
* append to the SSID of the access point (0-F)*/
volatile char UnitAddr;
UnitAddr = 'a'; // ' denotes a char - single character variable like 'C' or '
.
// " denotes a String - a string of characters.
String APname = "ThisIsADynamicName" + UnitAddr;
The const declaration is the function's guarantee to you that it won't change the value that you pass it. You can pass it a non-const array.
Post the EXACT error message. The message you posted implies that softAP() expects a character, not a string. That does not seem to be the case based on the fact that you can send the function a static (also const) string.
Thanks for clarification on the const char* - it did seem rather odd that we wouldn't be allowed to modify the AP name in our code (By requiring a constant to be fed to the function)
I don't have hardware in front of me, so can't test the code right now. Does "Note 3" code look like it will do what I want to do?
void setup() {
char UnitAddr; /* This variable will be written to based on the values seen
* from the rotary switch. 0b0000 -> 0b1111 = '0' -> 'f' */
UnitAddr = 'a'; // ' denotes a char - single character variable like 'C' or '
.
// " denotes a String - a string of characters.
String APname = "accesspoint" + UnitAddr;
/* NOTE 3: Untested on hardware - but does compile when not commented out
char ssid[13] = "accesspoint_";
APname.toCharArray(ssid,12);
*/
Of course, if you ARE going to use Strings, you can pass the data wrapped by the String instance (using the c_str() method) to the softAP() method. Exactly what the cast needs to look like depends on the EXACT error message that the original code generated.
Arduino documentation was not getting me anywhere near this. The code above became a case of throwing stuff at the wall to see what sticks. Just trying to figure out the gaps in the documentation.
To help others out looking at this thread with a similar issue .... this behaves how I want it to.
/*Look at address lines, use the 4 to create a letter to
* append to the SSID of the access point (0-F)*/
byte UnitAddr;
UnitAddr = 0b00001111;
/* sprintf http://www.cplusplus.com/reference/cstdio/sprintf/
* Formatting (%X) http://www.cplusplus.com/reference/cstdio/printf/
* char array (APname) must be at least ONE larger than the assigned string to allow
* for NULL termination
* %X is replaced by contents of UnitAddr, with the X denoting the format
* X = Unsigned hexadecimal integer (uppercase)*/
char APname[11];
sprintf(APname, "MyAccess_%X", UnitAddr);
/* Start the AP with appended SSID
* http://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-class.html#set-up-network */
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(APname);