Im using NodeMCU 0.9(ESP8266), and will connected to MIT app inventor. But i always failed to upload because there is an error that says: "Compilation error: 'const char OK []' redeclared as different kind of entity"
this is the code:
#include <ESP8266WiFi.h>
const char WiFiPassword[] = "secret";
const char AP_NameChar[] = "secret" ;
WiFiServer server(80);
String request = "";
#define Kipas 5
void setup()
{
Serial.begin(115200);
pinMode(Kipas, OUTPUT);
WiFi.disconnect();
boolean conn = WiFi.softAP(AP_NameChar, WiFiPassword);
server.begin();
}
void loop()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Read the first line of the request
request = client.readStringUntil('\r');
if ( request.indexOf("OnKipas") > 0 ) {
digitalWrite(Kipas, LOW);
//client.flush();
client.println("HTTP/1.1 200 OK\r\n");
client.println( "OnKipas");
client.flush();
Serial.println("inside ON");
}
else if ( request.indexOf("OffKipas") > 0 ) {
digitalWrite(Kipas, HIGH);
//client.flush();
client.println("HTTP/1.1 200 OK\r\n");
client.println( "OffKipas");
client.flush();
Serial.println("inside OFF");
}
}
I've already tryng to modify it but the result still the same
someone please help me quickly
I moved your topic to an appropriate forum category @thariqzayn.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
Are you using Arduino IDE or something else, like Platform.IO?
Which board definition are you using?
I've compiled in Arduino IDE 2.3.2 your code for board "NodeMCU0.9 (ESP12)" from this set of board definitions:
The only two places where the chracters "OK" occur in the code that you posted are these two lines:
client.println("HTTP/1.1 200 OK\r\n");
and
client.println("HTTP/1.1 200 OK\r\n");
but in these lines the letters "OK" are part of a string.
Your error-message is related to a variable with name "OK".
So my assumption is that the code that you have compiled is a different code than the code you have posted.
It might be that this error has to do with some include-files.
To narrow down if this is the case you have to post the full and verbose compiler-log. This requires to adjust the arduino-IDE to verbose output like described in this tutorial
and then post the complete compiler-log as a code-section
If the compiler-log exceeds 120000 characters - which can happen when compiling for ESP32's then attach the complete compiler-log as a textfile
You know what they say about assumptions. They tend to produce ugly offspring.
Or, rather, how the #includes are handled by the compiler.
The error isn't unheard of; if you search a bit, you'll find it being mentioned elsewhere once or twice, too. I didn't spot a solution being associated with it.
I don't think it's related to the code that's posted above, but that it's rather related to board definitions.
Yes, the cause of the error seems to be a redefinitions of common-used flags OK, FAIL etc... as strings in ekstrand/ESP8266wifi/ library :
A solution might be to add a namespace around the code, but I'm not sure if this won't throw other errors.
It’s easier not to use such libraries at all.