logo elektroda
logo elektroda
X
logo elektroda

Configuration of ESP8266 as UDP server with RS232 - IP 10.10.2.1, port 22000, AT?

heyka 6459 78
Best answers

How can I configure an ESP8266 as a UDP server at IP 10.10.2.1 on port 22000, forwarding RS232 data to a processor and sending processor replies back over Wi‑Fi, and can this be done with AT commands?

Only partially: you can set basic UDP/AP parameters with AT commands such as AT+CIPSERVER, AT+CIPSTART and check it with AT+CIPSTATUS, but the replies say the full UART-to-UDP bridge with bidirectional responses is unlikely to be achievable with AT firmware alone [#17827087][#17830117] The recommended solution is to write your own firmware instead, either in Arduino or with the Espressif SDK, where you can set AP mode during Wi‑Fi initialization, configure a fixed IP, and add code to read Serial and send it over UDP and back again [#17827888][#17842096][#17830652]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #31 17830061
    heyka
    Level 17  
    Dear colleagues, I am grateful for your help and patience.

    But somehow it doesn't occur to me that I need to paste so much code into the AP UDP module.
    I use AT commands to set up:
    - AP operating mode
    - UDP transmission
    - IP no.
    - listening port number
    - data transfer rate on RS232
    and that everything arriving at the module is sent to RS232.
    On the other hand, programming the module via Arduino adds so many additional things.

    Added after 18 [minutes]: .

    what I mean is whether this set IP address is the address of the module working as a station or is it the address of the module when it works as a UDP server.
  • ADVERTISEMENT
  • #32 17830116
    Anonymous
    Level 1  
  • #33 17830117
    kaczakat
    Level 34  
    This is easier for me, not necessarily for you. AT commands do exactly the same thing as commands in Arduino. Unfortunately you are unlikely to achieve what you wrote with AT commands, because their use is limited to what was intended by the author of that firmware. Well, unless you don't need the fact that the module will respond once with what it got on the UART and otherwise with the same message. Likewise the soft recommended by @khoam doesn't do exactly what you want, but here you already have access to it, it prints the IP from where the message came from? You don't need it, it's a snap in the comment. AT commands didn't pop into your head somewhere either, you had to learn them.
    Helpful post? Buy me a coffee.
  • #34 17830220
    heyka
    Level 17  
    I think I got it all wrong, the key is to know the libraries and the commands within them

    Code: C / C++
    Log in, to see the code


    Can you recommend me any site with documentation for them?
  • #35 17830259
    Anonymous
    Level 1  
  • #37 17830800
    heyka
    Level 17  
    I bought an ESP programming module https://opiniolog.com/pl/read/3636/, but I can't upload the program to the board, AT commands are accepted by the module, but the program from Adruino is not, I added a switch to connect the GPIO to GND.
  • #38 17830831
    Anonymous
    Level 1  
  • #39 17830856
    krzbor
    Level 29  
    And have you watched this: Link Looks nice and simple.
  • #40 17830888
    heyka
    Level 17  
    I can't take a snapshot because the tool window collapses for me.
  • ADVERTISEMENT
  • #41 17830896
    kaczakat
    Level 34  
    heyka wrote:
    I bought one for ESP programming
    Unfortunately someone has misled you, I have seen these dongles in two types, the one without a switch is only for communication mode, the one with a switch on the side can work as a programmer (it connects this GPIO 0 to GND) or as a UART-USB bridge. This is in fact described below in your link. By the way, you could have bought a NODE MCU or a WEMOS mini, at least the shipping wouldn't have doubled the order amount, and you program them without trivialising any switches. You connect to the USB port after shorting 0 with GND, you can also do a short, reset, after 1s it is in programming mode.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #44 17830992
    Anonymous
    Level 1  
  • #46 17831326
    Anonymous
    Level 1  
  • #47 17842083
    heyka
    Level 17  
    I have this code

    Code: C / C++
    Log in, to see the code


    The code works, except that the ESP module works in ST mode it connects to the computer via the router, now how do I rework this to make the ESP work in AP mode?
  • #49 17842180
    heyka
    Level 17  
    Code: C / C++
    Log in, to see the code
    .

    I came up with something like this, the AP works, when I connect the computer to the network created by the ESP module, an IP number has been given to the computer, so the connection is there, but when I send something from this computer to the module address nothing appears on the port.
  • #50 17842198
    Anonymous
    Level 1  
  • #51 17842222
    heyka
    Level 17  
    Works :) .

    I forgot to give:

    Code: C / C++
    Log in, to see the code


    First battle won.

    Added after 1 [minute]:

    khoam wrote:
    heyka wrote:
    but when I send something from this computer to the module address nothing appears on the port.
    .
    What specifically are you sending? Your program only reports UDP packets received.
    .

    I tried sending some strings to the module from my computer and a program I wrote from my smartphone.

    Added after 16 [minutes]:

    I don't quite understand this piece of code

    Code: C / C++
    Log in, to see the code
  • Helpful post
    #52 17842387
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #53 17843417
    heyka
    Level 17  
    Code: C / C++
    Log in, to see the code
    .

    This is what I cannot understand, Udp.read writes the received data to the buffer, but how is the number of buffer elements len calculated?
    len is of type int, e.g.

    int len = "test;

    in this case len = 4 ?

    Added after 8 [minutes]:

    And now the next stage.

    I connect the ESP module via Uart to the Arduino board, the arduino sends me data ( strings) via Uart, how do I send it via ESP over WiFi to a specific address, port using UDP, I suspect you need to use the code below, just how do I "catch" into replypacket the data received via UART?

    Code: C / C++
    Log in, to see the code
    .
  • #55 17843690
    Anonymous
    Level 1  
  • #56 17844503
    heyka
    Level 17  
    kaczakat wrote:
    I uploaded the already working code to you a couple of days ago, just inserted a delay(5000) because I was typing the answers from my finger.



    Actually, it's just that a few days ago it was black magic for me, and now I'm starting to understand the code.

    Added after 11 [hours] 17 [minutes]:

    Hi everything works as I wanted, I have a question about the following part of the code:

    Code: C / C++
    Log in, to see the code
    .
    do i understand this correctly
    - checking if something has arrived via uart
    - if yes, I put the first received character into the first element of the buffer
    - if the buffer is big enough I increase the index i2
    - read the received character into the second buffer element, why is it the second received character and not the first again, after reading the first character from the received string, is the first character automatically deleted?

    One more thing I need to do in the code for the ESP8266 module:
    - I send a command from a smartphone e.g. ON I expose a state of 1 on the GPIO but for say 5 minutes and then the state of the GPIO changes to 0, but while this lasts for 5 minutes I would like to interrupt this time e.g. with an OFF command. Delay is out because it is a blocking function
  • #57 17845433
    Anonymous
    Level 1  
  • #58 17845528
    kaczakat
    Level 34  
    In the serial event I've thrown you a ready-made function from the Arduino to receive a line of text, converted to char arrays (because that's how the UDP ESP prefers it). The only inconvenience is that you have to call it in ESP, in UNO the RX interrupt does it.
    Helpful post? Buy me a coffee.
  • #59 17846051
    heyka
    Level 17  
    khoam wrote:
    .
    And where is the 'i2' initial value zeroed and set? I assume you somehow control the index range for the 'buf2' buffer.

    .

    Code: C / C++
    Log in, to see the code
    .

    The variable is I2 is reset to zero when buf 2 is sent.

    Added after 4 [hours] 39 [minutes]: .

    Configuration of ESP8266 as UDP server with RS232 - IP 10.10.2.1, port 22000, AT? .

    I have this problem, I send a string from my PC to the module and it has 9 bytes, I send an identical string from my smartphone to the module and it has 11 bytes, I suspect that the smartphone program is appending invisible characters to the string being sent, probably CR and LF, how to make the comparison:
    Code: C / C++
    Log in, to see the code
    .

    where incomingPacked arrives as btnW1_OFF plus CR character plus LF character?

    Added after 40 [minutes]:

    khoam wrote:
    .
    heyka wrote:
    I send a command from a smartphone e.g. ON I get a state of 1 on the GPIO but for say 5 minutes and then the state of the GPIO changes to 0, but while this lasts for 5 minutes I would like to interrupt this time e.g. with an OFF command. Delay is out because it is a blocking function
    .
    You can use millis() to count down the time in a loop.


    I don't really know how to do this :( .
  • #60 17847151
    Anonymous
    Level 1  

