crazydiam0nd
Posts: 2
Joined: Thu May 07, 2020 9:30 am

Re: 4G Hat

Sat May 09, 2020 1:27 pm

Hi, great instructions and have obtained ip
For some reason mine crashes the PI as soon as I go to ping google.
Any ideas why?

trejan
Posts: 3064
Joined: Tue Jul 02, 2019 2:28 pm

Re: 4G Hat

Sat May 09, 2020 1:49 pm

crazydiam0nd wrote:
Sat May 09, 2020 1:27 pm
Hi, great instructions and have obtained ip
For some reason mine crashes the PI as soon as I go to ping google.
Any ideas why?
Most likely cause is insufficient power. Current consumption of the modem is significantly higher once you're actively communicating with something.

crazydiam0nd
Posts: 2
Joined: Thu May 07, 2020 9:30 am

Re: 4G Hat

Tue May 12, 2020 4:05 pm

trejan wrote:
Sat May 09, 2020 1:49 pm
crazydiam0nd wrote:
Sat May 09, 2020 1:27 pm
Hi, great instructions and have obtained ip
For some reason mine crashes the PI as soon as I go to ping google.
Any ideas why?
Most likely cause is insufficient power. Current consumption of the modem is significantly higher once you're actively communicating with something.
Was powered from a 5A supply so that wasn't even a concern.
Turns out its EMI that crashes the Pi Zero.

I moved the HAT away, used quality USB cable and shielded the PI.
Then another issue developed where the IP would change back to 169.x.x.x
This is on an IOT-HAT Sim7000e

Given up on this Sim7000e for now and may buy a 7600, but are you managing to get a PPP connection with one thats stable?
I don't want to use AT commands for my AWS IOT project.
I need something reliable that gives me internet connectivity, GPNS and through headless Pi

Ideas welcome

PetruVW
Posts: 1
Joined: Wed May 13, 2020 2:35 pm

Re: 4G Hat

Wed May 13, 2020 2:43 pm

Hi

Could somebody with a working setup please post the output of AT+CUSBPIDSWITCH? I changed mine to 9011,1,1 reading a different post and did not record the initial state.

Thanks

rpiserialseek
Posts: 2
Joined: Sat May 16, 2020 3:36 am

Re: 4G Hat

Sat May 16, 2020 3:42 am

Hello everyone,

Glad i stumbled upon this post because it helped me a lot to setup my Waveshare SIM7600 4G hat with a Raspberry pi !

I managed to make it work and use 4g network with UART and USB, but now i'd like to use it only from UART but my issue is that the speed is really (really) low !

The fastest i managed to make it work is something like 0.05 Mbits/s in download speed.. !

But when i connect it over USB (with same SIM card) using the steps detailed in this post i can achieve full speed (17Mbits/s) so i'd like to know if there are any settings that i could tweak to have a fastest speed using ONLY UART ?

Baudrate is : 115200 and i think it might be the issue here :idea:

Thanks in advance

trejan
Posts: 3064
Joined: Tue Jul 02, 2019 2:28 pm

Re: 4G Hat

Sat May 16, 2020 2:34 pm

rpiserialseek wrote:
Sat May 16, 2020 3:42 am
Baudrate is : 115200 and i think it might be the issue here :idea:
You need to use USB if you want to get the full speed of your connection. 115200 is 0.1Mbps which is why you're seeing ~0.05Mbps after overhead.

SIM7600 is capable of driving its UART at up to 4Mbps according to the datasheet. You'll need to use the full featured PL011 UART on the Pi and set it up for hardware handshaking. You still won't be able to get the full speed of your 4G connection though. USB will be a much better option if you can do it.

busseanlagen
Posts: 3
Joined: Sun Mar 12, 2017 8:49 pm

Re: 4G Hat: Signal loss

Sat May 16, 2020 6:48 pm

How do you guys handle signal loss and auto reconnect?

I use a script that pings 8.8.8.8 every 10 seconds and if the connection goes down it just executes the given commands to reestablish a connection. Unfortunately after a few days I get an error: "Couldn't create client for the 'wds' service - CID allocation failed" which tells me that I have too many active CIDs. Currently I think about saving the previous CIDs and PHDs and stop the qmicli request so that the CIDs get released.
Do you think that's the way to go or do you have any other ideas?

rpiserialseek
Posts: 2
Joined: Sat May 16, 2020 3:36 am

Re: 4G Hat

Sat May 16, 2020 11:46 pm

trejan wrote:
Sat May 16, 2020 2:34 pm
rpiserialseek wrote:
Sat May 16, 2020 3:42 am
Baudrate is : 115200 and i think it might be the issue here :idea:
You need to use USB if you want to get the full speed of your connection. 115200 is 0.1Mbps which is why you're seeing ~0.05Mbps after overhead.

SIM7600 is capable of driving its UART at up to 4Mbps according to the datasheet. You'll need to use the full featured PL011 UART on the Pi and set it up for hardware handshaking. You still won't be able to get the full speed of your 4G connection though. USB will be a much better option if you can do it.
Thanks a lot for taking time to answer me !

I already used this module with USB and like you said in this case there is the full speed of the 4G connection, but sadly in this project i cannot use the USB interface of the raspberry and have no other choices than to use UART only !

Any ideas on how i could setup the RPI zero to a baudrate capable of at least 2Mbits/s and do the same with the 4G module ?

I've read about AT+IPR command used to set the baud rate but not sure which values to set..

jimenaleon
Posts: 1
Joined: Thu May 21, 2020 9:00 pm

