logo elektroda
logo elektroda
X
logo elektroda

[Solved] ESP8266 simultaneous NTP client and UDP server - how to avoid interference?

misiekhardcore 1020 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18609231
    misiekhardcore
    Level 7  
    Hi, I have a problem because I am trying to write a program on the ESP8266. I need such a program in which I simultaneously handle the downloading of time from an NTP server and at the same time I also want to communicate with another device via UDP protocol. Everything would be fine if it wasn't for the fact that when downloading time, we first send data to the NTP server and then parse the packet (working as a client), while communication with the other device starts with parsing the packet first and only then a reply is sent (working as a server). This seems to work somehow, but the two modes often interfere with each other.

    Here is a code snippet with both functions (both work separately without problems):
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #2 18609783
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #3 18609801
    misiekhardcore
    Level 7  
    The interference is that both methods parse the package so it happens that one parses the package that is intended for the other and vice versa. I don't know how to separate this so that both methods work independently so that the parsing can't get mixed up
  • #4 18609821
    Anonymous
    Level 1  
  • #5 18609850
    misiekhardcore
    Level 7  
    Can you be more specific? I'm not that familiar with the subject yet
  • ADVERTISEMENT
  • Helpful post
    #6 18609889
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #7 18609969
    misiekhardcore
    Level 7  
    So should I do a separate udp.begin() with a separate port each time?
  • Helpful post
    #8 18610063
    Anonymous
    Level 1  
  • #9 18610074
    misiekhardcore
    Level 7  
    I honestly didn't come across it, but it has a chance of working. When I do the tests I'll be sure to let you know how it went. I'll create two objects with different ports and see how it goes.
  • #10 18612913
    misiekhardcore
    Level 7  
    @khoam everything worked as you wrote. Creating two separate UDP class objects and assigning separate ports helped. Everything is running smoothly.
    I consider the topic closed

Topic summary

The discussion revolves around the challenge of simultaneously implementing an NTP client and a UDP server on the ESP8266 without interference. The main issue arises from both functions parsing packets, leading to confusion between the NTP and UDP communications. A solution proposed involves using separate UDP class objects with distinct local ports for each function, which successfully resolves the interference problem. The user confirmed that this approach worked effectively, allowing both functionalities to operate independently without packet mixing.
Summary generated by the language model.
ADVERTISEMENT