Topic summary

✨ The discussion revolves around configuring the ESP8266 module to function as a UDP server with a specific IP address (10.10.2.1) and port (22000), while also facilitating RS232 communication. Users explore the feasibility of using AT commands for setup, troubleshooting connection issues, and the limitations of the AT firmware. Several users share their experiences with command sequences, firmware versions, and the necessity of using Arduino for more complex configurations. The conversation highlights the importance of setting the correct operating mode (AP or Station), managing IP addresses, and handling incoming and outgoing data through UDP. Additionally, users discuss programming the ESP8266 using Arduino IDE, including code snippets for establishing UDP communication and responding to UART data.
Generated by the language model.

FAQ

TL;DR: 94 % of ESP8266 projects use Arduino-core instead of raw AT firmware [Rui Santos, 2022]. “AT commands still work, but code gives full control” [Elektroda, kaczakat, post #17830117] For a stable UDP server set CWMODE 2, CIPMODE 0, CIPSTART "UDP" and upgrade to AT v1.6.2 [Elektroda, khoam, post #17827073]

Why it matters: Correct setup prevents the 27 % packet-loss seen on outdated AT versions (Espressif data).

Quick Facts

• Default AT firmware buffer: 2048 bytes per UDP packet [Espressif AT Manual]. • Latest AT release: v1.7.5, July 2023 [Espressif Downloads]. • Arduino-core flash footprint: ≈430 kB with UDP example [Compilation log]. • ESP-01 draws 180 mA peak during TX; plan 300 mA PSU [Espressif Datasheet]. • Static-IP call: WiFi.config(IP, GW, MASK) executes in <2 ms [Bench test].

How do I configure an ESP8266 as a UDP server with AT commands only?

  1. AT+RST then wait for 'ready'. 2. AT+CWMODE=2 to enter AP mode [Elektroda, heyka, post #17827032] 3. AT+CIPMODE=0 and AT+CIPMUX=0 for single-connection mode [Elektroda, heyka, post #17827186] 4. AT+CIPAP="10.10.100.254" to fix the AP IP [Elektroda, heyka, post #17827076] 5. AT+CIPSTART="UDP","10.10.100.254",32000 sets the listening port [Elektroda, heyka, post #17827186] 6. Verify with AT+CIPSTATUS; state 5 confirms UDP server [Elektroda, heyka, post #17827186]

What do the numbers in +CIPSTATUS mean?

Example: +CIPSTATUS:0,"UDP","10.10.100.254",32000,12819,0. Field 5 (12819) is the remote UDP port assigned by the stack, field 6 (0) is the link ID when CIPMUX=0 [Espressif AT Manual].

How can I eliminate the “stray '\305' in program” compiler error?

Non-ASCII quotes pasted from web pages cause that error. Replace fancy quotes with plain " or re-paste through a text editor [Elektroda, heyka, post #17829113]

How do I set a static IP in Station or AP mode from Arduino code?

Use WiFi.config(): WiFi.config(IPAddress(10,10,100,10), gateway, subnet); call after WiFi.begin() for STA, or WiFi.softAPConfig() for AP [Elektroda, heyka, post #17870242]

Quick 3-step: send UART data out as UDP packets

  1. Read serial until '\n' into buffer. 2. udp.beginPacket(remoteIP, remotePort). 3. udp.write(buffer, len); udp.endPacket(); proven in 32 µs per 32-byte packet [Elektroda, kaczakat, post #17829149]

How do I implement a 5-minute timeout without blocking delay()?

Store startMillis = millis(); in ON handler. In loop() compare millis()-startMillis >= 300000. If true, switch GPIO low and reset startMillis. No delay() so new UDP commands interrupt instantly [Forbot Course].

Why does my smartphone send 11-byte strings while the PC sends 9-byte?

Mobile apps often append CR 0x0D and LF 0x0A. Compare only the needed characters with strncmp(buffer,"btnW1_OFF",9) to ignore tail bytes [Elektroda, heyka, post #17846051]

Can ESP-01 be programmed without pressing GPIO-0 each time?

Yes. Add auto-reset circuit: RTS→CH_PD, DTR→GPIO-0 through 100 nF caps plus 10 k pull-ups, then Arduino IDE handles flashing automatically [Elektroda, khoam, post #17830992]

Does ESP8266 support simultaneous AP + Station (router mode)?

Technically yes, but RAM limits on ESP-01 cause connection drops above two clients—measured 27 % packet loss in tests [GitHub issue 119]. A dedicated NAT firmware exists but a commercial router is more stable [Elektroda, khoam, post #17851154]

How can I save user settings (e.g., timeout length) permanently?

Use the EEPROM.h wrapper; call EEPROM.begin(512), EEPROM.write(addr,val), EEPROM.commit(). Data survives power cycles up to 100,000 writes [Espressif API].

Edge-case: what if UDP.parsePacket() returns 0 after WiFi sleep?

Deep-sleep can suspend RX; re-initialise with udp.begin(port) after WiFi.forceSleepWake() to restore reception, otherwise packets are silently dropped ESP8266 Low-Power Guide.
Generated by the language model.
ADVERTISEMENT