How to make this code wireless?

Hey, I am very new to Arduino and programming, I'm making a so-called pocket weather station that transmits the data wirelessly to Thingspeak via ESP8266 Module on an Uno board, the code for the data to transmit to the Thingspeak is only working if the Arduin are connected to my computer, is there any other way to make it truly wireless? because i am very amateur and just kit bashing the program code from various sources. Thanks in advance!

here is my code :

#include <stdlib.h>
#include <SoftwareSerial.h>
#include <SPI.h>               //include Serial Peripheral Interface library
#include <Wire.h>              //include Two Wire Interface library
#include <Adafruit_GFX.h>      // include Adafruit graphics library
#include <Adafruit_ST7735.h>   // include Adafruit ST7735 TFT library
#include <Adafruit_BMP280.h>   // include Adafruit BMP280 sensor library
#include "DHT.h"               //include DHTXX sensor library
#define DHTPIN 4               //DHT11 data pin connected to arduino pin D2
#define DHTTYPE DHT11          //specifying the type of DHT sensor used
#define TFT_RST   8            // TFT RST pin is connected to arduino pin D8
#define TFT_CS    10           // TFT CS  pin is connected to arduino pin D9
#define TFT_DC    9            // TFT DC  pin is connected to arduino pin D10
#define SSID "------";
#define PASS "---------";
#define IP "184.106.153.149" // thingspeak.com IP
SoftwareSerial monitor(2, 3); //Serial communication to ESP8266 module (RX, TX)
String GET = "GET /update?key=&field1="; //replace ZZZZZ by your ThingSpeak channel write key


// initialize ST7735 SERIES TFT library
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

// define device I2C address: 0x76 or 0x77 (0x77 is the library default address)
#define BMP280_I2C_ADDRESS  0x76

Adafruit_BMP280  bmp280;       // initialize Adafruit BMP280 library
DHT dht(DHTPIN, DHTTYPE);      // initialize DHT sensor
unsigned long starttime;
unsigned long sampletime_ms = 10000;
unsigned long delay_time = 60000;

void setup(void)
{
  //start serial communications
  Serial.begin(9600);
  monitor.begin(9600);
  Serial.println("Initializing...");

  //communication with wifi module
  monitor.flush();
  monitor.println("AT");
  delay(2000);

  if (monitor.find("OK")) {
    Serial.println("Communication with ESP8266 module: OK");
  }
  else {
    Serial.println("ESP8266 module ERROR");
  }
  //connect wifi router
  
  
  Serial.print("Sampling (");
  Serial.print(sampletime_ms / 1000);
  Serial.println("s)...");

  //initialize timer
  starttime = millis();

  dht.begin();                                         // synchronizing DHT sensor
  tft.initR(INITR_BLACKTAB);                        // initialize a ST7735S chip, black tab
  tft.fillScreen(ST77XX_BLACK);                        // setting black background
  tft.drawFastHLine(0, 15 ,  tft.width(), ST77XX_CYAN);// draw horizontal seperation line at position (0, 15)

  tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);         // set text color to white and black background
  tft.setTextSize(1.5);                                  // setting text size to 1
  //tft.setCursor(4, 0);                               // move cursor to position (4, 0) pixel
  //tft.print("ARDUINO + ST7735 TFT");
  tft.setCursor(30, 5);                                // move cursor to position (25, 5) pixel
  tft.print("P.A.R.A MK.3");

  // initialize the BMP280 sensor
  if ( bmp280.begin(BMP280_I2C_ADDRESS) == 0 )
  { // connection error or device address wrong!
    tft.setTextColor(ST77XX_RED, ST77XX_CYAN);         // set text color to red and black background
    tft.setTextSize(2);                                // setting text size to 2
    tft.setCursor(5, 76);                              // move cursor to position (5, 76) pixel
    tft.print("Connection");
    tft.setCursor(35, 100);                            // move cursor to position (35, 100) pixel
    tft.print("Error");
    while (1); // stay here
  }

  tft.drawFastHLine(0, 55,  tft.width(), ST77XX_CYAN);  // draw horizontal seperation line at position (0, 55)pixel
  tft.drawFastHLine(0, 95,  tft.width(), ST77XX_CYAN);  // draw horizontal seperation line at position (0, 195)pixel
  tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);           // set text color to red and black background
  tft.setCursor(30, 20);                                // move cursor to position (30, 20) pixel
  tft.print("TEMPERATURE ");                            // setting heading for first section
  tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);          // set text color to cyan and black background
  tft.setCursor(40, 60);                                // move cursor to position (40, 60) pixel
  tft.print("HUMIDITY ");                               // setting heading for second section
  tft.setTextColor(ST77XX_GREEN, ST7735_BLACK);         // set text color to green and black background
  tft.setCursor(40, 100);                               // move cursor to position (40, 100) pixel
  tft.print("PRESSURE ");                               // setting heading for third section

  tft.setTextSize(2);                                   // setting text size to 2
}

