logo elektroda
logo elektroda
X
logo elektroda

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

heyka 5211 78
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #61 17847992
    heyka
    Level 17  
    I have the code completed, I have learnt a lot thanks to your help, I have one last question in this thread.

    In the following way I check myself in the ESP module the incoming string from the smartphone, while the module responds with a defined char array and it is OK

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

    The following is how I implement the LED timer, after which I turn off the LED and would like to inform the smartphone, I send the char array with the same commands as above, but nothing comes out of the module
    Code: C / C++
    Log in, to see the code
    .

    Are the Udp.remoteIP() and Udp.remotePort() data cleared after response by the module?
  • ADVERTISEMENT
  • #62 17848012
    khoam
    Level 42  
    The variable 'currentTime' is redundant - it is the same as millis() called directly.
    In the condition 'if ( differenceTime >= 6000UL)' you should assign the variable 'rememberedTime' the value millis() - it's like a 'reset', after the set time to turn off the LED.
  • #63 17848043
    heyka
    Level 17  
    khoam wrote:
    The variable 'currentTime' is redundant - it is the same as millis() called directly.
    In the condition 'if ( differenceTime >= 6000UL)' you should assign the variable 'rememberedTime' the value of millis() - it's like a 'reset', after the set time to turn off the LED.
    .

    Ok, thanks :) .

    My code also works but I am aware that it is far from optimal, but this is a normal occurrence for beginners. I still need to create functions to replace repetitive parts of the code, it just needs to be "polished".

    Optimisation welcome at any stage. :)

    But I was referring to sending information from the module when the LED goes off after a set time, nothing is coming out of the module and I wonder if the module is deleting the address and port of the device from which it previously received a request and answered it.
  • ADVERTISEMENT
  • #64 17848049
    khoam
    Level 42  
    heyka wrote:
    But I was referring to sending information from the module when the LED goes off, nothing comes out of the module
    .
    That's because it only goes out once, and because it doesn't do what I described in the second sentence of my previous post.
  • ADVERTISEMENT
  • #65 17848090
    heyka
    Level 17  
    khoam wrote:
    heyka wrote:
    But I was referring to sending information from the module after the LED goes off, nothing comes out of the module
    .
    That's because it only goes out once, and because it doesn't do what I described in the second sentence of my previous post.


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

    This is what I do when the diode is lit, the first code, in the second code I check if the diode is lit, if there is a high state on the pin, if so I check the time that will pass since the diode is lit, if this time exceeds 6000 UL , I turn off the diode, and so I send information about it through the Uart( it comes out) and through WiFi - it does not come out.
  • #66 17848106
    khoam
    Level 42  
    It would be best if you showed all the code, not snippets - it's really hard to get your head around when you're referencing (I think) global variables.
  • ADVERTISEMENT
  • #67 17848158
    heyka
    Level 17  
    Code: C / C++
    Log in, to see the code
    .

    When the LED lights up, I memorise the address and port of the client, then when the LED goes out after a certain time I send info about it to the memorised address and port and everything works just fine. :) .
    To replace such a piece of code


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

    into a function to which I pass a char array as an argument, where can I read about this?
  • #68 17848177
    khoam
    Level 42  
    heyka wrote:
    in a function to which I pass an array of chars as an argument, where to read about it?
    .

    Link .

    There are many other useful lessons there ;) .
  • #69 17848194
    heyka
    Level 17  
    khoam wrote:
    It would be best if you showed all the code, not bits of it - it's really hard to get your head around when you're referencing (I think) global variables.
    .


    All the code, maybe useful for someone to experiment with.

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

    The ESP8266 controls the lighting and extinguishing of the diode when it receives the commands :
    btnW1_ON - lighting up the diode, it confirms this by sending the W1_ON command to the client
    btnW1_OFF - turning off the diode, it acknowledges this by sending the W2_OFF command to the client,

    I send the commands from a smartphone from a program I once wrote in B4A, but you can also use any UDP Terminal downloaded from the Play Store.
    All comments very welcome.

    Many thanks to the Fellows who have helped me on this forum, without whom I would not have got off the ground and learned anything.

    I will be developing the code, I still need to somehow send to the module the time after which the LED on self extinguish and save this in the flash of the Module and I have some other ideas.
  • #70 17848223
    khoam
    Level 42  
    heyka wrote:
    I will develop the code, I still need to somehow send to the module the time after which the diode is automatically extinguished and store this in the module's flash and I have a few more ideas.


    You can store such information in an emulated EEPROM on the ESP8266. The data will be remembered between shutdowns/switches of the module.
    An example is here .
    Clear explanation of what an emulated EEPROM is: Link .
  • #71 17850686
    heyka
    Level 17  
    And how to realise control from a smartphone with, for example, three ESP8266 modules?

    One module I set up as AP creates a WiFi network (main module), and the other 3 ( executive modules) how do I configure? It seems to me that also as AP because they have to listen, I only give them fixed IP addresses.

    And now how do I program the main module, the idea is that the smartphone sends some data to the IP address of one of the working modules. I need the main module to act like a router i.e. receive data and send it to the appropriate address and possibly receive an acknowledgement from the module to the smartphone.
  • #72 17850779
    khoam
    Level 42  
    heyka wrote:
    And how do I implement control from a smartphone with e.g. three ESP8266 modules?
    I set one module as AP creates WiFi network (main module), and the other 3 ( executive modules) how do I configure? I think also as AP because they have to listen, I only give them fixed IP addresses.
    .
    Isn't it enough to have the master module set up in AP mode and the working modules (Station) connect to it to receive instructions?
  • #73 17850876
    heyka
    Level 17  
    Of course it is enough. I didn't think.

    Added after 48 [minutes]: .

    I've been looking for code to create a router from the ESP module, but can't find anything.
  • #74 17851154
    khoam
    Level 42  
    heyka wrote:
    I searched for code to create a router from the ESP module, but can't find anything.
    .
    It's going to be rather difficult for you to run the AP+Station on the ESP-01. It supposedly says in the documentation that you can, but I haven't managed to get it to work properly. If you find a hint, let me know ;) .

    Here is an explanation of why there is a problem with AP+Station mode.

    Added after 31 [minutes]: .

    heyka wrote:
    I searched for code to create a router from an ESP module,
    .
    At most, NAT router : Link
  • #75 17854260
    heyka
    Level 17  
    khoam wrote:
    .
    At most NAT router : 27cff85e1fd Link[/url]


    I don't know how it works, the cheapest and surest way would be to buy a regular router like: Link
  • #77 17869987
    heyka
    Level 17  
    How do I set a fixed IP address for a module operating in STA mode?
  • #78 17870157
    khoam
    Level 42  
    heyka wrote:
    How do you set the static IP address of a module running in STA mode?
    .
    Do you mean static addressing in Station mode? Here you have examples: Link , Link .
  • #79 17870242
    heyka
    Level 17  
    Thanks to

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

    I didn't specify all the parameters, it's OK now.

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.
Summary generated by the language model.
ADVERTISEMENT