# Fetching JS\_GAIN value

**URL:** <https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192>\
**Category:** General Discussion\
**Tags:** ardusub, pymavlink\
**Created:** [November 11, 2022, 12:31pm UTC](https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192 "2022-11-11T12:31:57Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![elchinaslanli](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/elchinaslanli/32/10461_2.png) [@elchinaslanli](https://discuss.bluerobotics.com/u/elchinaslanli)\
**Post date:** [November 14, 2022, 2:43pm UTC](https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192/3 "2022-11-14T14:43:50Z")

</div>

I combined all the sources you mentioned here: [Reading current gain percentage and flight mode - #2 by EliotBR](https://discuss.bluerobotics.com/t/reading-current-gain-percentage-and-flight-mode/12303/2)

And the code is working, thank you very much. I am putting my final code below:

```auto
from pymavlink import mavutil
import time
# connect to vehicle
# Create the connection
master = mavutil.mavlink_connection('udp:192.168.2.1:14880')
# Wait a heartbeat before sending commands
master.wait_heartbeat()

message_types = {'NAMED_VALUE_FLOAT'}
def handle_named_value_float(msg):
    if msg.name == 'PilotGain':
        print(f'Gain is {msg.value:.2%}')

message_handlers = {
    'NAMED_VALUE_FLOAT': handle_named_value_float,
}

def handle_message(message):
    type_ = message.get_type()
    if type_ in message_handlers:
        message_handlers[type_](message)
    else:
        print(type_)

while True:
    message = master.recv_match(type=message_types, blocking=True)
    handle_message(message)

```

---

_[View the full topic](https://discuss.bluerobotics.com/t/fetching-js-gain-value/13192)._
