How to connecting sensors from another network

Hello folks!
I need some help.
I use motion sensors, and everything was fine. I had to use another network (not local), I changed the IP to the one where my server is, but it doesn't want to connect. How can I connect my servers from another network to my home network? I've been trying all week but no luck!
I will be very happy if someone can give some help.

I am using latest version Domoticz2022.2 (build 14782).
It is installed on Ununtu 20.04 server.
and ESP12-F

I'm also uploading the code I've used so far. Maybe a username and password should be added. I do not know...

Thanks in advance!

/* PIR Advanced motion Detection with deep-sleep mode */
#define DEBUGPRINTLN0(x) Serial.println(x)


ADC_MODE(ADC_VCC); //vcc read

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

// WiFi credentials & Domoticz API IDX.
const char* WIFI_SSID = "MyWifiName";
const char* WIFI_PASS = "password";
const char* DOMOTICZ_SRV = "http://myIP:8080";
const char* DOMOTICZ_SWITCH_IDX = "16";
const char* DOMOTICZ_VOLT_IDX = "66";
const int PIRSignalPin = 14; //Using GPIO14 for PIR Data

void setup() {
  HTTPClient http;      // HTTP object
  String api;           // Holds full API string for Domoticz
  int httpCode;         // Return HTTP code
  String response;      // Response from HTTP GET request
  float vdd;            // Internal voltage
  String s_vdd;         // Internal voltage (formatted as string)
  
  Serial.begin(115200);
  Serial.setTimeout(2000);

  while (!Serial) { }   // Wait for serial to initialize.
  
  Serial.println("");
  Serial.println("-------------------------------------");
  Serial.println("PIR Motion Detection Firmware!");
  Serial.println("-------------------------------------");

  // Connect to Wifi.
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    // Check to see if
    if (WiFi.status() == WL_CONNECT_FAILED) {
      Serial.println("");
      Serial.println("Failed to connect to WiFi. Please verify credentials!");
      delay(10000);
    } else {
      delay(500);
      Serial.print(".");
    } 
  }

  Serial.println("");
  Serial.print("WiFi connected with IP address: ");
  Serial.println(WiFi.localIP());

  // Send post request to Domoticz
  Serial.println("");
  
  Serial.println("Sending On signal to Domoticz.");
  //Build API command
  api = DOMOTICZ_SRV;
  api += "/json.htm?type=command&param=switchlight&idx=";
  api += DOMOTICZ_SWITCH_IDX;
  if (digitalRead(PIRSignalPin)==HIGH) {
    api += "&switchcmd=On";
  } else {
    DEBUGPRINTLN0("Sending 'Off' signal to Domoticz.");
    api += "&switchcmd=Off";
  }    
  http.begin(api);                        //Specify request destination
  httpCode = http.GET();                  //Send the request and set return code
  Serial.print("Return code: ");
  Serial.println(httpCode);
  if (httpCode > 0) {                     //Check the returning code  
    response = http.getString();          //Get the request response
    Serial.println("Response:");
    Serial.println(response);
  } 
  http.end();                             //Close connection

  delay(200);

  Serial.print("Sending voltage to Domoticz: ");
  vdd = ESP.getVcc() / 1024.0f;
  s_vdd = String(vdd, 3);
  Serial.println(s_vdd);
 
  api = DOMOTICZ_SRV;
  api += "/json.htm?type=command&param=udevice&idx=";
  api += DOMOTICZ_VOLT_IDX;
  api += "&nvalue=0&svalue=";
  api += s_vdd;
  http.begin(api);                        //Specify request destination
  httpCode = http.GET();                  //Send the request and set return code
  Serial.print("Return code: ");
  Serial.println(httpCode);
  if (httpCode > 0) {                     //Check the returning code  
    response = http.getString();          //Get the request response
    Serial.println("Response:");
    Serial.println(response);
  } 
  http.end();                             //Close connection
  
  Serial.println("");
  Serial.println("Going into deep sleep!");
  ESP.deepSleep(0); // forever

}

void loop() {
  // Never reached!
}```

you have to configure the router which connects your home network to the internet to forward packets to the appropriate server - this is usually called port forwarding - - how you do this varies from router to router - look it up in the router user manual
e.g. when a packet arrives at your router for port 80 (the standard HTTP port) you set up the router to forward it to the IP address of the PC on your home network which is running your HTTP web server
note that any servers may be accessed using port forwarding should have static IP addresses

yes thanks, but that's what I did. I have forwarded the ports to the server's IP. from my phone opens it with mobile data but asks for user and password. and locally, when I connect, it doesn't ask for username and password. I supposedly added this IP from where I want it to run without a user-password, but it doesn't work. apparently I have to describe something like username and password somewhere.

this must be a security feature of your router
there must be some method to switch it off otherwise how can you a general web server, ftp server, etc
my router just forwards without problems

i tried adding an extra line with name and password in my code and reuploading it to my esp-12f board but it doesn't work. I still can't connect the sensor from an external network. maybe i'm not doing something right. I don't know exactly how to code the password correctly most likely.
all port is open. not problem in port. i have another services, and dont have problem to port.