Re: 4G Hat

Thu May 21, 2020 9:08 pm

Hi,
I'm trying to follow the instructions but after I download the libraries and I run the first command.

Code: Select all

sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
I have an error that is

Code: Select all

error: couldn't create QmiDevice: Couldn't query file info: Error when getting information for file “/dev/cdc-wdm0”: No such file or directory
Somebody know why this is happen and how can I fix this, thank you.

Pintovski
Posts: 4
Joined: Tue May 26, 2020 12:23 am

Re: 4G Hat

Tue May 26, 2020 1:05 am

Thank you all for your posts... they got me through to have my setup 100% operational.

I leave here some comments for anyone that is interested, specially to my future self next time I browse the internet about this issue.

(Hello to me!!... I know you will need this post in a couple of years!!!!)

Feel free to propose changes and improve... :)

My needs
I want to have 4G automatically after boot with no user intervention
I also want to be able to have 4G + SMS/GPS/... at the "same time" without compromising functionalities

My setup
My setup is a Raspberry Pi 4 model B
I am running DietPi OS
I have the jumper in B
I have an USB-C cable connecting the USB-C port of the HAT to a normal USB on the Raspberry Pi 4 (I am using a 3.0 USB port)

Comment 1 - I don't want to press the button!
Normally it is required to press the PWRKEY manually. However there is a note in the manual (pg. 9) that is worthwhile copying here:
"The default hardware of SIM7600CE4GHAT needs to be turned on by button. If the hardware needs to be turned on automatically, you can use a connection line to connect the PWR and GND pins on the module pin, so that it can automatically turn on, as shown in the figure below."
https://www.waveshare.com/w/upload/6/6d ... ual-EN.pdf

Comment 2 - My script
I followed mostly what was mentioned in the posts of this forum. However, I needed to include some extra steps to make it work for me.
In this post I include the script that I am using. It has some extra lines of coding with output, feel free to remove those, but be careful because it uses the log file to check for errors.

Comment 3 - What is my APN?
If you don't know... don't bother your communication provider! Just put the SIM card in a cellphone and check in the settings what are the provider details. I use android for that and it is super easy. Just google it.

Comment 4 - Running at boot
Running at each boot in the Raspberry Pi is super easy. Just copy the script file to "/var/lib/dietpi/postboot.d/" all files that are in that folder will be run after each boot with sudo priveliges.

However, for this procedure to work and be registered in a network, it is important to be able to check for errors and keep trying to connect until it works. That is why you see "While" in the script.

The script

1. Change the PATH variables in the script to match your specific project.
2. Change the "sudo qmicli -p -d /dev/cdc-wdm0 ..." line to match your APN, etc...
3. Just copy into a new file.
4. Don't forget to "chmod +x [YOUR-FILENAME]" to make it executable.

ENJOY!

Code: Select all

#!/bin/bash
LOG_PATH="/home/joao/scripts/log_scripts/4G.log"
sim7600_4G_hat_init_PATH = "/home/joao/scripts/4G-HAT/SIM7600X-4G-HAT-Demo/Raspberry/c/sim7600_4G_hat_init"
MAX_TRIES=20

N_TRY=0
TRY=""

echo "Logs go to: $LOG_PATH"
rm $LOG_PATH

echo "---------------------------------" > "$LOG_PATH"
echo "Connecting 4G-LTE" >> "$LOG_PATH"
echo "-check hat net led---------------" >> "$LOG_PATH"
echo "-sim7600_4G_hat_ini--------------" >> "$LOG_PATH"

echo "$LOG_PATH"
echo "---------------------------------"
echo "Connecting 4G-LTE"
echo "-check hat net led---------------"
echo "-sim7600_4G_hat-ini--------------"

sh "$sim7600_4G_hat_init_PATH" >> "$LOG_PATH"

while [ "$TRY" != "done" ]
do
   N_TRY=$((N_TRY + 1))

   echo "--try $N_TRY --" >> "$LOG_PATH"
   echo "--try $N_TRY --"

   echo "--dms SET operating mode--" >> "$LOG_PATH"
   echo "--dms SET operating mode--"

   sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online' >> "$LOG_PATH"

   echo "--dms GET operating mode--" >> "$LOG_PATH"
   echo "--dms GET operating mode--"

   sudo qmicli -d /dev/cdc-wdm0 --dms-get-operating-mode >> "$LOG_PATH"

   if [ "$N_TRY" = "$MAX_TRIES" ]
   then

      echo "reached MAX_TRIES = $MAX_TRIES" >> "$LOG_PATH"
      echo "reached MAX_TRIES = $MAX_TRIES"

      TRY="done"
   fi
   temp="$(grep -c "online" "$LOG_PATH")"

   if [ $temp -eq 1 ]
   then
      echo "Success! <0.0>" >> "$LOG_PATH"
      grep "online" "$LOG_PATH" >> "$LOG_PATH"

      echo "Success! <0.0>"
      grep "online" "$LOG_PATH"

      TRY="done"
   fi
done

echo "Needed $N_TRY tries to connect" >> "$LOG_PATH"
echo "-get-signal-strength-------------" >> "$LOG_PATH"

echo "Needed $N_TRY tries to connect"
echo "-get-signal-strength-------------"


sudo qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength >> "$LOG_PATH"

tail -14 "$LOG_PATH"

echo "-get-home-network----------------" >> "$LOG_PATH"

echo "-get-home-network----------------"

