# RSSI in Python

**URL:** <https://forums.digi.com/t/rssi-in-python/2958>\
**Category:** Python\
**Created:** [February 6, 2009, 10:20am UTC](https://forums.digi.com/t/rssi-in-python/2958 "2009-02-06T10:20:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfc\_at\_navipartner.d](https://avatars.discourse-cdn.com/v4/letter/k/8dc957/32.png) [@kfc\_at\_navipartner.d](https://forums.digi.com/u/kfc_at_navipartner.d)\
**Post date:** [February 6, 2009, 10:20am UTC](https://forums.digi.com/t/rssi-in-python/2958/1 "2009-02-06T10:20:33Z")

</div>

Hi all,

I was wondering how I can get the RSSI value from my XBee devices using the Python libraries?

Best regards  
Kenneth

---

<div class="post-metadata">

**Author:** ![Mawr](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Mawr](https://forums.digi.com/u/Mawr)\
**Post date:** [February 6, 2009, 2:16pm UTC](https://forums.digi.com/t/rssi-in-python/2958/2 "2009-02-06T14:16:44Z")

</div>

Hi kfc,

The RSSI value can come in a few different forms from the XBee device. The simplest would be to query the ‘DB’ value from the device to get the RSSI value of the last received packet.

If you are using the python interpreter on a Digi Gateway product, this could be done like so:

import zigbee, struct  
rssi\_raw = zigbee.ddo\_get\_param(‘[00:13:a2:00:40:0a:12:96]!’, ‘DB’)

rssi\_val = struct.unpack(‘=B’, rssi\_raw)

We do two things in the above code. First we query the address ‘[00:13:a2:00:40:0a:12:96]!’ for its DB value using the zigbee.ddo\_get\_param() call, then we use the struct.unpack() function to cast the output of the function as a character.

Casting the output as a character is necessary when receiving data through the ddo\_get\_param() function. Everything received is a binary packed string.

Other methods for getting the RSSI value from a node without using a Digi Gateway are going to depend on your particular setup.

Mawr

---

<div class="post-metadata">

**Author:** ![matalalento](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@matalalento](https://forums.digi.com/u/matalalento)\
**Post date:** [June 5, 2009, 10:40am UTC](https://forums.digi.com/t/rssi-in-python/2958/3 "2009-06-05T10:40:52Z")

</div>

Hi Mawr,

I also utilized your rssi code, thank you for that. Do you know the range for the rssi values it gives? I get something like (37,) or (38,) when the radio and gateway are next to each other and the number gets bigger when distance grows. Does it have some kind of maximum and minimum values? I have connectport X8 gateway and Xbee series 2 modules.

Thanks

-Matalalento-

---

<div class="post-metadata">

**Author:** ![matalalento](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@matalalento](https://forums.digi.com/u/matalalento)\
**Post date:** [June 10, 2009, 8:03am UTC](https://forums.digi.com/t/rssi-in-python/2958/4 "2009-06-10T08:03:59Z")

</div>

Hi again Mawr,

## referring to your code:

import zigbee, struct  
rssi\_raw = zigbee.ddo\_get\_param(‘[00:13:a2:00:40:0a:12:96]!’, ‘DB’)

## rssi\_val = struct.unpack(‘=B’, rssi\_raw)

If the node (in this case [00:13 … :96]) is unavailable the code seems to try to search for the DB value for over 30 seconds before it finally sends and exception error “error fetching DDO parameter”.

Do you know if there would be some timeout for this so I wouldnt need to wait so long in case the node doesnt respond?

thanks again!

-Matalalento-

---

<div class="post-metadata">

**Author:** ![balart40](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@balart40](https://forums.digi.com/u/balart40)\
**Post date:** [June 12, 2009, 4:43pm UTC](https://forums.digi.com/t/rssi-in-python/2958/5 "2009-06-12T16:43:00Z")

</div>

Hi Mawr, Im using the LQI and RSSI, value; first I will want to know in what datasheet is the information about the RSSI value, I already readied the following datasheets:  
ConnectPort X Family Users Guide  
Digi Connect Family  
XBee/XBee-PRO ZB RF Modules

Now, the gateway that Im using (connectport X4 S2 ethernet, X4-B11-E-A) get the LQI values (by python commands) between nodes, for example if we have 3 nodes a, b, c the gateway get the LQI value between the node a and b, a and c, b and c, ¿can i get the RSSI values between the nodes (the same as in the LQI)?, now, ¿the LQI values obtained, are an average of the LQI value of node a with respect to the b and the b with respect to the a? or ¿how the gateway know about the LQI values between nodes?, cause maybe the LQI value obtained from the node a with respect to the b is not the same from the node b with respect to the a.

Any documentation (explaining the LQI and RSSI calculations and description) will be help full, the previous datasheet only explain too little about the both values (explain more about RSSI), here is a list of the devices that Im using:

ConnectPort X4 - ZNet 2.5 with ethernet. (X4-B11-E-A)  
XBee RS-485 Adapter - ZNet 2.5 (formerly Series 2) (XA-B14-CS3R)  
XBee ZB/ZNet 2.5 Development Kit w/ 2 XBee-PRO modules & 3 regular XBee modules (XB24-BPDK)

---

<div class="post-metadata">

**Author:** ![Mawr](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Mawr](https://forums.digi.com/u/Mawr)\
**Post date:** [June 5, 2009, 6:36pm UTC](https://forums.digi.com/t/rssi-in-python/2958/6 "2009-06-05T18:36:52Z")

</div>

Hi Matalalento,

Because the DB register is an 8 bit register, at the very most it will have a range of 0-255. I did a quick check through the manual and its measured in negative dBm, in other words, the lower the number the RSSI value is, the stronger the signal strength. For example, if the code above returns a 20, that indicates a stronger signal then if it returned a 40.

Keep in mind the signal strength is only measuring the last hop of the transmission, and the last received packet. For accurate signal strength testing, one would have to take many measurements over time from each hop on the route.

---

<div class="post-metadata">

**Author:** ![Mawr](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@Mawr](https://forums.digi.com/u/Mawr)\
**Post date:** [June 17, 2009, 5:06pm UTC](https://forums.digi.com/t/rssi-in-python/2958/7 "2009-06-17T17:06:37Z")

</div>

Hi Matalalento,

The amount of time for the command to return varies depending on the following properties and conditions:

If the 16 bit address of the node is not known, a network address discovery takes place. If the 16 bit address node is not discovered at this time, the command will return with an error at this time.

If the 16 bit address is known, but a route is not defined in the transmitter’s routing table, a route discovery will take place. If the route is not discovered, the command will return with an error at this time.

Once the 16 bit address and the route is defined, a transmission will take place.

There are 2 timeout categories defined here:

Transmitting to a router or coordinator  
Transmitting to a child end device

Transmitting to a router or coordinator has its timeout in ms defined to:

3 \* ((50 \* NH) + 100)

NH = 30 (Default on ZB firmware)

3 \* ((50 \* 30) + 100) = 1600 or 1.6 seconds.

Transmitting to a child end device has a timeout dependent on the SP parameter, with the minimum buffer time of 1.2 seconds:

3 \* ((50 \* NH) + (1.2 \* SP))

NH = 30  
SP = 32 (Default on ZB firmware)

3 \* ((50 \* 30) + (1.2 \* 32)) = 4615 or 4.6 seconds

Timeouts can be tricky! The above information only applies to the ZB RF protocol.

Mawr

---

<div class="post-metadata">

**Author:** ![vnrselango](https://avatars.discourse-cdn.com/v4/letter/v/46a35a/32.png) [@vnrselango](https://forums.digi.com/u/vnrselango)\
**Post date:** [September 24, 2010, 10:48am UTC](https://forums.digi.com/t/rssi-in-python/2958/8 "2010-09-24T10:48:02Z")

</div>

HI balart40 , I am in need of the python code to read LQI values Can you help us with your complete code for our work.

---

<div class="post-metadata">

**Author:** ![jordanh](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jordanh](https://forums.digi.com/u/jordanh)\
**Post date:** [June 15, 2009, 4:35pm UTC](https://forums.digi.com/t/rssi-in-python/2958/9 "2009-06-15T16:35:58Z")

</div>

How are you fetching the LQI value? Are you sending a ZDP (ZigBee Device Profile) request to the ZDO endpoint, cluster 0x8031?

If so, the LQI value is defined in the ZigBee specification. The way it is derived is complex and only a portion of it is computed from RSSI.

Jordan

---

<div class="post-metadata">

**Author:** ![balart40](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@balart40](https://forums.digi.com/u/balart40)\
**Post date:** [June 17, 2009, 3:51pm UTC](https://forums.digi.com/t/rssi-in-python/2958/10 "2009-06-17T15:51:49Z")

</div>

Yes I’m requesting the LQI value with the cluster 0x31, i already readied the zigbee specification, my question about the calculation of the LQI because i thought that the zigbee devices of digi have a specific way to calculate it, in the zigbee specification say how to calculate the link cost (3.6.3.1 Routing Cost, pages 413,414) but the variable “pl” (probability of packet delivery on the link l) is not explained.

Does digi zigbee devices have a specific way to calculate the LQI, if so is there documentation about that?

My application is on python, i already getting the LQI values, now that it see that is possible to get the RSSI values (by python) with the previous code:

import zigbee, struct  
rssi\_raw = zigbee.ddo\_get\_param(‘[00:13:a2:00:40:0a:12:96]!’, ‘DB’)

rssi\_val = struct.unpack(‘=B’, rssi\_raw)

With the LQI request i can get the value between nodes (not from nodes to the gateway) with the previous code (or other way by python code )

can i get the RSSI values between nodes?

I ask this cause if not, i want to see if there is a way to calculate RSSI from LQI, and if possible calculate SNR from LQI
