Use API to control GPIO?


#1

I just found API documention here: https://dev.gl-inet.com/router-api/

Does this apply to GL-inet MIFI? If so, is it possible to use the API to control GPIO?


#2

The API is still not yet finished. There is no GPIO API. So if you want to do this need to develop the API.


#3

Do you have example code on how to interact with gpio?


#4

You should ssh to the router. Here is an example.

root@GL-MIFI:/# echo 28 > /sys/class/gpio/export 
root@GL-MIFI:/# echo out > /sys/class/gpio/gpio28/direction 
root@GL-MIFI:/# echo 1 > /sys/class/gpio/gpio28/value
root@GL-MIFI:/# echo 0 > /sys/class/gpio/gpio28/value

You can check the PINOUT to see all available gpios.

https://docs.gl-inet.com/en/3/hardware/mifi/


#5

Thank you, I have tested this but am seeing an issue with GPIO28. When I set it to LOW, it goes to 2.3v instead of 0v. When I go high, it goes to 5v which is correct. I’m trying to use this with this relay: https://www.amazon.com/gp/product/B07M88JRFY/ref=ppx_od_dt_b_asin_title_s00?ie=UTF8&psc=1

In LOW trigger mode. In high trigger mode it works, but not in LOW mode. Any thoughts?


#6

Set it to low, it goes to 0V, and set it to high, it goes to 2.6V.


#7

How do we get an authentication key for the API? I cant’ find any information on how to do that.


#8

Also, I’m having another issue. I’m using GPIO28 with a Sainsmart 1 channel relay. If the relay is connected before the MIFI boots up, the MIFI will not boot. If I unplug the relay, the MIFI will boot up properly, and then I can plug the relay in and it works fine. This is a problem if I cannot keep the relay plugged in during reboots!

Here is the relay I’m using: https://www.amazon.com/gp/product/B0151F3A9Q/ref=ppx_yo_dt_b_asin_title_o03_s00?ie=UTF8&psc=1


#9

You have to call the login at first. http://192.168.8.1/api/router/login?pwd=YOUR PASSWORD


#10

For those that stumble onto this thread, it appears that having a relay plugged into GPIO28 will cause the MIFI to not boot. I have tested other GPIO’s, and the following are tested to work as expected with relays:

GPIO22
GPIO0

Thanks.


#11

You might want to use a relay that has an opto for the signal if you aren’t already and don’t use power from the Mifi too.


#12

I’m integrating the relay into the MIFI so I need to use the MIFI power. I will check and see if I can source an opto relay, I think that makes a lot of sense.


#13

The GPIO is low 0 and 2.6V high. If you have 5V that may mean there is pull up.

Is your relay 5V?


#14

My relay is 5v, but I have read that it works with 3.3v without any issue.


#15

GPIO28 is used for bootstrap, so don’t use it when booting. It needs to be high at booting.

Also don’t connect 5V to the board which may damage the board.