sudo qmicli -d /dev/cdc-wdm0 --nas-get-home-network >> "$LOG_PATH"

echo "- -w ----------------------------" >> "$LOG_PATH"

echo "- -w ----------------------------"

sudo qmicli -d /dev/cdc-wdm0 -w >> "$LOG_PATH"

echo "-wwan0 down----------------------" >> "$LOG_PATH"

echo "-wwan0 down----------------------"

sudo ip link set wwan0 down >> "$LOG_PATH"

echo "-raw_ip -> Y---------------------" >> "$LOG_PATH"

echo "-raw_ip -> Y---------------------"

echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip >> "$LOG_PATH"

echo "-wwan0 up------------------------" >> "$LOG_PATH"

echo "-wwan0 up------------------------"

sudo ip link set wwan0 up >> "$LOG_PATH"

echo "-get-autoconnect-settings--------" >> "$LOG_PATH"

echo "-get-autoconnect-settings--------"

sudo qmicli -d /dev/cdc-wdm0 --wds-get-autoconnect-settings >> "$LOG_PATH"

echo "-set-autoconnect-settings--------" >> "$LOG_PATH"

echo "-set-autoconnect-settings--------"

sudo qmicli -d /dev/cdc-wdm0 --wds-set-autoconnect-settings=disabled >> "$LOG_PATH"

tail -2 "$LOG_PATH"

echo "if error 26 -> its ok. It means that autoconnect was already disabled" >> "$LOG_PATH"
echo "-start network-------------------" >> "$LOG_PATH"

echo "if error 26 -> its ok. It means that autoconnect was already disabled"
echo "-start network-------------------"

N_TRY=0
TRY=""
while [ "$TRY" != "done" ]
do
   N_TRY=$((N_TRY + 1))

   echo "--try $N_TRY --" >> "$LOG_PATH"
   echo "--try $N_TRY --"

# CHANGE THIS NEXT LINE TO MATCH YOUR COMMUNICATION PROVIDER
   sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='net2.vodafone.pt',ip-type=4" --client-no-release-cid >> "$LOG_PATH"

   if [ "$N_TRY" = "$MAX_TRIES" ]
   then

      echo "reached MAX_TRIES = $MAX_TRIES" >> "$LOG_PATH"
      echo "reached MAX_TRIES = $MAX_TRIES"

      TRY="done"
   else
      echo "...$N_TRY of $MAX_TRIES: unable to start network. Trying again in 5s."
      sleep 5
   fi
   temp="$(grep -c "\[/dev/cdc-wdm0\] Network started" "$LOG_PATH")"

   if [ $temp -eq 1 ]
   then
      echo "...$N_TRY of $MAX_TRIES: Success!" >> "$LOG_PATH"
      grep "\[/dev/cdc-wdm0\] Network started" "$LOG_PATH" >> "$LOG_PATH"

      echo "...$N_TRY of $MAX_TRIES: Success!"
      grep "\[/dev/cdc-wdm0\] Network started" "$LOG_PATH"

      TRY="done"
   fi
done

echo "network started ?"
echo "network started ?" >> "$LOG_PATH"

echo "-start---------------------------" >> "$LOG_PATH"

echo "-start---------------------------"

sudo qmi-network /dev/cdc-wdm0 start >> "$LOG_PATH"

echo "-udhcpc--------------------------" >> "$LOG_PATH"

echo "-udhcpc--------------------------"

sudo udhcpc -t 10 -i wwan0 >> "$LOG_PATH"

echo "-ip a s--------------------------" >> "$LOG_PATH"

echo "-ip a s--------------------------"

ip a s wwan0 >> "$LOG_PATH"

echo "-ip r s--------------------------" >> "$LOG_PATH"

echo "-ip r s--------------------------"

ip r s >> "$LOG_PATH"

echo "-ifconfig------------------------" >> "$LOG_PATH"
echo "ifconfig" >> "$LOG_PATH"
echo "---------------------------------" >> "$LOG_PATH"
ifconfig wwan0

ifconfig >> "$LOG_PATH"

echo "-manufacturer--------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-manufacturer >> "$LOG_PATH"

echo "-model---------------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-model >> "$LOG_PATH"

echo "-firmware------------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-revision >> "$LOG_PATH"

echo "-IMEI----------------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-ids >> "$LOG_PATH"

echo "-SIM-status----------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --uim-get-card-status >> "$LOG_PATH"

echo "-qmicli version------------------" >> "$LOG_PATH"
sudo qmicli --version >> "$LOG_PATH"

echo "-final-testing-------------------" >> "$LOG_PATH"
sudo ping -c 1 -I wwan0 8.8.8.8 >> "$LOG_PATH"

echo "-final-testing-------------------"
#sudo ping -c 1 -I wwan0 8.8.8.8
tail -7 "$LOG_PATH"

Pintovski
Posts: 4
Joined: Tue May 26, 2020 12:23 am

Re: 4G Hat: Signal loss

Tue May 26, 2020 8:51 am

busseanlagen wrote:
Sat May 16, 2020 6:48 pm
How do you guys handle signal loss and auto reconnect?

I use a script that pings 8.8.8.8 every 10 seconds and if the connection goes down it just executes the given commands to reestablish a connection. Unfortunately after a few days I get an error: "Couldn't create client for the 'wds' service - CID allocation failed" which tells me that I have too many active CIDs. Currently I think about saving the previous CIDs and PHDs and stop the qmicli request so that the CIDs get released.
Do you think that's the way to go or do you have any other ideas?
Hello,

