GPIO: Read / Write

I’m trying to use the GPIO from python. I’m using the doc at page: Remote Hardware Service | Meshtastic

I can set a PIN to 1 or 0 with a command like:

meshtastic --gpio-wrb 2 1 --dest \!f244c480
meshtastic --gpio-wrb 2 0 --dest \!f244c480

Now I’d like to understand what return the read.

$ meshtastic --port /dev/ttyUSB0 --gpio-rd 0x10 --dest \!f244c480 
Connected to radio
Reading GPIO mask 0x10 from !f244c480
GPIO read response gpio_value=16

What is gpio_value=16 ?

Is it the buffer of the gpio set to output ? Meaning the value of the PIN in Output mode.
Usually on a microcontroller we have to define if a PIN is input or output.
I can’t see any command to set the direction.

Can someone help ?

I guess the answer is somewhere in RemoteHardwarePlugin.cpp

/// Read all the pins mentioned in a mask
static uint64_t digitalReads(uint64_t mask)

pinModes(mask, INPUT_PULLUP);


On a read the code set the PIN to INPUT.

Then I have an issue because when I write en mask 2 (=PIN 2)

meshtastic --gpio-wrb 2 0 --dest \!f244c480
meshtastic --gpio-wrb 2 1 --dest \!f244c480
meshtastic --gpio-wrb 2 0 --dest \!f244c480

I see the PIN moving from 0V to 3V and back to 0V.

But if I read the same PIN 2:

meshtastic --gpio-rd 0x02 --dest \!f244c480

I always get:

Connected to radio
Reading GPIO mask 0x2 from !f244c480
GPIO read response gpio_value=2

When PIN2 is not connected or when PIN2 is set to GND.

I don’t understand.

In the code we have:
// we need to throttle our sending, so that if a gpio is bouncing up and down we
// don’t generate more messages than the net can send. So we limit watch messages to
// a max of one change per 30 seconds