So I'm using Arduino Uno and ESP8266-01, and I'm trying to connect WiFi to my ESP.
Below is the code I'm working with.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <SoftwareSerial.h>
#define RX 2
#define TX 3
String AP = "***********"; // SSID
String PASS = "*********"; // Password
String API = "***********"; // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
SoftwareSerial esp8266(RX,TX);
void setup() {
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}
void loop() {
//String getData = "GET /update?api_key="+ API +"&field1="+getTemperatureValue()+"&field2="+getHumidityValue();
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");
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Below is the error message I got.
Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"
C:\Users\wweih\Desktop\New folder (2)\wifi_codes2.0\forum.code\forum.code.ino: In function 'void setup()':
forum.code:20:3: error: 'sendCommand' was not declared in this scope
sendCommand("AT",5,"OK");
^~~~~~~~~~~
C:\Users\wweih\Desktop\New folder (2)\wifi_codes2.0\forum.code\forum.code.ino: In function 'void loop()':
forum.code:28:2: error: 'sendCommand' was not declared in this scope
sendCommand("AT+CIPMUX=1",5,"OK");
^~~~~~~~~~~
forum.code:30:38: error: 'getData' was not declared in this scope
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
^~~~~~~
exit status 1
'sendCommand' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.