I put this script in a file, and add it to the crontab with the freq that suits my needs. Make sure it runs the cron as sudo. The checking procedure is quite fast. I am doing a check every 10s, but could try higher frequencies.

Let me know if anyone has a better way :)

Code: Select all

#!/bin/bash
TURN_ON_SCRIPT_PATH="/home/joao/scripts/4G-HAT/4G_turn_on.sh"
inet_count="$(ifconfig wwan0 | grep -c 'inet ')"

if [ $inet_count -eq 1 ]
then
  echo "-> wwan0 is connected."
else
  echo "-> wwan0 is offline."
  sudo sh "$TURN_ON_SCRIPT_PATH"
fi

ndomx
Posts: 1
Joined: Tue May 26, 2020 5:15 pm

Re: 4G Hat

Tue May 26, 2020 7:07 pm

I've been following mkrzysztofowicz' steps with my SIM7600SA-H module (not a hat, only the module with a USB port). I'm currently struggling with the raw_ip setup. On step 3, I get

Code: Select all

pi:~$ sudo qmicli -d /dev/cdc-wdm0 -w		# this confirms the name of the network interface, typically wwan0
pi:~$ sudo ip link set wwan0 down		# change the wwan0 to the one returned above if different
pi:~$ echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip
tee: /sys/class/net/wwan0/qmi/raw_ip: No such file or directory
Y
I've found there's no directory named qmi inside the wwan0 folder and I'm also unable to create it (in case the answer was that simple) because the parent folder is protected. I guess the libqmi-utils package should have created those missing directories (?).

There's also another issue that may be causing this error. On step 2, when I execute the command

Code: Select all

pi:~$ sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
The module turns on. However, the command also throws a timeout error. I'm not so sure this is what's causing my raw_ip problem because all the verification commands that come after work properly (get-operating-mode, get-signal-strength & get-home-network).

mkrzysztofowicz wrote:
Wed Apr 03, 2019 11:35 am
OK, I've got this working fully now!

For those of you who are still struggling, here's the required steps:

1. Install required software

Code: Select all

pi:~$ sudo apt-get update && sudo apt-get install libqmi-utils udhcpc


2. This one is important - when you reboot the pi, the SIM7600 module's cellular radio is OFF and needs to be turned ON before you can see the mobile network. One way is to use a script which pulls the GPIO pin 4 LOW for a second or two (as per this post: https://lb.raspberrypi.org/forums/viewt ... 1#p1368015), but a more elegant way I think is to use the newly installed qmi utils:

Code: Select all

pi:~$ sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
Note, you can verify if your radio needs to be turned on by using the following commands:

Code: Select all

qmicli -d /dev/cdc-wdm0 --dms-get-operating-mode
qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength
qmicli -d /dev/cdc-wdm0 --nas-get-home-network
If the first command shows in its output 'Low Power' or anything other than 'online' it means your radio is off and needs to be turned on.
The last of those commands should return the LTE network ID if your device successfully connected.

3. Reconfigure the network interface for raw-ip protocol

The qmi-wwan kernel driver creates the wwan0 network interface for you when it detects the SIM7600 module connected to your Raspberry Pi. By default that interface is set to 802-3 protocol, however it seems the correct protocol should be raw-ip. The qmi-network script tries to set that up for you, but it will most likely fail. To make the change, do the following:

Code: Select all

pi:~$ sudo qmicli -d /dev/cdc-wdm0 -w		# this confirms the name of the network interface, typically wwan0
pi:~$ sudo ip link set wwan0 down		# change the wwan0 to the one returned above if different
pi:~$ echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip
pi:~$ sudo ip link set wwan0 up
4. Connect to the mobile network.

After having done all the above, when trying to use qmicli to connect, I was getting the following error: error: "couldn't start network: QMI protocol error (64): '(null)'. .

There have apparently been some changes to qmi utils in Stretch and most of the documentation I saw over the last days is almost correct but missing one vital detail - you need to add ip-type=4 to other parameters for qmicli -d /dev/cdc-wdm0 --wds-start-network= as below.

Code: Select all

pi:~$ qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='YOUR_APN',username='YOUR_USERNAME',password='YOUR_PASSWORD',ip-type=4" --client-no-release-cid
[/dev/cdc-wdm0] Network started
	Packet data handle: '2264328160'
[/dev/cdc-wdm0] Client ID not released:
	Service: 'wds'
	    CID: '20'
5. Finally, configure the IP address and the default route with udhcpc:

Code: Select all

pi:~$ sudo udhcpc -i wwan0
udhcpc (v1.22.1) started
No resolv.conf for interface wwan0.udhcpc
Sending discover...
Sending select for 10.65.52.178...
Lease of 10.65.52.178 obtained, lease time 7200
cat: /run/resolvconf/lock/pid: No such file or directory
/sbin/resolvconf: 733: kill: Illegal number:
clearing stale lock pid
Too few arguments.
Too few arguments.
As you can see, this spits out a number of errors, but they relate to configuration of DNS servers in your resolv.conf file, but otherwise this works and I can now get the connection via the mobile network:

Code: Select all

pi:~ $ ip a s wwan0
3: wwan0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/none
    inet 10.65.52.178/30 scope global wwan0
       valid_lft forever preferred_lft forever

pi:~ $ ip r s
default via 10.65.52.177 dev wwan0
10.65.52.176/30 dev wwan0 proto kernel scope link src 10.65.52.178
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.5 metric 202

