The use of the ESP8266 in the world of IoT

User avatar
By hobby_guy
#90267 I'm experimenting with an ESP8266, connected to an ATMEGA88, and configuring it via AT commands. I've got it set up to connect to my wifi with a TCP connection, and it receives data OK. Now I want it to also listen for UDP broadcasts. But I can't get it to work.

The setup for TCP is something like this:
Code: Select alldescription         command                           expected response
====================================================================================================
Begin            ATE0 / AT                        OK

WIFIMode         AT+CWMODE=3                        OK
ConnectionMode      AT+CIPMUX=0                        OK
ApplicationMode      AT+CIPMODE=0                     OK

connected ?         AT+CIPSTATUS                     STATUS:2 (ESP8266_CONNECTED_TO_AP)

Start            AT+CIPMUX?                        CIPMUX:0
               AT+CIPSTART="TCP","x.x.x.x",10000      CONNECT
               
                                             STATUS:3 (ESP8266_CREATED_TRANSMISSION)

where "x.x.x.x" is the IP of my server (i.e., Android app, on same network) at port 10000.

So, it sets application mode to "both station and access point" (3); connection mode to "single" (1); application mode to "normal" (0); and then establishes the TCP connection (on IP x.x.x.x:10000). As I said, this works :) But when I try to follow this guide (https://www.espressif.com/sites/default ... n_v1.3.pdf) to set up UDP "as well", I end up getting error "CIPMUX and CIPSERVER must be 0"

Basically, what I'm trying to modify (with TCP + UDP) is to set connection mode to "multiple" (i.e. AT+CIPMUX:1) and then essentially do,
Code: Select allAT+CIPSTART="TCP","x.x.x.x",10000
AT+CIPSTART=0,"UDP","0.0.0.0",4445

As I understand it, this second line will begin listening for UDP broadcasts on port 4445 -- from any IP address.

Does anyone see what's gone wrong here? CIPMUX must be set to 1 (multiple), right, to use TCP *and* UDP simultaneously?
User avatar
By hobby_guy
#90282 Thanks for replying!
Actually, I am setting connection_id = 0 in both connections, also for TCP. My firmware is configured to set connection ID (which is 0) if connection mode is multiple (CIPMUX:1). Problem is, my configuration never gets to starting the TCP and UDP connections at all; the error occurs when setting the application mode, which causes the AVR to crash and reboot. That shouldn't happen (AVR crash), so I'll look into why that is (I think it might be that the error message from the ESP is simply too many chars, causing a buffer overflow).

In any case, here's the startup/configuration as seen from the AVR (i.e. what it sends to the ESP over UART) as well as the responses from the ESP:

AVR says:

Code: Select allHELLO WORLDATE0
                                                     
AT
                                                                           
HELLO WORLDATE0
                                                     
AT
                                                                           
AT+CIPCLOSE=5
                                                                 
AT+CWMODE=3
                                                                   
AT+CIPMUX=1
                                                                   
AT+CIPMODE=0
                                                                 
AT+CIPSTATUS
                                                                 
HELLO WORLDATE0
                                                     
AT+CIPCLOSE=5
                                                                 
AT+CWMODE=3
                                                                   
AT+CIPMUX=1
                                                                   
AT+CIPMODE=0
                                                                 
                                                                               
                   


ESP responds:
Code: Select allready
WIFI CONNECTED
AT


OK
AT+CIPCLOSE=5

MUX=0

ERROR
WIFI GOT IP
AT+CWMODE=3


OK
AT+CIPMUX=1


OK
AT+CIPMODE=0

CIPMUX and CIPSERVER must be 0


As you might see, the AVR crashes and reboots, as is evident from the initial "HELLO WORLD" message. The AVR begins communicating with the ESP by sending AT/ATE0, waiting for an "OK" response. Then, to allow the AVR to reconnect if it crashes, the AVR attempts to close any TCP connections (CIPCLOSE) before proceeding. This does cause an error from the ESP if no connections exist, but I don't think this is a problem? At least it doesn't seem to affect the "normal" use case, where I only use TCP (CIPMUX=0).