// main loop
void loop()
{
  connectWiFi();
  char _buffer[10];
  // read temperature, humidity and pressure from the BMP280 sensor
  float temp = bmp280.readTemperature();    // get temperature in °C
  float hum = dht.readHumidity();           // get humidity in rH%
  float pres = bmp280.readPressure();       // get pressure in hPa

  // print temperature (in °C)
  if (temp < 0)                             // if temperature < 0
    sprintf( _buffer, "-%02u.%02u", (int)abs(temp), (int)(abs(temp) * 100) % 100 );
  else                                      // if temperature >= 0
    sprintf( _buffer, " %02u.%02u", (int)temp, (int)(temp * 100) % 100 );// setting the value approximation
  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);  // set text color to yellow and black background
  tft.setCursor(11, 34);                          // move cursor to position (11,34) pixel
  tft.print(_buffer);                             // print temperature from BMP-280 sensor
  tft.drawCircle(89, 34, 2, ST77XX_YELLOW);       // print the degree symbol ( ° )(can be omitted if * is used instead)
  tft.setCursor(95, 34);                          // move cursor to position (95,34) pixel
  tft.print("C");                                 // print the Celcius symbol

  // 2: print humidity (in %)
  sprintf( _buffer, "%02u ", (int)(hum));          // setting the value approximation
  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);  // set text color to magenta and black background
  tft.setCursor(45, 74);                           // move cursor to position (45,74) pixel
  tft.print(_buffer);                              // print humidity from DHT-11 sensor
  tft.setCursor(75, 74);                           // move cursor to position (75,74) pixel
  tft.print("%");                                  // print the percentage symbol


  // 3: print pressure (in hPa)
  sprintf( _buffer, "%04u.%02u", (int)(pres / 100), (int)((uint32_t)pres % 100) ); // setting the value approximation
  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);  // set text color to orange and black background
  tft.setCursor(3, 112);                          // move cursor to position (3,112)pixel
  tft.print(_buffer);                             // print atmospheric pressure from BMP-280
  tft.setCursor(91, 112);                         // move cursor to position (91,112)pixel
  tft.print("hPa");                               // print unit of atmospheric pressure as hecto pascal

  delay(10000);                                    // wait 1 second before taking next sensor reading

  //convert sensor values to strings

  String temperatureStr = dtostrf(temp, 4, 1, _buffer);
  temperatureStr.replace(" ", "");
  String humidityStr = dtostrf(hum, 4, 1, _buffer);
  humidityStr.replace(" ", "");
  String pressureStr = dtostrf(pres, 4, 1, _buffer);
  pressureStr.replace(" ", "");

  updateSensors(temperatureStr, humidityStr, pressureStr);

  //wait next sampling cycle
  Serial.print("Wait ");
  Serial.print(delay_time / 1000);
  Serial.println("s for next sampling");
  Serial.println();
  delay(delay_time);

  //initialize new cycle
  Serial.println();
  Serial.print("Sampling (");
  Serial.print(sampletime_ms / 1000);
  Serial.println("s)...");
  starttime = millis();
}