pi:~ $ ping -4 www.google.com
PING www.google.com (74.125.193.147) 56(84) bytes of data.
64 bytes from ig-in-f147.1e100.net (74.125.193.147): icmp_seq=1 ttl=50 time=732 ms
64 bytes from ig-in-f147.1e100.net (74.125.193.147): icmp_seq=2 ttl=50 time=79.4 ms
64 bytes from ig-in-f147.1e100.net (74.125.193.147): icmp_seq=3 ttl=50 time=80.3 ms
64 bytes from ig-in-f147.1e100.net (74.125.193.147): icmp_seq=4 ttl=50 time=79.4 ms
^C
--- www.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 79.447/242.945/732.530/282.662 ms
You can take a look at this article: http://www.embeddedpi.com/documentation ... face-setup for a way to tidy things up a bit. It refers to a different 3G/4G modem (Sierra Wireless) but the way they set interfaces up and everything else still applies.

Good luck!

omikron
Posts: 15
Joined: Sat May 25, 2019 8:30 am

Re: 4G Hat

Thu May 28, 2020 8:31 am

Hello,

Is it possible to use SIM7600E-H 4G GPS hat for 4G connection and GPS accurate time (gpsd) at the same time?

How to do it? :?:

Pintovski
Posts: 4
Joined: Tue May 26, 2020 12:23 am

Re: 4G Hat

Thu May 28, 2020 3:14 pm

omikron wrote:
Thu May 28, 2020 8:31 am
Hello,

Is it possible to use SIM7600E-H 4G GPS hat for 4G connection and GPS accurate time (gpsd) at the same time?

How to do it? :?:
YES! I am doing that. Check my post above.

Pintovski
Posts: 4
Joined: Tue May 26, 2020 12:23 am

Re: 4G Hat

Thu May 28, 2020 3:19 pm

Hahaha... When I submitted this post, I didn't think I would need it so soon... just bricked the SD card and I have no backups of the code...

Thank you to my younger me for posting here the scripts :)

J

Pintovski wrote:
Tue May 26, 2020 1:05 am
Thank you all for your posts... they got me through to have my setup 100% operational.

I leave here some comments for anyone that is interested, specially to my future self next time I browse the internet about this issue.

(Hello to me!!... I know you will need this post in a couple of years!!!!)

Feel free to propose changes and improve... :)

My needs
I want to have 4G automatically after boot with no user intervention
I also want to be able to have 4G + SMS/GPS/... at the "same time" without compromising functionalities

My setup
My setup is a Raspberry Pi 4 model B
I am running DietPi OS
I have the jumper in B
I have an USB-C cable connecting the USB-C port of the HAT to a normal USB on the Raspberry Pi 4 (I am using a 3.0 USB port)

Comment 1 - I don't want to press the button!
Normally it is required to press the PWRKEY manually. However there is a note in the manual (pg. 9) that is worthwhile copying here:
"The default hardware of SIM7600CE4GHAT needs to be turned on by button. If the hardware needs to be turned on automatically, you can use a connection line to connect the PWR and GND pins on the module pin, so that it can automatically turn on, as shown in the figure below."
https://www.waveshare.com/w/upload/6/6d ... ual-EN.pdf

Comment 2 - My script
I followed mostly what was mentioned in the posts of this forum. However, I needed to include some extra steps to make it work for me.
In this post I include the script that I am using. It has some extra lines of coding with output, feel free to remove those, but be careful because it uses the log file to check for errors.

Comment 3 - What is my APN?
If you don't know... don't bother your communication provider! Just put the SIM card in a cellphone and check in the settings what are the provider details. I use android for that and it is super easy. Just google it.

Comment 4 - Running at boot
Running at each boot in the Raspberry Pi is super easy. Just copy the script file to "/var/lib/dietpi/postboot.d/" all files that are in that folder will be run after each boot with sudo priveliges.

However, for this procedure to work and be registered in a network, it is important to be able to check for errors and keep trying to connect until it works. That is why you see "While" in the script.

The script

1. Change the PATH variables in the script to match your specific project.
2. Change the "sudo qmicli -p -d /dev/cdc-wdm0 ..." line to match your APN, etc...
3. Just copy into a new file.
4. Don't forget to "chmod +x [YOUR-FILENAME]" to make it executable.

ENJOY!

Code: Select all

#!/bin/bash
LOG_PATH="/home/joao/scripts/log_scripts/4G.log"
sim7600_4G_hat_init_PATH = "/home/joao/scripts/4G-HAT/SIM7600X-4G-HAT-Demo/Raspberry/c/sim7600_4G_hat_init"
MAX_TRIES=20

N_TRY=0
TRY=""

echo "Logs go to: $LOG_PATH"
rm $LOG_PATH

echo "---------------------------------" > "$LOG_PATH"
echo "Connecting 4G-LTE" >> "$LOG_PATH"
echo "-check hat net led---------------" >> "$LOG_PATH"
echo "-sim7600_4G_hat_ini--------------" >> "$LOG_PATH"

echo "$LOG_PATH"
echo "---------------------------------"
echo "Connecting 4G-LTE"
echo "-check hat net led---------------"
echo "-sim7600_4G_hat-ini--------------"

sh "$sim7600_4G_hat_init_PATH" >> "$LOG_PATH"

