# Reading ZMQ messages in Python

**URL:** <https://www.ruby-forum.com/t/reading-zmq-messages-in-python/243302>\
**Category:** GNU Radio\
**Created:** [September 8, 2015, 9:54pm UTC](https://www.ruby-forum.com/t/reading-zmq-messages-in-python/243302 "2015-09-08T21:54:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [September 8, 2015, 9:54pm UTC](https://www.ruby-forum.com/t/reading-zmq-messages-in-python/243302/1 "2015-09-08T21:54:33Z")

</div>

Hello,

I have a flowgraph that send ZMQ PUB messages generated by a custom  
OOT block. The messages transmitted by GNURadio ZMQ PUB block are  
received by a Python application, using a standard ZMQ Library.

[custom\_oot\_block] —(GNURadio message)—\> [ZMQ Publisher]  
…(ethernet)…\> [Python ZMQ SUB Library]

This is the part of the code of the OOT block that creates the message:

* * *

float \*outPdPfa = (float \*) output\_items[0];

## pmt::pmt\_t msg = pmt::init\_f32vector(1, outPdPfa); message\_port\_pub(pmt::mp(“hard\_decision”), msg);

In Python, I receive the transmitted message and this is some of the  
strings that are received:

‘\n\x08\x00\x00\x00\x01\x01\x00?\xe4\xbe\x83\x00\x00\x00\x00’  
‘\n\x08\x00\x00\x00\x01\x01\x00?\xe5R\xb5 \x00\x00\x00’  
‘\n\x08\x00\x00\x00\x01\x01\x00?\xe4B0\xa0\x00\x00\x00’  
‘\n\x08\x00\x00\x00\x01\x01\x00?\xe4\xa3\\xa0\x00\x00\x00’  
‘\n\x08\x00\x00\x00\x01\x01\x00?\xe5jV\xa0\x00\x00\x00’  
‘\n\x08\x00\x00\x00\x01\x01\x00?\xe4\xf8\x00\x00\x00\x00\x00’  
‘\n\x08\x00\x00\x00\x01\x01\x00?\xe4\x90\x00\x00\x00\x00\x00’

How do I convert these strings to a floating number value?

Thank you.

Regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![Daniel\_Mazzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Daniel\_Mazzer](https://www.ruby-forum.com/u/Daniel_Mazzer)\
**Post date:** [September 8, 2015, 11:16pm UTC](https://www.ruby-forum.com/t/reading-zmq-messages-in-python/243302/2 "2015-09-08T23:16:56Z")

</div>

try struct.unpack()

---

<div class="post-metadata">

**Author:** ![Daniel\_Mazzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Daniel\_Mazzer](https://www.ruby-forum.com/u/Daniel_Mazzer)\
**Post date:** [September 8, 2015, 11:29pm UTC](https://www.ruby-forum.com/t/reading-zmq-messages-in-python/243302/3 "2015-09-08T23:29:12Z")

</div>

Hi,

the “right way” to do this is use PMT’s python bindings:

import pmt  
s=’\n\x08\x00\x00\x00\x01\x01\x00?\xe4\xbe\x83\x00\x00\x00\x00’  
p = pmt.deserialize\_str(s)  
python\_numpy\_array = pmt.pmt\_to\_python.pmt\_to\_python§

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![Daniel\_Mazzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Daniel\_Mazzer](https://www.ruby-forum.com/u/Daniel_Mazzer)\
**Post date:** [September 9, 2015, 1:55am UTC](https://www.ruby-forum.com/t/reading-zmq-messages-in-python/243302/4 "2015-09-09T01:55:50Z")

</div>

Hi Marcus,

I was missing the “deserialize” call. I’ll try it tomorrow.

Thank you.  
Regards,  
Daniel