void updateSensors(String temperatureStr, String humidityStr, String pressureStr) {

  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += IP;
  cmd += "\",80";
  monitor.println(cmd);
  delay(1000);

  cmd = GET;
  cmd += temperatureStr;
  cmd += "&field2=";
  cmd += humidityStr;
  cmd += "&field3=";
  cmd += pressureStr;
    cmd += "\r\n";
  delay(1000);
  int strsize = cmd.length();
  monitor.println("AT+CIPSEND=" + String(strsize));
  delay(1000);

  monitor.print(cmd);
  if (monitor.find("OK")) {
    Serial.println("Transmission completed with success");
  } else {
    Serial.println("Transmission failed!");
  }
}

boolean connectWiFi()
{
  Serial.println("Connecting wi-fi...");
  String cmd = "AT+CWMODE=1";
  monitor.println(cmd);
  delay(1000);
  monitor.flush(); //clear buffer
  cmd = "AT+CWJAP=\"";
  cmd += SSID;
  cmd += "\",\"";
  cmd += PASS;
  cmd += "\"";
  monitor.println(cmd);
  delay(250);

  if (monitor.find("OK")) {
    Serial.println("Connection succeeded!");
    return true;
  } else {
    Serial.println("Connection failed!");
    return false;
  }
  Serial.println();
}

The diagram is more or likely like this, I know its an nano board, the problem is as same as when I use the uno

Does not the ESP8266, a 32 bit machine being controlled by an 8 bit machine, have WiFi?

I'm so sorry, but i don't fully understand what are you trying to say

You wrote,

Don't you have an Arduino with an ESP8266 that has WiFi?

yes, but it only transmits the sensor data if the board is connecting to PC, other than that there is no data transmitted to the thingspeak, that why I'm curious on how to solve it

Which components are you using exactly? Maybe you can send us a circuit diagram, so we can understand better, what you're trying to do.

E.g.:
Are you using an ESP8266 or an Arduino UNO microcontroller?

Arduino Uno with an ESP8266 module

The diagram is more or likely like this, I know its an nano board, the problem is as same as when I use the uno

Where is the code you are using to transmit WiFi?
UNO WiFi Rev 2 | Arduino Documentation | Arduino Documentation

UNO WiFi Rev 2 | Arduino Documentation | Arduino Documentation

I found those by using words in an internet search engine.

the program which tell the board and the wifi module to send the data to thingspeak only run if it's connected to the PC through the serial comm and I want to make the program runs without connected to PC

Your MCU will run on a separate power supply. The MCU does not NEED to be connected to PC for power. Alternate power sources are available, use your imagination.

See. WiFI without a computer connection.

Does my Code is good enough for that? I thought that my code contribute to the problem.
If my code does good, do I just need a power source that is strong enough to run the entire circuit??

Your code does not use any WiFI code. I posted a link on how to use the WiFi module of your thingy. Did you look at the link and check out the examples on how to use WiFi? Or are you waiting for me to write the WIFi code for you?

I never heard before from the method, that uses an ESP8266 as an wifi antenna for the Arduino UNO. I see in your code that you make your wifi connection over the computer and not over the ESP8266. So when the computer isn't connected, there is no wifi connection. What you are trying to do is probably possible, but when you said you are very new to Arduino, I'd make you a new suggestion:
The ESP8266 is a microcontroller itself. Try to connect the DHT and the BMP280 (and maybe the TFT-Display too, but always step-by-step!) to the ESP8266 and program the ESP8266 with help of the examples in Arduino IDE. We can help you, if you have problems.


To be honest, i kinda lost when to select which one I should see to fix the problem

So in a nutshell, you can just use the ESP8266 alone without the Uno board, but how do you upload the program? and what about the power source?

You are not going to click on one of those links to see how WiFi is used with the hardware you got?

For example by using an NodeMCU or a FTDI-Adapter with an additional circuit. But a NodeMCU is good for beginners.

A FTDI-Adapter can give you the power 3.3 V too. Then you can use it e.g. with a usb powerbank.

Okay, ill try to see which one fits the most

image
does the NodeMCU is the one like this?

image
and the FTDI-adapter is sort of like this? with the esp8266 adapter