<pre style="background-color: #ffffff; border: 0px; border-radius: 0px; box-sizing: border-box; overflow-x: auto; width: 658.906px; color: #434f54; tab-size: 2;">
   <code class="language-fallback" data-lang="fallback" style="background-color: #f7f9f9; color: #000000; padding: 0px;"><span style="font-size: 12px;">EthernetUDP Udp;
void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
}
void loop() {
  Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
  Udp.write("hello");
  Udp.endPacket();
}</span></code>
   <br /></pre>
<pre style="background-color: #ffffff; border: 0px; border-radius: 0px; box-sizing: border-box; overflow-x: auto; width: 658.906px; color: #434f54; font-size: 16px; tab-size: 2;">
   <code class="language-fallback" data-lang="fallback" style="background-color: #f7f9f9; color: #000000; font-size: 14px; padding: 0px;"><span style="font-size: 12px;">================================================================
// if there's data available, read a packet</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8;"></span><span class="hljs-keyword" style="box-sizing: inherit; color: #333333; font-weight: bold; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">int</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;"> packetSize = Udp.parsePacket();
  </span><span class="hljs-keyword" style="box-sizing: inherit; color: #333333; font-weight: bold; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">if</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;"> (packetSize) {
    Serial.print(</span><span class="hljs-string" style="box-sizing: inherit; color: #dd1144; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">"Received packet of size "</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
    Serial.println(packetSize);
    Serial.print(</span><span class="hljs-string" style="box-sizing: inherit; color: #dd1144; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">"From "</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
    IPAddress remoteIp = Udp.remoteIP();
    Serial.print(remoteIp);
    Serial.print(</span><span class="hljs-string" style="box-sizing: inherit; color: #dd1144; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">", port "</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
    Serial.println(Udp.remotePort());
    </span><span class="hljs-comment" style="box-sizing: inherit; color: #999988; font-style: italic; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">// read the packet into packetBufffer</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8;"></span><span class="hljs-keyword" style="box-sizing: inherit; color: #333333; font-weight: bold; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">int</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;"> len = Udp.read(packetBuffer, </span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">32</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
    </span><span class="hljs-keyword" style="box-sizing: inherit; color: #333333; font-weight: bold; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">if</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;"> (len &gt; </span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">0</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">) {
      packetBuffer[len] = </span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">0</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">;
    }
      Serial.print(</span><span class="hljs-string" style="box-sizing: inherit; color: #dd1144; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">"Contents:"</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">); Serial.println(packetBuffer);
      </span><span class="hljs-comment" style="box-sizing: inherit; color: #999988; font-style: italic; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">// send a reply, to the IP address and port that sent us the packet we received</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">
      Udp.beginPacket</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">(Udp.remoteIP(), Udp.remotePort());
      </span><span class="hljs-built_in" style="box-sizing: inherit; color: #0086b3; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">memset</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">(temp, </span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">0x00</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">, </span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">64</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
      </span><span class="hljs-built_in" style="box-sizing: inherit; color: #0086b3; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">sprintf</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">(temp, </span><span class="hljs-string" style="box-sizing: inherit; color: #dd1144; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">"TEST"</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
      </span><span class="hljs-built_in" style="box-sizing: inherit; color: #0086b3; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">sprintf</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">(temp, </span><span class="hljs-string" style="box-sizing: inherit; color: #dd1144; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">"Current: %d.%d mA Voltage:%d.%d V"</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">, 
        (</span><span class="hljs-keyword" style="box-sizing: inherit; color: #333333; font-weight: bold; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">int</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">)average, (</span><span class="hljs-keyword" style="box-sizing: inherit; color: #333333; font-weight: bold; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">int</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">)(average*</span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">10</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">) % </span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">10</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">,    
        (</span><span class="hljs-keyword" style="box-sizing: inherit; color: #333333; font-weight: bold; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">int</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">)loadvoltage, (</span><span class="hljs-keyword" style="box-sizing: inherit; color: #333333; font-weight: bold; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">int</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">)(loadvoltage*</span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">10</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">) % </span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">10</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);    
      Udp.write(temp); </span><span class="hljs-comment" style="box-sizing: inherit; color: #999988; font-style: italic; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">// ReplyBuffer);</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">
      Udp.endPacket();
      delay(</span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">5</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
      Udp.stop();
      delay(</span><span class="hljs-number" style="box-sizing: inherit; color: #008080; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">5</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
      Serial.println(</span><span class="hljs-string" style="box-sizing: inherit; color: #dd1144; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">"\nStarting connection to server..."</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
      </span><span class="hljs-comment" style="box-sizing: inherit; color: #999988; font-style: italic; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">// if you get a connection, report back via serial:</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">
      Udp.begin(localPort);
      Serial.print(</span><span class="hljs-string" style="box-sizing: inherit; color: #dd1144; font-family: monospace, monospace; white-space: pre-wrap; font-size: 12px;">"Listening on port "</span><span style="color: #333333; font-family: monospace, monospace; white-space: pre-wrap; background-color: #f8f8f8; font-size: 12px;">);
      Serial.println(localPort);      
  }</span></code>
   </pre>