I have been reading several documentation and I got lost on how to connect the esp2866 esp-01 wifi module.
I was under the impression that I could use the following API ESP8266WiFi library — ESP8266 Arduino Core 2.7.2-10-g2843a5ac documentation in my arduino code and call it in my Arduino program.
#include <ESP8266WiFi.h>
const char* ssid = "my-ssid";
const char* password = "my-password";
void setup() {
Serial.begin(115200);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
If I set my Board -> Arduino Uno, I am getting this error
exit status 1
ESP8266WiFi.h: No such file or directory
Does it mean that the only way to connect thru the internet thru the ESP2866 is thru the use of the AT command and sending it like this in Arduino?
void loop() {
valSensor = getSensorData();
String getData = "GET /update?api_key="+ API +"&"+ field +"="+String(valSensor);
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
}
int getSensorData(){
return random(1000); // Replace with
}
void sendCommand(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
I was under the impression that I can call the esp2866 library in my arduino code.
Is my understanding correct or am I missing something?