Code Monkey home page Code Monkey logo

Comments (7)

ofekp avatar ofekp commented on September 20, 2024

@jeffpkamp
Can you please try the code from the branch issue10
FYI, there is a better API soon from the branch newApi you can try this too if you prefer, for me it works better because of some timeouts that I changed and also fixed a few debug prints that might help us now.

In case you're interested, in the method addPortMapping you're stopping here https://github.com/ofekp/TinyUPnP/blob/master/src/TinyUPnP.cpp#L58

This is probably because waitForUnicastResponseToMSearch failed. Not sure why yet, since I do see the required urn:schemas-upnp-org:device:InternetGatewayDevice:1 in the output you attached.
There's a chance this is related to issue10 since the size of the packets from your router exceed 255 byte.

Anyway, let's give it a try please.
Ofek.

from tinyupnp.

jeffpkamp avatar jeffpkamp commented on September 20, 2024

I changed the UDP read length to max with no effect. When I get the specific error it runs into during port mapping, it says it fails due to all three conditions. Is this just an issue of it failing to parse the info from the xml file? I tried setting the values manually when they failed (ie _gwinfo.port = 1900, _gwinfo.host = IPAddress(239,255,255,250), _gwinfo.path="http://192.168.0.1:1900/igd.xml"
, but this just times out waiting for the igd.

from tinyupnp.

jeffpkamp avatar jeffpkamp commented on September 20, 2024

The new API seems to be working. Its a little delayed but it gets the job done in a minute or so. I'm a little confused because it keeps cranking out information to the Serial Connection after the connection is established. Is there a way to make it less verbose once it succeeds?

from tinyupnp.

ofekp avatar ofekp commented on September 20, 2024

Glad it works!
Just curious, when you used newApi, did you also use the new UDP packet size?
You can turn off all the prints that originate from the package by changing:
#define IS_DEBUG true
to false in the .h file.
Other prints in the .ino file will have to be removed manually.

from tinyupnp.

jeffpkamp avatar jeffpkamp commented on September 20, 2024

okay, so looking at it as it runs it sort of works. But it hangs when looking for port mapping

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ESP8266SSDP.h>
#include "TinyUPnP.h"

const char* ssid = "SSID";
const char* password = "password";
#define LISTEN_PORT 40
#define LEASE_DURATION 300  // seconds
#define FRIENDLY_NAME "test"
unsigned long lastUpdateTime = 0;

TinyUPnP *tinyUPnP = new TinyUPnP(10000);  // -1 means blocking, preferably, use a timeout value (ms)
ESP8266WebServer server(LISTEN_PORT);

void setup() {
  Serial.begin(115200);
  //WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (tinyUPnP->addPortMapping(WiFi.localIP(), LISTEN_PORT, RULE_PROTOCOL_TCP, LEASE_DURATION, FRIENDLY_NAME)) {
    lastUpdateTime = millis();
  }
  Serial.println();

  tinyUPnP->printAllPortMappings();
  Serial.println();


program stalls here
port mapping works because I can see it on my routers UPnP page, but it never reaches my loop function. Just keeps printing SSDS info, which I assume is from the printAllPortMappings() function.

  Serial.println("UPnP done");

}

void loop(void) {


  // update UPnP port mapping rule if needed
  if ((millis() - lastUpdateTime) > (long) (0.8D * (double) (LEASE_DURATION * 1000.0))) {
    Serial.print("UPnP rule is about to be revoked, renewing lease");
    if (tinyUPnP->addPortMapping(WiFi.localIP(), LISTEN_PORT, RULE_PROTOCOL_TCP, LEASE_DURATION, FRIENDLY_NAME)) {
      lastUpdateTime = millis();
    }
  }
}

from tinyupnp.

ofekp avatar ofekp commented on September 20, 2024

Please make sure to use the newApi branch.
It is updated after I merged the branch issue10 with the UDP_TX_PACKET_MAX_SIZE issue.
It also solves what you described here. printAllPortMappings takes a long time if you have many UPnP ports open on your IGD router. The new branch will only print this if you encounter an error upon startup.
If you prefer to use your current code (since I am still testing the code in newApi) you can simply delete this print method from the .ino file.

from tinyupnp.

ofekp avatar ofekp commented on September 20, 2024

Closing this, since the issue is resolved.
I will debug the branch newApi a bit more before I'll put it in master.

from tinyupnp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.