5

I have a robot (using the Raspberry Pi 3) outside my home with no internet connection, and I want to remotely access like this my Raspberry Pi's desktop. How can I do this?

Perhaps if I get this module with a SIM card and connect it to Raspberry Pi it'll have a 3G or 4G connection. Can do it with this module?

How would I configure this module, what would I have to do to make the Raspberry Pi connect automatically when I turn it on? After connecting to 4G, can I access the Raspberry Pi via VNC?

11
  • 2
    Ah, let me see. Your project sounds interesting. Let me summarize your situation and goal: (1) You have a laptop at home. Can I assume you have a WiFi network at home and the laptop is connected to the WiFi network? If your home has no WiFi network, then skip (2) and jump to (3). (2) You have a Rpi3 based robot outside and you want to control your robot using your laptop. I think you can connect your Rpi3 to the same WiFi network. Then you can use your laptop to VNC control your Rpi3 Robot. / 同continue, ...
    – tlfong01
    Mar 24, 2020 at 14:45
  • 1
    In my home I have internet connection (the laptop is connected to the wifi),but I need a SIM808 module to connect it to raspberry pi to have 4G connection from everywhere(because the robot will be far away from home). So, my problem is : What AT commands(for python) should I use to enable 4G for raspberry pi??? After,I can use my laptop to VNC control the Robot. Can anyone know any link about "enable 4G in raspberry pi"??? I searched ,but I didn't find anything. Thanks!!! Mar 24, 2020 at 15:14
  • 2
    What is the max. distance between laptop and RasPi? Please address me with @Ingo otherwise I won't see your reply.
    – Ingo
    Mar 24, 2020 at 15:18
  • 2
    max distance = 50-150 meters Mar 24, 2020 at 15:22
  • 2
    @Nick_Gkoutzas, I reccomend you just connect to wifi.
    – user96931
    Mar 24, 2020 at 18:27

1 Answer 1

4

This might be a bit late but I have recently used 4G in combination with my Raspberry Pi. The usecase I had is somewhat different but should have the same steps to setup the 4G connection (I used a webserver on my Pi to have endpoints I could access from my PC).

First off, what I used:

  • A Raspberry Pi LTE Hat (in my case equipped with the SIM7600E)
  • Raspberry Pi 3b+
  • A SIM card with an APN (provided by your provider).

Now for the steps to setup the connection, at first I thought aswell that I have to do a lot of AT commands to setup things. I wasted a lot of time by reading through all the commands and tutorials describing what to do, and for me that just didn't work. Eventually, I found this tutorial, which I tried on my Pi, but resulted in some errors. I found out the cause of these errors and fixed them with slight changes. The errors I encountered are explained by NOTE, but you can ignore them if you do not understand them).

So here we go:

0. Setting up the hardware

Setting up the hardware is quite simple. You attach the hat onto the pi and connect the usb from the pi to the (micro) usb port on the hat (do not connect it to the usb-to-uart, that will not work).

I recommend to only connect the usb-to-usb connection whenever you are done with installing and updating the pi (so after 1.), just to be completely sure :)

Raspberry Pi setup with 4G Hat

1. Updating the Pi

First we make sure the Pi is up-to-date with everything by running the following commands:

  • sudo apt update -y

  • sudo apt dist-upgrade -y

  • sudo rpi-update

And then reboot.

Now we will install the libraries that we will use to setup the 4G connection:

  • sudo apt install libqmi-utils
  • sudo apt install udhcpc

(Note: in the tutorial this was sudo apt install libqmi-utils && udhcpc, however for me this did not work as it treats udhcpc as a command to be executed after sudo apt install libqmi-utils, but udhcpc is not installed yet... So doing 2 seperate installs is safe.)

Some explanation for the libraries taken from the tutorial I mentioned:

libqmi-utils installs libraries that allow you to interact with Qualcomm-based modems. SIM7600 comes with a Qualcomm MDM9607 chipset. udhcpc is used for modem DHCP leasing. The cellular network gives a unique IP to the HAT and the Pi will have its own IP. This is used to solve IP addressing conflicts between the Pi and the HAT.

Now we enable UART to communicate with the device:

  • sudo raspi-config

This should prompt an interface where you should the following:

  • Go to 3 Interface Options
  • Go to P6 Serial Port
  • Select No when asked Would you like a login shell to be accessible over serial? and then select Yes for the second question afterwards.

2. Configuring the SIM7600 module

Now we will configure our SIM7600E module. To turn on the module we will use the qmicli commands (installed before in step 1). Activate the device with:

  • sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'

We can now verify the status of our module (optional but recommended):

  • To see if it is online: sudo qmicli -d /dev/cdc-wdm0 --dms-get-operating-mode
  • To see the signal strength and quality values: sudo qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength
  • To see the carrier name: sudo qmicli -d /dev/cdc-wdm0 --nas-get-home-network

You should now be able to see a wwan0 interface in net-stats (use ifconfig), wwan0 is the default interface this device uses.

Now for the last steps, we configure the module to user raw-ip protocol:

  • sudo ip link set wwan0 down
  • echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip
  • sudo ip link set wwan0 up

And now we can connect to a mobile network:

  • sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='YOUR_APN', auth=BOTH,username='YOUR_USERNAME',password='YOUR_PASSWORD',ip-type=4" --client-no-release-cid

Don't forget to change the APN, username and password :)

(NOTE: In the tutorial the --device-open-net had the value net-no-qosheader which clearly misses -, it should be net-no-qos-header according to the documentation. Moreover, I had to set the authentication type to BOTH, which was not configured in the tutorial I mentioned. This might depend on your provider.)

Finally, we set the default route and IP using udhcpc:

  • sudo udhcpc -i wwan0 And tell the udhcpc library to receive a DHCP lease from the network:
  • ip a s wwan0

And we are done, you should now be able to use 4G on your pi!

Some sidenotes

Now some notes, everytime you reboot your pi, you need to receive a DHCP lease again. So you would have to repeat some of the steps (which you can put in a script). Steps should be:

  • sudo ip link set wwan0 down
  • echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip
  • sudo ip link set wwan0 up
  • sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='YOUR_APN', auth=BOTH,username='YOUR_USERNAME',password='YOUR_PASSWORD',ip-type=4" --client-no-release-cid
  • sudo udhcpc -i wwan0
  • ip a s wwan0

I, myself, have not yet tried automating this at startup, however I have seen some articles on the internet that do say it can be a bit tough. Apparently, a kernel uses the /sys/class/net/wwan0/qmi/raw_ip file at boot, so we cannot temper with that at boot. And thus we cannot execute the first part of our steps that I mentioned above. If you manage to get this working on reboot, please let me know! :)

Additionally, I would like to say that I used this specific 4G hat because it was easily available. I am pretty sure you can do with a cheaper one (even without GSM), as long as you have the SIM7600 module.

Furthermore, I want to give big credits to the tutorial I mentioned, they really gave all of the information and I just fixed some things that did not work for me. So credits should go to them.

I hope this helped any of you, I have been struggling with finding much information on the internet about setting up a 4G connection and hope I will save some of your time!

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.