while [ "$TRY" != "done" ]
do
   N_TRY=$((N_TRY + 1))

   echo "--try $N_TRY --" >> "$LOG_PATH"
   echo "--try $N_TRY --"

   echo "--dms SET operating mode--" >> "$LOG_PATH"
   echo "--dms SET operating mode--"

   sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online' >> "$LOG_PATH"

   echo "--dms GET operating mode--" >> "$LOG_PATH"
   echo "--dms GET operating mode--"

   sudo qmicli -d /dev/cdc-wdm0 --dms-get-operating-mode >> "$LOG_PATH"

   if [ "$N_TRY" = "$MAX_TRIES" ]
   then

      echo "reached MAX_TRIES = $MAX_TRIES" >> "$LOG_PATH"
      echo "reached MAX_TRIES = $MAX_TRIES"

      TRY="done"
   fi
   temp="$(grep -c "online" "$LOG_PATH")"

   if [ $temp -eq 1 ]
   then
      echo "Success! <0.0>" >> "$LOG_PATH"
      grep "online" "$LOG_PATH" >> "$LOG_PATH"

      echo "Success! <0.0>"
      grep "online" "$LOG_PATH"

      TRY="done"
   fi
done

echo "Needed $N_TRY tries to connect" >> "$LOG_PATH"
echo "-get-signal-strength-------------" >> "$LOG_PATH"

echo "Needed $N_TRY tries to connect"
echo "-get-signal-strength-------------"


sudo qmicli -d /dev/cdc-wdm0 --nas-get-signal-strength >> "$LOG_PATH"

tail -14 "$LOG_PATH"

echo "-get-home-network----------------" >> "$LOG_PATH"

echo "-get-home-network----------------"

sudo qmicli -d /dev/cdc-wdm0 --nas-get-home-network >> "$LOG_PATH"

echo "- -w ----------------------------" >> "$LOG_PATH"

echo "- -w ----------------------------"

sudo qmicli -d /dev/cdc-wdm0 -w >> "$LOG_PATH"

echo "-wwan0 down----------------------" >> "$LOG_PATH"

echo "-wwan0 down----------------------"

sudo ip link set wwan0 down >> "$LOG_PATH"

echo "-raw_ip -> Y---------------------" >> "$LOG_PATH"

echo "-raw_ip -> Y---------------------"

echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip >> "$LOG_PATH"

echo "-wwan0 up------------------------" >> "$LOG_PATH"

echo "-wwan0 up------------------------"

sudo ip link set wwan0 up >> "$LOG_PATH"

echo "-get-autoconnect-settings--------" >> "$LOG_PATH"

echo "-get-autoconnect-settings--------"

sudo qmicli -d /dev/cdc-wdm0 --wds-get-autoconnect-settings >> "$LOG_PATH"

echo "-set-autoconnect-settings--------" >> "$LOG_PATH"

echo "-set-autoconnect-settings--------"

sudo qmicli -d /dev/cdc-wdm0 --wds-set-autoconnect-settings=disabled >> "$LOG_PATH"

tail -2 "$LOG_PATH"

echo "if error 26 -> its ok. It means that autoconnect was already disabled" >> "$LOG_PATH"
echo "-start network-------------------" >> "$LOG_PATH"

echo "if error 26 -> its ok. It means that autoconnect was already disabled"
echo "-start network-------------------"

N_TRY=0
TRY=""
while [ "$TRY" != "done" ]
do
   N_TRY=$((N_TRY + 1))

   echo "--try $N_TRY --" >> "$LOG_PATH"
   echo "--try $N_TRY --"

# CHANGE THIS NEXT LINE TO MATCH YOUR COMMUNICATION PROVIDER
   sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='net2.vodafone.pt',ip-type=4" --client-no-release-cid >> "$LOG_PATH"

   if [ "$N_TRY" = "$MAX_TRIES" ]
   then

      echo "reached MAX_TRIES = $MAX_TRIES" >> "$LOG_PATH"
      echo "reached MAX_TRIES = $MAX_TRIES"

      TRY="done"
   else
      echo "...$N_TRY of $MAX_TRIES: unable to start network. Trying again in 5s."
      sleep 5
   fi
   temp="$(grep -c "\[/dev/cdc-wdm0\] Network started" "$LOG_PATH")"

   if [ $temp -eq 1 ]
   then
      echo "...$N_TRY of $MAX_TRIES: Success!" >> "$LOG_PATH"
      grep "\[/dev/cdc-wdm0\] Network started" "$LOG_PATH" >> "$LOG_PATH"

      echo "...$N_TRY of $MAX_TRIES: Success!"
      grep "\[/dev/cdc-wdm0\] Network started" "$LOG_PATH"

      TRY="done"
   fi
done

echo "network started ?"
echo "network started ?" >> "$LOG_PATH"

echo "-start---------------------------" >> "$LOG_PATH"

echo "-start---------------------------"

sudo qmi-network /dev/cdc-wdm0 start >> "$LOG_PATH"

echo "-udhcpc--------------------------" >> "$LOG_PATH"

echo "-udhcpc--------------------------"

sudo udhcpc -t 10 -i wwan0 >> "$LOG_PATH"

echo "-ip a s--------------------------" >> "$LOG_PATH"

echo "-ip a s--------------------------"

ip a s wwan0 >> "$LOG_PATH"

echo "-ip r s--------------------------" >> "$LOG_PATH"

echo "-ip r s--------------------------"

ip r s >> "$LOG_PATH"

echo "-ifconfig------------------------" >> "$LOG_PATH"
echo "ifconfig" >> "$LOG_PATH"
echo "---------------------------------" >> "$LOG_PATH"
ifconfig wwan0

ifconfig >> "$LOG_PATH"

