zigpy / zigpy-cc

Texas Instruments Z-Stack ZNP handler for zigpy
https://github.com/zigpy/zigpy-cc
GNU General Public License v3.0
71 stars 13 forks source link

[REQUEST] Allow strength of "TX Power" configuration for modules with Power Amplifier (PA) #33

Open Hedda opened 4 years ago

Hedda commented 4 years ago

Please consider allowing setting "TX power" (TX PWR) on radio modules with Power Amplifier (PA).

Backstory: Some if not all TI CC radio modules feature integrated or external Power Amplifier (PA), a powered RF-amplification frontend, and the amp power that goes to that RF-amplifier should be controllable via software via a configuration setting. All however also have a default setting which is always automatically used if no custom setting is asked for.

For example; the default TX power (TX_PWR) for the CC1352P and CC2652P is 5 dBm, however, these chips support up to a max of 19 dBm (though technical specification says 20 dBm), if you allow the user to control this then they could potentially get better reception if the power to amplification is increased.

See https://github.com/Koenkk/zigbee2mqtt/issues/2253 from Koenkk of Zigbee2mqtt which the same idea and already implemented it as a proof-of-concept to allows setting the transmit power of the adapter for future versions which works for all adapters with Power Amplifiers, including CC2531, CC2530, CC1352P-2 and CC26X2R1, (in his POC allowed values are -22 dBm as the min to 19 dBm as the max, default is 0 except for the CC2530 + CC2591 = 4 and CC2530 + CC2592 = 19).

TI CC modules/chips which features an integrated or external RF-amplifier (PA/LNA) as I understand:

PS: As I understand, the chips have their maximum dBm hardcoded within safe limits so that there is no way to destroy the HW through these settings. It is just that depending on the frequency band, too high dBm values may not be legal outdoors and/or indoors depending on your country regulations, and therefore TI has set a low default value so that it is legal in all countries if one does not increase the values.

Hedda commented 4 years ago

https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread/f/158/t/443496

https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread/f/158/t/523553

The dBm TX power optional values are those mentioned on Table 4.6 in http://www.ti.com.cn/cn/lit/an/swra308a/swra308a.pdf

In the course of my further research I came across an interesting hint within the TI Forum, where an "undocumented" interface of the ZNP is pointed out:

https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread/f/158/p/443496/1593040#1593040

If you use ZNP, you can use the undocumented MT_SYS_STACK_TUNE command to the ZNP with the data for setting the Tx transmit power. It is an SREQ with 2 bytes of data, so

02 21 0F 00 XX where:

02 = 2 bytes of data

21 = SREQ + MT_RPC_SYS_SYS

0F = MT_SYS_STACK_TUNE

00 = STK_TX_PWR

XX = a valid power setting from ZMAC.h:

typedef enum { TX_PWR_MINUS_22 = -22, TX_PWR_MINUS_21, TX_PWR_MINUS_20, TX_PWR_MINUS_19, TX_PWR_MINUS_18, TX_PWR_MINUS_17, TX_PWR_MINUS_16, TX_PWR_MINUS_15, TX_PWR_MINUS_14, TX_PWR_MINUS_13, TX_PWR_MINUS_12, TX_PWR_MINUS_11, TX_PWR_MINUS_10, TX_PWR_MINUS_9, TX_PWR_MINUS_8, TX_PWR_MINUS_7, TX_PWR_MINUS_6, TX_PWR_MINUS_5, TX_PWR_MINUS_4, TX_PWR_MINUS_3, TX_PWR_MINUS_2, TX_PWR_MINUS_1, TX_PWR_ZERO, TX_PWR_PLUS_1, TX_PWR_PLUS_2, TX_PWR_PLUS_3, TX_PWR_PLUS_4, TX_PWR_PLUS_5, TX_PWR_PLUS_6, TX_PWR_PLUS_7, TX_PWR_PLUS_8, TX_PWR_PLUS_9, TX_PWR_PLUS_10, TX_PWR_PLUS_11, TX_PWR_PLUS_12, TX_PWR_PLUS_13, TX_PWR_PLUS_14, TX_PWR_PLUS_15, TX_PWR_PLUS_16, TX_PWR_PLUS_17, TX_PWR_PLUS_18, TX_PWR_PLUS_19 } ZMacTransmitPower_t; // The transmit power in units of -1 dBm.

Hedda commented 4 years ago

@sanyatuning FYI, apparently @puddly has already enabled "TXPower" settings in 3f6968d for zigpy-znp:

https://github.com/zha-ng/zigpy-znp/commit/3f6968d7af53e15d893d92240136bf93ef42f7ed

Hedda commented 4 years ago

Any more thought on allowing configuration of TX Power strength for modules with Power Amplifier?

As per https://github.com/zigpy/zigpy/issues/381 radio schema config extension, which is also same for zigpy-znp radio library:

https://github.com/zha-ng/zigpy-znp/issues/11