Can anyone help me with the portMapping

I try so hard to PortMapping my project but i can not make it.Everything is ok but I can not PortMapping.
Can anyone check my Code please? What is wrong? Sorry for my bad English. :sob:

#include "SPI.h"
#include "Ethernet.h"
#include "portMapping.h"


  const int ry1 = 13;
  const int ry2 = 12;
  const int ry3 = 11;
  const int ry4 = 10;
  
  EthernetClient client;
  PortMapClass portmap;

  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  IPAddress ip(192,168,1,7);
  EthernetServer server(5000);
  
  String readString; 

void setup(){
  //pin selected to control
  pinMode(ry1, OUTPUT); 
  pinMode(ry2, OUTPUT);
  pinMode(ry3, OUTPUT);
  pinMode(ry4, OUTPUT);

  ////UPnPSetUp
  Serial.begin(9600);
   while (!Serial) {
  }
 
  Serial.println(F("Initializing... "));
 
  // start the Ethernet connection:
  //fixed IP address:
  if (Ethernet.begin(mac) == 0) {
    Serial.println(F("Failed to configure Ethernet using DHCP"));
    // DHCP failed, so use a fixed IP address:
    Ethernet.begin(mac, ip);
    Serial.println(F("Fixed IP initialization complete"));
  }
  else
  {
    Serial.println(F("Configured Ethernet using DHCP"));
  }

  Serial.print(F("device IP is: "));
  Serial.println(Ethernet.localIP());
  
  Serial.print(F("gateway IP is: "));
  Serial.println(Ethernet.gatewayIP());
  
  Serial.print(F("subnet mask is: "));
  Serial.println(Ethernet.subnetMask());

  Serial.print(F("DNS is: "));
  Serial.println(Ethernet.dnsServerIP());

  Serial.print(F("External IP is: "));
  Serial.println(portmap.externalIp());

  if (portmap.addPortMap(Ethernet.localIP(),5000, 80))  // add port mapping for user defined port values
 {
   Serial.println(F("Port Mapped successfully!"));
   Serial.print(F("Internal Port: "));
   Serial.println(portmap.internalPort());
   Serial.print(F("External Port: "));
   Serial.println(portmap.externalPort());
 }else {
   Serial.println(F("unable to map port.  Check your router UPNP function is turned on"));
 }
   
}



void loop()
{
  // Create a client connection
  EthernetClient client = server.available();
  if (client.available()) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        
        if (readString.length() < 100) {

          
          readString += c; 
          
        } 

        
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          

          client.println("<h1>Light Controller</h1>
");
          
          
          // DIY buttons
          client.println("Room 1");
          
          client.println("<a href= /on1><h1>ON</h1></a>"); 
          client.println("<a href = /off1><h1>OFF</h1></a>"); 
          
          client.println("Room 2");

          client.println("<a href= /on2><h1>ON</h1></a>"); 
          client.println("<a href = /off2><h1>OFF</h1></a>"); 

          client.println("Room 3");

          client.println("<a href= /on3><h1>ON</h1></a>"); 
          client.println("<a href = /off3><h1>OFF</h1></a>");

          client.println("Room 4");

          client.println("<a href= /on4><h1>ON</h1></a>"); 
          client.println("<a href = /off4><h1>OFF</h1></a>");
          
         
          client.println("");
          client.println("");
 
          delay(10);
          
          client.stop();

          ////LOW=on////HIGH=off
          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >0)//checks for on
          {
            digitalWrite(ry1, LOW);    // set pin 13 on
            Serial.println("Led On");
          }
          if(readString.indexOf("off1") >0)//checks for off
          {
            digitalWrite(ry1, HIGH);    // set pin 13 off
            Serial.println("Led Off");
          }
          
          if(readString.indexOf("on2") >0)//checks for on
          {
            digitalWrite(ry2, LOW);    // set pin 12 on
            Serial.println("Led On");
          }
          if(readString.indexOf("off2") >0)//checks for off
          {
            digitalWrite(ry2, HIGH);    // set pin 12 off
            Serial.println("Led Off");
          }

          if(readString.indexOf("on3") >0)//checks for on
          {
            digitalWrite(ry3, LOW);    // set pin 11 on
            Serial.println("Led On");
          }
          if(readString.indexOf("off3") >0)//checks for off
          {
            digitalWrite(ry3, HIGH);    // set pin 11 off
            Serial.println("Led Off");
          }

          if(readString.indexOf("on4") >0)//checks for on
          {
            digitalWrite(ry4, LOW);    // set pin 10 on
            Serial.println("Led On");
          }
          if(readString.indexOf("off4") >0)//checks for off
          {
            digitalWrite(ry4, HIGH);    // set pin 10off
            Serial.println("Led Off");
          }
          readString="";
          delay(4000);
        }
      }
    }
  }
}

I can't see why you are port mapping. That is normally a function of a router to map an external IP/port to an internal IP/port. Do you have two ethernet shields connected to your Arduino?

SurferTim:
I can't see why you are port mapping. That is normally a function of a router to map an external IP/port to an internal IP/port. Do you have two ethernet shields connected to your Arduino?

I have one ethernet shields connected to my Arduino.

This is my portMapping code.

if (portmap.addPortMap(Ethernet.localIP(),5000, 80))  // add port mapping for user defined port values
{
  Serial.println(F("Port Mapped successfully!"));
  Serial.print(F("Internal Port: "));
  Serial.println(portmap.internalPort());
  Serial.print(F("External Port: "));
  Serial.println(portmap.externalPort());
}else {
  Serial.println(F("unable to map port.  Check your router UPNP function is turned on"));
}

Okay, one more time...what is the purpose of this port mapping? Are you trying to access the Arduino from the internet? Google "port mapping", then explain what you are trying to do with this.

I try to turn on and off the light using internet through the Arduino.When you forget to turn off your light you can turn it off everywhere just use the internet.

I try to make Arduino can auto fix IP and Port mapping.Not have to set Port forward in the router and make Arduino have Webserver too.

Why?

I try to use this with UPnP option in router because it is easy if arduino can fix ip and portmapping it automatic just plug it to the router and only fix IP for arduino.Then use NO-IP to connect from anywhere through the router to arduino and then you can turn on and off the light.

Pix of port forward/mapping on a Netgear 614 router attached. Youtube has tutorials.

That's a fair answer. Then the topic is really about uPnP and NO-IP. Does your port mapping library access your router with uPnP? Would you please post a link to the portMapping library?

edit: Are you aware that many routers need to have uPnP enabled before you can access them? It is disabled by default in several makes of routers.

Are you aware that some ISPs block inbound traffic access to popular ports, like port 80? You may need to use port 8080 or 5000 for the public port in your example code.