UDP- Trouble reading bytes from socket in python?
<p>I'm trying to send 14bit sensor data from a microcontroller to a PC using UDP Protocol. When I send the data and receive it on the <code>package sender</code> application I am getting data in hex as expected.</p>

<p><a href="http://i.stack.imgur.com/xyUBI.jpg" rel="nofollow">Energia Code: </a></p>

<p><a href="http://i.stack.imgur.com/p9xeA.png" rel="nofollow">Python, <code>Package Sender</code> app screenshots</a></p>

<p>Here, I am receiving it as char.</p>

<p>Sensor value in decimal: <code>(855) --- hex(357)</code> higher byte <strong>03</strong>, lower byte <strong>57</strong>. <code>57h</code> is char <code>W</code> in Ascii table</p>

<p>So when received through the socket, python outputs this as <strong>03W</strong></p>

<p>How to receive in hex and convert it to decimal?
Thank you in advance!!</p>

<p>You can use the <code>struct</code> module to unpack it like this:</p>

<pre><code>import struct
data = ['\x03W']
val = struct.unpack('&gt;H', data[0])  # now an integer
</code></pre>

python arduino network-programming udp serversocket