How do I declare for "sendCommand" and "getData"

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.

@smackytacky Why do users choose to ignore the advice on posting code ?

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

If you get errors when compiling please copy them from the IDE using the "Copy error messages" button and paste the clipboard here in code tags

Thanks for the advice. Now I have edited my post with code tags, please help.

Thanks for adding code tags. I hope that you can see how much easier to deal with it makes the code and errors

As to the errors, as you have correctly identified, you need to add sendCommand() and getData() functions to the sketch

Where exactly are you aiming to send commands to and get data from ?
What format is the data required in ?
Where did you get the code ?

I note that you are compiling for a Uno but that the sketch has many references to esp8266, so what exactly are you trying to do ?

@smackytacky, your topic has been moved to a more suitable location on the forum.

I found a "sendCommand()" function in an example. You could add it to your sketch.

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;
}

How about using the Arduino-IDE and a ESP32 nodeMCU as a replacement for the
Arduino-ESP8266-01 combination?

An ESP32 can be programmed with the arduino-IDE and do all the things the arduino-UNO and the ESP8266 can do and even more

  • More memory
  • more speed
  • more AD-IO-pins
  • more interrupts
    best regards Stefan

Does that solve OP's problem?

unclear because the OP does not describe what he wants to do in the end.
connecting to WiFi is not a self-purpose.
best regards Stefan

sorry, I'm new to this so please bear with me. So what you mean is I need to write down the whole code with the purpose, then I can test if the ESP can connect to my wifi?

sadly I can't as the project I'm doing need to use ESP8266-01

No. You should describe in normal words what your project is doing.
What can a person that is just watching your microcontroller see?

Does your microcontroller make some LEDs blink????
do you measure a temperature and want to display the temperaturevalue on a website???

OK. If you are forced to use an ESP8266 there is another way of connecting to a WiFi-network
If this other method makes more sense than using AT-commands highly depends on your project.

If you need even more explanation

best regards Stefan

So for my project I'm trying to send a message to the web every time the led is switched on by a PIR sensor.

I'm tyred of repeating the same lines of text again and again
read here

For my project, I'm using Arduino UNO, ESP8266-01, PIR sensor, and a LED.

The main objective is to send a signal to ThingSpeak every time the LED lights up, through ESP8266-01.

Is this format better or am I still doing it wrong? or is there something I'm missing out on?

You could have described some more details but it is OK.
the ESP8266 even an ESP8266-01 can be programmed with the Arduino-IDE directly.

When you buy it it has a firmware on it that uses these AT-commands.
Then everything has to be done with AT-commands.
For any other ESP8266-module except an ESP8266-01 it is much much more comfortable to write an arduino-like sketch for the ESP8266 itself.

It is doable for ESP8266-01 too but a bit unconveniant because the upload needs manual switching of a certain contact.
With an ESP8266-node-MCU like this
https://de.aliexpress.com/item/33051171807.html?albpd=de33051171807&acnt=494-037-6276&aff_platform=aaf&albpg=743612850714&netw=u&albcp=1705854617&sk=UneMJZVf&trgt=743612850714&terminal_id=51a0a3b8cf3548219a11d9f041211ace&tmLog=new_Detail&needSmbHouyi=false&albbt=Google_7_shopping&src=google&crea=de33051171807&aff_fcid=305db7b0f3f84cdd90abeed42696f17d-1624017709038-02485-UneMJZVf&gclid=CjwKCAjwiLGGBhAqEiwAgq3q_uJj6hM1TZCS93jNzX5K0q4L2UbQS1jQNrNpZiXdBCxdAajr_ISyGBoCX_IQAvD_BwE&albag=67310370915&aff_fsk=UneMJZVf&albch=shopping&albagn=888888&isSmbAutoCall=false&aff_trace_key=305db7b0f3f84cdd90abeed42696f17d-1624017709038-02485-UneMJZVf&device=c&gclsrc=aw.ds

The upload works exact the same way as for the Arduino-Uno.
that is why I'm avertising re-programming the ESP8266 with a arduino-sketch that replaces the AT-firmware

If you want it is possible to re-program the AT-firmware with a flash-tool-software but I have no exeprience with it.
With the Arduino-sektch you can program your own small protocol to send a datapacket over a serial connection to make the ESP8266 send data to thing-speak.

Random Nerd Tutorials has a lot of examples including sending data to things-speak based on ESP8266 that runs a arduino-skecth instead of the AT-firmware

best regards Stefan