echo "-manufacturer--------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-manufacturer >> "$LOG_PATH"

echo "-model---------------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-model >> "$LOG_PATH"

echo "-firmware------------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-revision >> "$LOG_PATH"

echo "-IMEI----------------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --dms-get-ids >> "$LOG_PATH"

echo "-SIM-status----------------------" >> "$LOG_PATH"
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --uim-get-card-status >> "$LOG_PATH"

echo "-qmicli version------------------" >> "$LOG_PATH"
sudo qmicli --version >> "$LOG_PATH"

echo "-final-testing-------------------" >> "$LOG_PATH"
sudo ping -c 1 -I wwan0 8.8.8.8 >> "$LOG_PATH"

echo "-final-testing-------------------"
#sudo ping -c 1 -I wwan0 8.8.8.8
tail -7 "$LOG_PATH"

minfrin
Posts: 14
Joined: Sun Jul 26, 2015 6:02 pm

Re: 4G Hat

Sun Jun 14, 2020 12:10 pm

Pintovski wrote:
Thu May 28, 2020 3:14 pm
omikron wrote:
Thu May 28, 2020 8:31 am
Hello,

Is it possible to use SIM7600E-H 4G GPS hat for 4G connection and GPS accurate time (gpsd) at the same time?

How to do it? :?:
YES! I am doing that. Check my post above.
I see instructions for the network part, but see no reference to gpsd - did you ever keep instructions for handling this part?

I have this device, gpsd is running, gpds tells me it is tracking zero devices. I see gpsd has the concept of USB autodetect, but gpds doesn't autodetect anything. Has anyone got gps to work on this device?

lancer6x
Posts: 3
Joined: Tue Jun 23, 2020 3:14 pm

Re: 4G Hat

Tue Jun 23, 2020 3:23 pm

I recently got this working with the qmicli command method that everyone has been having such luck with, but I wanted to share some struggles I was having that I figured out, as others seem to be having the same problems.

In the Waveshare wiki it mentions issuing the following command "AT+CUSBPIDSWITCH=9011,1,1" to set up RNDIS networking. If you're like me and read that before landing on this thread, you may have already issued that command to the HAT.

This will set the unit in to function as a RNDIS modem, which functions much differently from a QMI modem, and will render qmicli commands useless.

If you don't have a "wwan0" interface (and have "usb0" instead), and can't find /dev/cdc-wdm0 you are likely in the wrong PID mode.

Issue "AT+CUSBPIDSWITCH=9001,1,1" to the modem and wait for it to restart and it will come back up in QMI mode. A PID of 9001 alerts the kernel to treat the device as a qmi device, a PID of 9011 alerts the kernel to treat it as an RNDIS modem.

Problem solved.

I hope this saves people some time and struggles.

hariharan1998
Posts: 1
Joined: Thu Jun 25, 2020 6:18 am

Re: 4G Hat

Thu Jun 25, 2020 6:26 am

hi @kikusin,

can you send all the commands that you used to configure and activate the waveshare HAT. And also do i need to use any connections from the waveshare module to the raspberry pi3

lancer6x
Posts: 3
Joined: Tue Jun 23, 2020 3:14 pm

Re: 4G Hat

Sat Jun 27, 2020 7:06 pm

So update, after submitting my last post I am able to receive an IP address and I am able to ping 8.8.8.8, google.com, facebook.com, anything over the wwan0 interface. So I am definitely connected to the network. But attempting to do anything more than ping over the wwan0 interface does not work, for instance I can not use wget over that interface. It is not a DNS problem, because it can resolve host names like google.

Anyone run in to anything like this?

RustyFrame
Posts: 2
Joined: Wed Jul 01, 2020 3:52 am

Re: 4G Hat

Wed Jul 01, 2020 4:10 am

lancer6x wrote:
Sat Jun 27, 2020 7:06 pm
So update, after submitting my last post I am able to receive an IP address and I am able to ping 8.8.8.8, google.com, facebook.com, anything over the wwan0 interface. So I am definitely connected to the network. But attempting to do anything more than ping over the wwan0 interface does not work, for instance I can not use wget over that interface. It is not a DNS problem, because it can resolve host names like google.

Anyone run in to anything like this?

I've been battling this thing for 4 hours now and have finally ended up where you are. I've had to edit my /etc/resolv.conf and set it manually to the default google name server.

Code: Select all

sudo nano /etc/resolv.conf

nameserver 8.8.8.8


Then I've been off and running. This is on T-mobile, I"m not sure why it isn't updating this automatically and have just gotten to this point. So here is the work around.

Also to help over people out, the following worked for me only after I modified the qmi conf file.

Code: Select all

sudo qmi-netowrk /dev/cdc-wdm0 start


You can create a /etc/qmi-network.conf and then set it up with the following information

Code: Select all

 APN='yourAPN'
 ip-type=4
 

currently I'm bringing up my wave share through the following.

initialize that hat with the waveshare hat init. You should wait until your lights are steady. Someone else above had error checking to do this. then just like everyone else has said above.

Code: Select all

 
 sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
 sudo qmicli --d /dev/cdc-wdm0 -w  #this just gets the name, verfied for next step
 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='yourapn',ip-type=4" --client-no-release-cid
 sudo qmi-network /dev/cdc-wdm0 start
 sudo udpcpc -i wwan0
 
I've tried just the sudo qmi-network /dev/cdc-wdm0 start without the line above it, but it doesn't like it. However, it seems to tread over a lot of the same ground for setting up the connection. I'm really just copy paste monkey here, but seems like something I'd like to know more about. Then I'm still trying to figure out a method to get my resolv.conf to update.

