Can not automatically send data to ThingSpeak

Hey guys so im having an issue,

i have the esp8266 module working with the arduino mega and they are communicating fine.
I am having issues sending information to thingspeak automatically when i run my code.

what i mean by this is that i am able to send data to thingspeak (thingspeak will display my data correctly) if i manually give the esp8266 AT commands.

e.x

AT+CIPSTART="TCP","184.106.153.149",80
AT+CIPSEND=54
GET /update?key=MYKEYHERE&field1=10

But once my program starts to run, serial monitor/plotter will display my data, but thingpseak isnt receiving anything.

this is the code i have written so far.

Please excuse me if i have not written this post in the correct way, this is my first post ever on here.

#include <SoftwareSerial.h>
#include <stdlib.h>
#define SSID "iPhone"
#define PASS "cristian890"


//  Variables

int PulseSensorPurplePin = 0;        // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED13 = 13;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550;            // Determine which Signal to "count as a beat", and which to ingore.

String GET = "**MYAPIKEY**";
SoftwareSerial ser(9, 10); //RX, TX


// The SetUp Function:

void setup() {
  pinMode(LED13, OUTPUT);        // pin that will blink to your heartbeat
  Serial.begin(9600);         // Set's up Serial Communication at certain speed.
  ser.begin(9600);

  // reset ESP8266
  ser.println("AT+RST");
}

// The Main Loop Function

void loop() {

  Signal = analogRead(PulseSensorPurplePin);  // Read the PulseSensor's value.
                                                               // Assign this value to the "Signal" variable.

  Serial.println(Signal);       // Send the Signal value to Serial Plotter.


  if (Signal > Threshold) {         // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW);      //  Else, the sigal must be below "550", so "turn-off" this LED.
  }
}

boolean connectWiFi()
{
  Serial.println("AT+CWMODE=1");
  delay(2000);
  String com = "AT+CWJAP=\"";
  com += SSID;
  com += "\",\"";
  com += PASS;
  com += "\"";
  //sendDebug(cmd);
  delay(5000);
 
  //TCP connection

  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "184.106.153.149"; // api.thingspeak.com
  cmd += "\",80";
  ser.println(cmd);

  if (ser.find("Error")) {
    Serial.println("AT+CIPSTART error");
    return;
  }

  // prepare GET string
  String getStr = "GET /update?api_key=";
  getStr += GET;
  getStr += "&field1=";
  getStr += String(Signal);
  getStr += "\r\n\r\n";

  // send data length
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  ser.println(cmd);

  if (ser.find(">")) {
    ser.print(getStr);
  }
  else {
    ser.println("AT+CIPCLOSE");
    // alert user
    Serial.println("AT+CIPCLOSE");
  }




}

SoftwareSerial ser(9, 10); //RX, TX

On a Mega? Why? You have 4 hardware serial ports. Use them first.

Having a connectWiFi() function, but not calling it, is useless.

Having a connectWiFi() function that does more than connect to the network is wrong.

Thank you for your reply!
I'm fairly new to coding, as a result I've had to do most of this code on trial and error.

For your first concern,

I switched rx/tx to different pins because most of the sample codes I have found online recommend doing so (why? I'm not sure)

As for the connectWiFi() function, I have also adapted it to my code because from all the reading I've done (for the past 5 days) it is Required. Like I said earlier, I'm fairly new to coding so I am not to sure if I need it or if I'm using it correctly.

Like I said earlier, I'm fairly new to coding so I am not to sure if I need it or if I'm using it correctly.

You don't need the function if you don't plan to call it. It's like buying a book you don't plan to read.

Maybe that is why my data is not sending, because I am not calling the function.
Does it matter when/where I am the function in the code ( beginning/end of sketch)?

Does it matter when/where I am the function in the code ( beginning/end of sketch)?

I'm going to assume that English is not your first language, and guess at what you mean.

It does not matter where you PUT the function. You can put it before setup(), between setup() and loop(), or after loop().

It DOES matter where you CALL the function.

Thanks for your help.

English is, in fact, my native language.

I have seen you reply in some other threads and you are some character.

I do not understand why they would take in to consideration all of your post made with sarcasm and insults, towards your "Brattain Member" status.

What exactly do you get from trying to belittle other members who are simply trying to learn how to fix their coding issues?

Just another keyboard warrior, I suppose.