Error message: invalid conversion from 'int' to 'char*' [-fpermissive]

Hi,

I’m new to arduino programming, and I’m not sure what I’ve done wrong here.

This is my code (I’ve made the error line bold):

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <WiFi.h>

char ssid = “SKY195DA”; // your network SSID (name)
char key = “WRCWYBBY”; // your network key
int keyIndex = 0; // your network key Index number
int status = WL_IDLE_STATUS; // the Wifi radio’s status

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(“WiFi shield not present”);
// don’t continue:
while (true);
}

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WEP network, SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid,keyIndex,key);

// wait 10 seconds for connection:
delay(10000);

}
}

void loop()
{
// put your main code here, to run repeatedly:
// check the network status connection once every 10 seconds:
delay(10000);
Serial.println(WiFi.status());
}

Full error message:

Arduino: 1.8.4 (Mac OS X), Board: “Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck, Disabled, None”

/Users/Adi/Documents/Arduino/sketch_sep25b/sketch_sep25b.ino: In function ‘void setup()’:
sketch_sep25b:28: error: invalid conversion from ‘int’ to ‘char*’ [-fpermissive]
status = WiFi.begin(ssid,keyIndex,key);
^
In file included from /Users/Adi/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/ESP8266WiFi.h:34:0,
from /Users/Adi/Documents/Arduino/sketch_sep25b/sketch_sep25b.ino:1:
/Users/Adi/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h:39:21: error: initializing argument 2 of ‘wl_status_t ESP8266WiFiSTAClass::begin(char*, char*, int32_t, const uint8_t*, bool)’ [-fpermissive]
wl_status_t begin(char* ssid, char passphrase = NULL, int32_t channel = 0, const uint8_t bssid = NULL, bool connect = true);

^
sketch_sep25b:28: error: invalid conversion from ‘char*’ to ‘int32_t {aka int}’ [-fpermissive]
status = WiFi.begin(ssid,keyIndex,key);
^
In file included from /Users/Adi/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/ESP8266WiFi.h:34:0,
from /Users/Adi/Documents/Arduino/sketch_sep25b/sketch_sep25b.ino:1:
/Users/Adi/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h:39:21: error: initializing argument 3 of ‘wl_status_t ESP8266WiFiSTAClass::begin(char*, char*, int32_t, const uint8_t*, bool)’ [-fpermissive]
wl_status_t begin(char* ssid, char passphrase = NULL, int32_t channel = 0, const uint8_t bssid = NULL, bool connect = true);

^
exit status 1
invalid conversion from ‘int’ to ‘char*’ [-fpermissive]

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Help please!

ESP8266WiFiSTA.h:39:21: error:   initializing argument 2 of 'wl_status_t ESP8266WiFiSTAClass::begin(char*, char*, int32_t, const uint8_t*, bool)' [-fpermissive]
         wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);

The second argument is a char array/char pointer. Why are you supplying in int?

@Paul - I actually think the confusion comes from

[color=red]#include <ESP8266WiFi.h>[/color]
#include <SPI.h>
[color=red]#include <WiFi.h>[/color]

if you read the standard WiFi Arduino library:

Syntax

WiFi.begin();
WiFi.begin(ssid);
WiFi.begin(ssid, pass);
WiFi.begin(ssid, keyIndex, key);
Parameters

ssid: the SSID (Service Set Identifier) is the name of the WiFi network you want to connect to.

keyIndex: WEP encrypted networks can hold up to 4 different keys. This identifies which key you are going to use.

key: a hexadecimal string used as a security code for WEP encrypted networks.

pass: WPA encrypted networks use a password in the form of a string for security.

so his version is OK if he were on a standard basic Arduino.

but the compilation error shows he is targeting a Generic ESP8266 Module and unfortunately the begin() function from ESP8266WiFi.h is not the same…

it supports 3 variation

wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
wl_status_t begin();

and I suspect (error is flagging begin(char*, char*, int32_t, const uint8_t*, bool)) that the compiler has decided to match the OP’s call with the second one’s signature


@Adzzix

Long story short, don’t use both WiFi.h and ESP8266WiFi.h, keep the latter → you have an ESP hardware so just stick to that library and read documentation or the source code to understand the capabilities.

@J-M-L

Thank you so much, the code now works.

Great!