Now here's my question: How are you all making calls through this connection?

RustyFrame
Posts: 2
Joined: Wed Jul 01, 2020 3:52 am

Re: 4G Hat

Wed Jul 01, 2020 12:36 pm

lancer6x wrote:
Sat Jun 27, 2020 7:06 pm
So update, after submitting my last post I am able to receive an IP address and I am able to ping 8.8.8.8, google.com, facebook.com, anything over the wwan0 interface. So I am definitely connected to the network. But attempting to do anything more than ping over the wwan0 interface does not work, for instance I can not use wget over that interface. It is not a DNS problem, because it can resolve host names like google.

Anyone run in to anything like this?
You can preset a name server using the dnsmasq.

Edit /etc/dnsmasq.conf and add in your own name servers. Then it will always set the resolv.conf to include these name servers. Have not yet found why my ISP doesn't supply a name server when obtaining an IP.

Code: Select all

server=8.8.8.8
server=8.8.4.4
Fix found on Stackoverflow:

https://unix.stackexchange.com/question ... 506#163506

HftH
Posts: 4
Joined: Sat Jul 04, 2020 8:12 am

Re: 4G Hat

Sat Jul 04, 2020 9:50 pm

Has anybody managed to get this to work without the USB? Mine is perfect with the cable thanks to this thread but I cannot figure out how to use only UART connection. Some example code would be super handy!

Thanks

arkanos17
Posts: 2
Joined: Mon Jul 13, 2020 6:52 pm

Re: 4G Hat

Mon Jul 13, 2020 8:48 pm

Hello everyone. This is my first post.
I am super new at Pi/Hat/Linux.
Recently purchase first Pi4 with Waveshare 7600G-H hat.
Following different set of instructions but unable to proceed.
Every time I try something I stumble.

Here is basic info on my system.

Raspberry Pi4 build 4.19.118-v7l+
Waveshare 7600G-H.
Jumper is on B side
Connecting through USB port

First I used original Simcom instructions I found on waveshare/wiki installing the driver

(1) Connect the SIM7100 by physical USB interface and power on the modem.
(2) Open the terminal and type the shell command lsusb.
(3) SIM7100 module will be recognized by Ubuntu via USB interface(vid=1e0e,pid=9001).
(4) Type the command “sudo rmmod usbserial”, some error messages may be prompted, just
ignore them.
(5) Copy GobiSerial.tar.gz to home directory and type the command “tar zxvf
GobiSerial.tar.gz”
At this point i got stock as i was gettting an error 'No Rule to make target modules. Stop'
(6) Compile the driver GobiSerial. Type the command “cd GobiSerial && make”,if no error
occurs, a file named “GobiSerial.ko” will be generated.
(7) Type the command “sudo modprobe usbserial && sudo insmod GobiSerial.ko” to install
the driver.
(8) List the ttyUSBx devices by “ls -l /dev/ttyUSB*”
If /dev/ttyUSB0~5 are available,then device driver is installed successfully!

Second: I tried using instructions posted here by mkrzysztofowicz
sudo apt-get update && sudo apt-get install libqmi-utils udhcpc
went without a hitch

sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
error couldn't create QmiDevice. couldn't query file info: error while getting information for file /dev/cdc-wdm0no such file or directory.

What am i doing wrong? Please help i've been at this for few days.
Tested Hat with a Windows PC works like a charm. so unit is not faulty.

Thank you.
Ark.

Phressh
Posts: 2
Joined: Wed Jul 15, 2020 8:27 pm

Re: 4G Hat

Wed Jul 15, 2020 8:42 pm

I’ve been struggling getting my SIM7600g-h hat working on a rasp pi 4 on Ubuntu 20.04 , and for the most part have been successfully connected to 4G now by following all the instructions . Super helpful thread everyone.

One thing that tore my hair out trying to get working was getting the GPIO pins to successfully talk with my pi. So here are the steps i took:
Before connecting, run sim7600_init script with CORRECTION add to bottom:

echo > 1 /sys/class/gpio/gpio6/value
sleep 5
echo > 0 /sys/class/gpio/gpio6/value

This brings up not only the power but the cellular modem on the hat without having to manually push power button, as for my intended purpose of the pi i won’t be able to physically have access to it in the field.
1) connect hat to GPIO pins
2) connect microUSB from hat to USB on Pi
3) make sure to set jumpers to C

One thing that I still have yet to figure out is that the cell modem turns off by itself after every few hours or so (possibly randomly?). How would I go about creating a script to see if cell modem is off, then turn cell modem on through GPIO. Also how can I run that using only user permissions since I won’t be logged to root in my user crontab. Any help appreciated!

formantjim
Posts: 1
Joined: Wed Jul 22, 2020 9:08 pm

Re: 4G Hat

Wed Jul 22, 2020 9:24 pm

Hi Phressh I'm new to the Rasbperry scene and have purchased a couple of these GSM hats to create a remote wireless datalogger and looking at the troubles people have experienced and read through this thread I wish to ask the following.

When I mount the top hat to the PI like others I need this device out in the field collecting data and via the internet sending it to a webserver. I will not be able to go out there and hit the power button so need it to restart itself automatically should it loose cellular contact. So your little script is placing signals on the GPIO pin 6 to toggle it to cause it to start remotely but one still needs to connect a usb cable from the hat to the PI even though the hat is connected to the PI?

Return to “Networking and servers”