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
  • #1 17824897
    heyka
    Level 17  
    Please advise me how to configure the ESP8266 module to work:
    - as a UDP server
    - to listen on IP address 10.10.2.1 and port 22000
    - to send everything that comes to it via RS232 to the processor and if the processor responds to something to send it back to the client via WiFi

    Added after 18 [minutes]:

    Is it possible to set all this up using AT commands?
  • ADVERTISEMENT
  • #2 17824939
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #3 17826908
    heyka
    Level 17  
    Code: C / C++
    Log in, to see the code
    .

    does not accept my command to set up the server
  • #4 17826945
    Anonymous
    Level 1  
  • #5 17827032
    heyka
    Level 17  
    Code: C / C++
    Log in, to see the code
    .

    From the above information , it appears that the module is set as an AP, it sends received data to the serial port, it handles one connection at a time.
    How do I check if it is acting as a UDP server with IP 10.10.100.254 and has a listening port set to 32000?
  • #6 17827073
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #7 17827076
    heyka
    Level 17  
    Code: C / C++
    Log in, to see the code
    .
    I have set the IP, still only the port , but I do not know with what command
  • #8 17827087
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #9 17827186
    heyka
    Level 17  
    Code: C / C++
    Log in, to see the code
    .

    When I set according to the link, something is wrong

    Added after 27 [minutes]:

    Code: C / C++
    Log in, to see the code
    .
    I reset the module and set everything as above
    what does the Cipstatus number 12819 and that zero at the end mean?

    Can it be assumed that everything is set correctly?

    Added after 1 [minute]:

    Code: C / C++
    Log in, to see the code
    .
  • #10 17827222
    kaczakat
    Level 34  
    In my opinion the method from the first link will be more effective, you upload the code exactly as you need it and the ESP is immediately in that mode after the reset. With AT commands you will have to be careful if you accidentally do a reset and set it up again.
    Helpful post? Buy me a coffee.
  • #11 17827471
    heyka
    Level 17  
    kaczakat wrote:
    upload the code exactly as you need it
    .
    OK

    I need the module to work in AP mode as a UDP server listening on IP 10.10.100.254 on port 32000 and everything that arrives to it forwarded to RS232 with ASCII transmission.

    I have no experience with these modules and with Arduino.

    So do I need to write code in Arduino and program the module?
  • #12 17827888
    kaczakat
    Level 34  
    You don't need to know too much with Arduino, in the sticky in this section it is described what you need to do to install ESP8266 boards to Arduino. But it's still a lot of work ahead of you, I've been playing with Arduino for over 2 years and I still learn what I didn't know every day. If you have a NODE MCU/ WEMOS, a MICRO USB cable + Arduino is enough for programming. For the ESP-01 you need a 3.3V UART converter and a sequence of shorted pins to program, some 3.3V power supply, a tad harder to start with. In both cases you open a new sketch, paste the ready-made from the link from @khoam, modify the ready-made to send only the buffer to the serial (delete the extra lines) and you're almost done. ESP can be configured for a fixed IP and all network parameters, you need to add reading the response from Serial and writing back with either an incoming UDP or serial message (now the default is acknowledged) . For testing, you can use the TCP/UDP client SocketTeset v3.0.0 or something like that on a PC, there are also some for Android. It is also a question of how much of this data flies and how often. Whether AP or station this is specified when initialising WIFI in the sketch, for everything there are plenty of examples and in the Arduino IDE and on google. With Arduino you are most likely to even find something exactly like you need, there are many other hits for UDP - e.g. https://github.com/roboremo/ESP8266-WiFi-UART-Bridge/tree/master/v1.1 A week is not enough to review, copy, compile and test everything.
    Helpful post? Buy me a coffee.
  • #13 17827968
    heyka
    Level 17  
    I've got the Arduino installed, I've got the ESP8266 board installed, I've got the converter, I've got everything ( how little it takes to have everything :) )

    I need some code as simple as possible that will set up the module according to what I need to be able to analyze and understand it. This example pd mate khoma is heavily elaborated and I don't know how to go about it.
  • #14 17828289
    Anonymous
    Level 1  
  • #15 17828705
    heyka
    Level 17  
    I fired up Arduino today and my ESP 8266 board disappeared in the board manager.
    Attachments:
    • Configuration of ESP8266 as UDP server with RS232 - IP 10.10.2.1, port 22000, AT? arduino.png (8.17 KB) You must be logged in to download this attachment.
  • #16 17828710
    Anonymous
    Level 1  
  • #18 17828720
    Anonymous
    Level 1  
  • #19 17828728
    heyka
    Level 17  
    address is posted , but I have a download error message as I have attached on screean
  • #20 17828737
    Anonymous
    Level 1  
  • #21 17828743
    heyka
    Level 17  
    At my place yesterday everything was OK, strange, Arduino doesn't like me. Something makes me think I'll stick with C and Eclipse
  • #22 17828769
    Anonymous
    Level 1  
  • #23 17828989
    kaczakat
    Level 34  
    heyka wrote:
    I fired up the Arduino today and the ESP 8266 board disappeared in the board manager.
    .
    But how did it disappear, did you manage to install it? If you can't connect to the Arduino IDE somewhere, it's not likely to be a problem of network blocking software. Confirm by trying to fire up the library/board manager. The program in the first link from @khoam works OK, upload, test, disable what you don't need, upload, test, add what you need from the UART side (I recommend the serialEvent example), upload, etc.
    Helpful post? Buy me a coffee.
  • #24 17829051
    heyka
    Level 17  
    I can't upload because I don't have a board available in Arduino in the board manager, yesterday I installed it was available,and today I turned on Arduino and it's not there and I can't install it.
  • #25 17829056
    kaczakat
    Level 34  
    Well, download again/uninstall/install, you didn't have the day before yesterday so it's a small loss too. It will go faster the second/next time. There are also ZIP versions, which do not require installation.
    Helpful post? Buy me a coffee.
  • #26 17829113
    heyka
    Level 17  
    kaczakat wrote:
    .
    The program from the first link from @khoam works OK.


    Where to enter in the code
    - IP no. of the UDP server
    - port no. on which the server should receive


    I get an error when trying to compile

    Code: C / C++
    Log in, to see the code
    .
  • #27 17829132
    Anonymous
    Level 1  
  • Helpful post
    #28 17829149
    kaczakat
    Level 34  
    Well, it works OK, but there is something wrong with the fonts, I changed the inverted commas to Polish.
    See this version, my modifications towards your requirements:
    Code: C / C++
    Log in, to see the code
    .
    Helpful post? Buy me a coffee.
  • #29 17830044
    heyka
    Level 17  
    Code: C / C++
    Log in, to see the code
    .

    Is this the IP setting of the module or the UDP server?
  • #30 17830051
    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