logo elektroda
logo elektroda
X
logo elektroda

ESP8266 - How to change the client port in a TCP connection?

bonczi7 2526 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16097781
    bonczi7
    Level 11  
    Hello,
    can anyone find out if it is possible to change the client port on the ESP8266 chip under which it will connect to the server in TCP protocol?

    The only thing I have found in the documentation is the AT+CIPSTATUS command, which returns the client port information.

    Greetings,
    Piotr
  • ADVERTISEMENT
  • #2 16120971
    jjaskie
    Level 12  
    Are you referring to working as a UART extender using NodeMcu? That I don't know ;-) And otherwise I suggest you take an interest in the Arduino environment (+Visual Micro for the more advanced) for ESP8266 , because it can all be done.
  • ADVERTISEMENT
  • #3 16121949
    bonczi7
    Level 11  
    I have the ESP8266 connected via USART to the uC. I communicate using AT commands.
    I want it to be possible to set the client TCP port under which the chip(client) will connect to the server.
  • ADVERTISEMENT
  • #4 16121996
    jjaskie
    Level 12  
    From documentation it appears that the command used to establish the connection has the following syntax:
    AT+ CIPSTART= <id><type>,<addr>, <port>

    Similarly, the command to start the server:
    AT+ CIPSERVER= <mode>[,<port> ]

    That is: one parameter more, port number after the decimal point.
    Regards --- Jurek
  • #5 16122064
    piotrva
    VIP Meritorious for electroda.pl
    bonczi7 wrote:
    ESP8266 I have connected via USART to the uC.

    The question is do you need a separate uC?
  • ADVERTISEMENT
  • #6 16122393
    jjaskie
    Level 12  
    That's right. The ESP8266 already has a processor on board, this can be programmed in many ways. Especially the ESP-12E modules - they have 6 pins (GPIO 4, 5, 12, 13, 14, 16) of any use, plus 3 (0, 2, 15) to be careful with.
  • #7 16122754
    bonczi7
    Level 11  
    Yes, it needs a separate microcontroller.
    Regarding the CIPSTART command, the port given after the address is the server port, whereas I wanted to set the client port manually.
    Or did I misunderstand and it is possible to add an additional port number after the server port in the CIPSTART command for the TCP protocol?
  • #8 16122888
    piotrva
    VIP Meritorious for electroda.pl
    after all, I guess CIPSTART causes a connection on the client side?

    bonczi7 wrote:
    Yes, it needs a separate microcontroller.

    And would you say for what?
  • #9 16122912
    bonczi7
    Level 11  
    Yes, but you only select the IP address and port of the server, and the client port number is probably assigned automatically by ESP.
    I wanted to ask if it is possible to bypass this somehow, because the documentation, as far as I can see, is silent about it. The only thing is that for a UDP connection you can choose the client and server port.
    The thing is developmental, SD card, ethernet (additional connection via cable), USB...
  • #10 16122931
    jjaskie
    Level 12  
    Aha. TCP communication for outgoing connections always uses one of the ports in the pool designated for this, so when establishing a connection as a client generally the operating system chooses it for you. When starting a server - you have to specify it. Similarly, when connecting to a server - you specify the remote port. Of course, in most OS programming sockets, you can indicate from where the connection will be initiated, also specify this port. But - almost certainly - not from within AT+ commands.
    The TCP server, when accepting an incoming connection, should not check which port it came from.
    There is no reason why it should be any different in such a truncated OS as on the ESP8266....
    So my question is this: Why?
ADVERTISEMENT