The Device Network
Your IP Address is:


  • Using UDP protocol with Arduino

    Posted on Fri January 4, 2013

    The KSduino uses UDP to connect Arduino to Internet to show device parameters at KSduino web site.

    The UDP history:

    The User Datagram Protocol (UDP) is one of the core members of the Internet protocol suite, the set of network protocols used for the Internet. With UDP, computer applications can send messages, in this case referred to as datagrams, to other hosts on an Internet Protocol (IP) network without prior communications to set up special transmission channels or data paths. The protocol was designed by David P. Reed in 1980 and formally defined in RFC 768.

    UDP is most quick of basic Internet Protocols. But the UDP protocol does not guarantee 100% packet delivery since UDP has no built-confirmation as TCP for example. Stable connection using UDP releases using software protocols.

    About KSduino UDP send-receive algorithm:

    Sending and receiving UDP packets embedded in KSduino Library that can be downloaded from the DOWNLOADS.

    There are two modes to send values:

    1. synchronous
    2. asynchronous (default)

    See functions where these modes uses: http://ksdu.in/o/22

    In synchronous method we send value and are waiting answer from server. When we use this method we have not lost packets because KSduino waits for answer and repeat packets if it does not get answer during timeout. This method should be used with critical values. But this method takes lot of time from sketch: time minimum = ping to server time 3-4 milliseconds. This is not acceptable for normal operation! So we created another one - asynchronous mode.

    In asynchronous mode we send value, save it packet number to Queue and don’t wait answer after send. It takes only 1 - 3 milliseconds as ksd.getLoopTime() shows. We get a response from servers at next loops and check the Queue. We do not save sent Values because Arduino has not memory for it. So from time to time we have lost packets and wrong packets.

    In this method:

    Lost packet means: we have not got response from server but we don’t sure that server hoes not got this value;

    Wrong packet means: the server (or network) sends something that we are not waiting now! It may be some lost packet which going to long or broadcast or some parasite UDP network packet. We check only packets we are waiting now and drop all other. In most case Wrong packets - is packets which we don’t get during timeout. Arduino has low memory to save packets we send so we decided to have lost packets instead of spending time.

    In most case Lost packet means we don’t got response during timeout. But it’s not real lost packet.

    Best regards,
    Kirill Scherba
    The founder and main developer of KSduino project.

  • comments powered by Disqus
Created with KSNews


Copyright © 2012-2013, The KSduino Project