4

I'm trying to upload the code from here to work with an ESP8266. So I copy/pasted the code to the Arduino IDE and I get this error:

C:\Program Files (x86)\Arduino\libraries\WiFi\src/WiFi.h:79:9: error: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)' [-fpermissive]

int begin(char* ssid, const char *passphrase); ^

exit status 1 invalid conversion from 'const char*' to 'char*' [-fpermissive]

Can anyone help me with this?

3

This begin() method expects a modifiable character array as its first argument. That's what you should provide:

char ssid[]           = "YOUR_SSID";      // this is changed
const char* password  = "YOUR_PASSWORD";  // this is fine
[...]
WiFi.begin(ssid, password);
4
  • When I try to upload it I get: warning: espcomm_sync failed error: espcomm_open failed. Do you know if it is from the code?
    – Physther
    Jun 21 '17 at 20:04
  • @Physther: I don't know. It's ESP specific and I have no experience with those devices. But see this GitHub issue Jun 21 '17 at 20:18
  • Regarding the espcomm_sync failed error, see github.com/esp8266/Arduino/blob/master/doc/faq/…
    – per1234
    Jun 22 '17 at 0:41
  • It's more likely that the WiFi library is simply unwise in its declaration. There's no real need for the ssid argument to be mutable - the ssid and passphrase are in fact treated identically internally. Nov 4 '17 at 19:25
2

The location where you are calling the function begin, has as first parameter a parameter of type const char* instead of char* ... remove the const from this argument type.

Probably you have something like

const char* s = ....

...

...begin(s, ...)

Change class s to

char* s = ...
2
  • The same question as for Edgar. Can this: warning: espcomm_sync failed error: espcomm_open failed be caused by the code?
    – Physther
    Jun 21 '17 at 20:06
  • It could be ... I have also no experience with them like Edgar Bonet. Trace back where you call the function that fails and check the parameter values (and compare it to examples). Jun 21 '17 at 21:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.