Hey Benjamin,
The USB connection is definitely important. Without it, the board doesn’t run correctly. I have tried without it.
Kindest regards,
Tim
Hey Benjamin,
The USB connection is definitely important. Without it, the board doesn’t run correctly. I have tried without it.
Kindest regards,
Tim
@Tim ,
thanks a lot for your explanations to the people who is asking for help here.
I have the following question on this 7600G-H now, when I downloaded the demo script from your guide, and run the script on the “FindGPSthenSMSFinal.py” , it shows:
Traceback (most recent call last):
File “/home/pi/SIM7600X-4G-HAT-Demo/Raspberry/python/demo_script/article-downloads-waveshare-4g-gps-printable-mount-and-python-scripts/python-scripts-4g-waveshare-hat/FindGPSthenSMSFinal.py”, line 151, in
send_at(‘AT+CGPS=1,1’,‘OK’,1)
File “/home/pi/SIM7600X-4G-HAT-Demo/Raspberry/python/demo_script/article-downloads-waveshare-4g-gps-printable-mount-and-python-scripts/python-scripts-4g-waveshare-hat/FindGPSthenSMSFinal.py”, line 102, in send_at
NorthOrSouth = Cleaned[12]
IndexError: string index out of range
So, what’s the issue happening here? The “GPS.py” works fine.
Also, the Phonecall.py doesn’t work, it shows:
SIM7600X is starting:
SIM7600X is ready
OK
NO CARRIER
This simcard can make a call when put into the iphone for sure.
the SMS.py works fine to send the message to the phone.
Could you please help on them?
Hey all,
I’ve taken the time to rewrite the FindGPSthenSMSFinal.py script. I’ve named it rather un-inventively as | NewFindGPSthenSMSFinal.py |. You will be able to find it in the downloadable Zip file found at the bottom of the guide.
This should now work for any location in the globe. Before it was clear from these comments that the older script would only function for certain areas in the southern hemisphere. It really came down to the way I was formatting the GPS data as it came in. The section of the script which I updated can be found below.
global GPSDATA
#print(GPSDATA)
GPSDATA = str(rec_buff.decode())
Cleaned = GPSDATA[13:]
#print(Cleaned)
Lat = Cleaned[:2]
SmallLat = Cleaned[2:11]
NorthOrSouth = Cleaned[12]
#print(Lat, SmallLat, NorthOrSouth)
Long = Cleaned[14:17]
SmallLong = Cleaned[17:26]
EastOrWest = Cleaned[27]
#print(Long, SmallLong, EastOrWest)
FinalLat = float(Lat) + (float(SmallLat)/60)
FinalLong = float(Long) + (float(SmallLong)/60)
if NorthOrSouth == 'S': FinalLat = -FinalLat
if EastOrWest == 'W': FinalLong = -FinalLong
FinalLongText = round(FinalLong, 6)
FinalLatText = round(FinalLat, 6)
StringFinalLongText = str(FinalLongText)
StringFinalLatText = str(FinalLatText)
#print(FinalLat, FinalLong)
#print(FinalLat, FinalLong)
#print(rec_buff.decode())
global text_message
#text_message = ('Longitude is ' + ((float(Cleaned[1:8])/1000)) + ' S, and Latitude is '+((float(Cleaned[16:27]/1000)) + 'E'))
text_message = ('The Raspberry Pi - Longitude is ' + StringFinalLongText + ' Degrees, and Latitude is ' + StringFinalLatText + ' Degrees')
print(text_message)
SendShortMessage(phone_number,text_message)
I hope this helps everyone! Particularly in regards to @Tamsyn216845 and @paul2024226815 . Please pop me a message if it doesn’t work straight away as I will continue to fix it until it does!
Kindest regards,
Tim
Hi Tim,
Thanks a lot for the quick response! I am in the U.S. so really expect it can be send the message on the GPS information via sim7600.
I ran the code you updated, looks there is the compilation error as below:
Traceback (most recent call last):
File “/usr/lib/python3.9/ast.py”, line 50, in parse
return compile(source, filename, mode, flags,
File “/home/pi/SIM7600X-4G-HAT-Demo/Raspberry/python/demo_script/article-downloads-waveshare-4g-gps-printable-mount-and-python-scripts/python-scripts-4g-waveshare-hat/FindGPSthenSMSFinal-1.py”, line 95
GPSDATA = str(rec_buff.decode())
^
IndentationError: unindent does not match any outer indentation level
can you help to check?
Here is the whole file:
#!/usr/bin/python
import RPi.GPIO as GPIO
import serial
import time
ser = serial.Serial(‘/dev/ttyS0’,115200)
ser.flushInput()
power_key = 6
rec_buff = ‘’
time_count = 0
#phone_number = ‘Your Number Here’
phone_number = ‘xxxxxxx’
text_message = ‘’
#Important User-Defined function to make talking to the HAT easier
def power_on(power_key):
print(‘SIM7600X is starting:’)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(power_key,GPIO.OUT)
time.sleep(0.1)
GPIO.output(power_key,GPIO.HIGH)
time.sleep(2)
GPIO.output(power_key,GPIO.LOW)
time.sleep(20)
ser.flushInput()
print(‘SIM7600X is ready’)
def power_down(power_key):
print(‘SIM7600X is loging off:’)
GPIO.output(power_key,GPIO.HIGH)
time.sleep(3)
GPIO.output(power_key,GPIO.LOW)
time.sleep(18)
print(‘Good bye’)
def SendShortMessage(phone_number,text_message):
print("Setting SMS mode...")
send_at2("AT+CMGF=1","OK",1)
print("Sending Short Message")
answer = send_at2("AT+CMGS=\""+phone_number+"\"",">",2)
#power_down(power_key)
if 1 == answer:
ser.write(text_message.encode())
ser.write(b'\x1A')
answer = send_at('','OK',20)
if 1 == answer:
print('send successfully')
else:
print('error')
else:
print('error%d'%answer)
#power_down(power_key)
def send_at2(command,back,timeout):
rec_buff = ‘’
ser.write((command+‘\r\n’).encode())
time.sleep(timeout)
if ser.inWaiting():
time.sleep(0.01 )
rec_buff = ser.read(ser.inWaiting())
if back not in rec_buff.decode():
print(command + ’ ERROR’)
print(command + ’ back:\t’ + rec_buff.decode())
return 0
else:
print(rec_buff.decode())
return 1
def send_at(command,back,timeout):
rec_buff = ‘’
ser.write((command+‘\r\n’).encode())
time.sleep(timeout)
if ser.inWaiting():
time.sleep(0.01 )
rec_buff = ser.read(ser.inWaiting())
if rec_buff != ‘’:
if back not in rec_buff.decode():
print(command + ’ ERROR’)
print(command + ’ back:\t’ + rec_buff.decode())
return 0
else:
#print(rec_buff.decode())
global GPSDATA
#print(GPSDATA)
GPSDATA = str(rec_buff.decode())
Cleaned = GPSDATA[13:]
#print(Cleaned)
Lat = Cleaned[:2]
SmallLat = Cleaned[2:11]
NorthOrSouth = Cleaned[12]
#print(Lat, SmallLat, NorthOrSouth)
Long = Cleaned[14:17]
SmallLong = Cleaned[17:26]
EastOrWest = Cleaned[27]
#print(Long, SmallLong, EastOrWest)
FinalLat = float(Lat) + (float(SmallLat)/60)
FinalLong = float(Long) + (float(SmallLong)/60)
if NorthOrSouth == 'S': FinalLat = -FinalLat
if EastOrWest == 'W': FinalLong = -FinalLong
FinalLongText = round(FinalLong, 6)
FinalLatText = round(FinalLat, 6)
StringFinalLongText = str(FinalLongText)
StringFinalLatText = str(FinalLatText)
#print(FinalLat, FinalLong)
#print(FinalLat, FinalLong)
#print(rec_buff.decode())
global text_message
#text_message = ('Longitude is ' + ((float(Cleaned[1:8])/1000)) + ' S, and Latitude is '+((float(Cleaned[16:27]/1000)) + 'E'))
text_message = ('The Raspberry Pi - Longitude is ' + StringFinalLongText + ' Degrees, and Latitude is ' + StringFinalLatText + ' Degrees')
print(text_message)
SendShortMessage(phone_number,text_message)
#break
return 1
else:
print('GPS is not ready')
return 0
#Code Body Starts which utillises all the above Definitions
power_on(power_key)
rec_null = True
answer = 0
print(‘Start GPS session…’)
rec_buff = ‘’
send_at(‘AT+CGPS=1,1’,‘OK’,1)
time.sleep(2)
while rec_null:
answer = send_at(‘AT+CGPSINFO’,'+CGPSINFO: ',1)
if 1 == answer:
answer = 0
if ‘,’ in rec_buff:
print(‘GPS is not ready’)
rec_null = False
time.sleep(1)
else:
print(‘error %d’%answer)
rec_buff = ‘’
send_at(‘AT+CGPS=0’,‘OK’,1)
time.sleep(1.5)
I will download the file you uploaded then.
Good day Tim,
Thank you for your guide and your efforts in helping this community. It really means alot as I have benefitted in developing my final project, however, I have been having some issues.
I managed to get the 4G data working with a local service provider called Digicel here in Trinidad and Tobago. I bought that new sim yesterday and following instructions from the website below, I was able to get the internet access, by inputting Digicel’s APN into the code below instead of Telnyx’s.
The website:
This is the code I editted-
Before:
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --wds-start-network=“ip-type=4,apn=data00.telnyx” --client-no-release-cid.
After:
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --wds-start-network=“ip-type=4,apn=web.digiceltt.com” --client-no-release-cid
However, I have encountered a new problem. Whenever the Pi reboots, the IP and network settings apparently reverts back to what it was before I did the setup and I then need to do this setup all over again in order to get internet access when it restarts.
Would you be able to guide me as to how I can get the settings to save and not change everytime the Pi turns off or is rebooted?
Thanks a million in advance and do have a great day!
Kind regards,
Vinu Gunness
Just an update to my last request. I noticed that I am getting an error as shown below. I attempted to create a file called cdc-wwm0 but that did not help. Thanks in advance!
Loved your tutorial I’m curious though how easy would it be to recieve audio calls using this device? I’m assuming I can modify the LED script for sms messages to be displayed in a UI but do you have to manually set it up to constantly check for incoming calls? How would that be accomplished?
Hello,
I am a senior engineering student and I am using a Waveshare SIM7600G-H hat for a raspberry pi. I am using it to do two way audio and it works great, but I am having trouble recording this audio. I have tried using the SIM7600 AT commands to record the audio, specifically “AT+CREC”, and the SIM7600 recognizes the commands and gives the appropriate response, but it does not save the audio to the microSD card on the hat. Are there any solutions to this problem? This would be great help.
As a side note, there are no restrictions to recording audio in my region.
Thanks,
John
Hello, thank you for the thorough guide! Would it be possible to use this setup to make phone calls from a landline? Any idea how to connect the two? Thank you!
Hi Tim,
I wanted to help further progress what you’ve done here with IOT and the various Waveshare modem hats you sell.
I’ve built a python script that robustly provides bi-directional Linux shell access over SMS, and a further bash script to install the python script as a Linux systemd service. (We briefly talked about this some time back as the internet provided no working proof of concept code that I and others could find).
My script can either accept full SMS shell commands or (conveniently) parse case insensitive SMS keyword shortcuts to trigger pre-set remote shell commands. (Think garage door open with a simple “g” SMS) All shell command output and command confirmation is sent back to the sender’s phone number as single or multi-page SMS. For security the sender’s phone number must be in an access list to be able to send any commands. Additionally, all commands are logged and each script function has error checking applied so problems in the shell won’t break the script. I’ve not been able to crash it so far sending all sorts of odd characters and such. More detail is given on my Github.
I’ve tried to design the script to be universal so as to work with all modem types, SMS language character sets and other text mode parameters that various hardware manufacturers might require. In researching this I learned that Waveshare modems have some quirks as they default to hex/UCS-2 for Asian and Arabic character support, and I suspect that variations in modem character set support, encoding and decoding schemas etc might explain the lack of working proof-of-concept code seen out there - its a bit tricky.
Check out my script here: SMS-to-Shell github repo
All is tested and working great with a Vodafone sim using Raspi4/Raspbian Bullseye and one of your Waveshare 7600G-H models.
If you see value here and want to put together a how-to video, please reach out as I’d be happy to share more detail on what I learned in troubleshooting and putting this together with the Waveshare hardware. Eg – I observed in testing that the Waveshare appears to reset itself back to default hex encoding after a time period, which the script and systemd service also fixes.
Cheers,
Dave
Hey John
Checkout my post today and my github link SMS-to-Shell github repo
I’ve finally got around to build a working SMS-to-Shell framework that should do all you ask. Let me know how it goes as I’m interested in making improvments.
Does this 4G hat also provide internet access to the Raspberry pi that it is connected to?
And does the same apply to the [B] model Pi Zero version?
Hi Steven,
It sure does! I’d check out this guide that will work for both versions of the HAT: Super SIM, Raspberry Pi 4, and the Waveshare 4G Hat Getting Started Guide | Twilio
Liam
Hello there! While running the line: 7z x SIM7600X-4G-HAT-Demo.7z -r -o/home/pi
I ran into the error message- system ERROR: permission denied
I’m a complete RP noob, I guess I or the Terminal dont have permission to do that, how can I fix this? (This is my first time using a pi and following this guide is all I know I’m afraid)
Sorry to be a pain! Thank you
Hello
I have purchased an SIM7600E LTE Cat-1 HAT and I would like to set up internet connection with Raspberry Pi 4 model B.
Could you please provide a tutorial or help with regards to how could I do this?
I am hoping to send data through the HAT (from sensors) and/or to use it as a hotspot for other devices. So technically how I would be able to use a mobile phone with an active SIM and mobile data for similar purposes.
On another note,
I have followed through your youtube tutorial ( https://www.youtube.com/watch?v=ABnwz-IYzqA&t=572s ) until 9.33. However, I have encountered permission denied issues when cd-ing into the pi folder. Might this be due to firewall issues?
Thank you so much for your assistance in advance.
My man. I made an account just for you. The link you posted is PRICELESS! I finally have internet on my rip and I couldn’t do it without you. Thank you!
As for the 4g connectivity on startup, I need it as well. I haven’t tried yet, but what i will probably do is create a .sh script with all the necessary commands and request to open internet and just make rpi run this script at startup. I’ll post here when I’m done. You are a LEGEND
Sooo… that was WAY harder than I thought. But I did it somehow. I’m a copy/paste coder so I barely know what any of this code means, but I’m sure there is something redundant. I’ll let real coders optimize this solution.
This solution will try to raise network interfaces at startup and fail, but its ok because internet connectivity still works. For my purposes, I have auto login so I added the .sh script in .bashrc. You can try and see if it works in local.rc to see if it boots up before login. Anyways, here is what I managed to get:
create a file wwan0
sudo nano /etc/network/interfaces.d/wwan0
type this into the file (WARNING: it does not show in these comments, but before EVERY “pre-up” you should add an empty space like this " pre-up" and not just “pre-up”):
auto wwan0
iface wwan0 inet manual
pre-up ifconfig wwan0 down
pre-up sudo systemctl unmask NetworkManager.service
pre-up sudo systemctl disable NetworkManager.service
pre-up sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode=“online”
pre-up sudo ip link set wwan0 down
pre-up echo ‘Y’ | sudo tee /sys/class/net/wwan0/qmi/raw_ip
pre-up sudo ip link set wwan0 up
pre-up sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --wds-start-network=“ip-type=4, apn=YOUR_APN_HERE” --client-no-re> pre-up sudo udhcpc -i wwan0
pre-up ip a s wwan0
then create anywhere you want a .sh script. I called mine 4g.sh and put it in /home/USERNAME
my 4g.sh file:
#! /bin/sh
sudo systemctl unmask ModemManager.service
sudo systemctl disable ModemManager.service
sudo systemctl enable dhcpcd
sudo systemctl start dhcpcd
sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode=“online”
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 --device=/dev/cdc-wdm0 --device-open-proxy --wds-start-network=“ip-type=4, apn=YOUR_APN” --client-no-release-cid
sudo udhcpc -i wwan0
ip a s wwan0
FINALLY, you do this:
sudo nano .bashrc
(or sudo nano /home/USERNAME/.bashrc)
and in this file you add a line
sudo sh /home/USERNAME/4g.sh
And thats it.
As I said, if you need login capability, add this last line NOT into .bashrc but into rc.local
sudo nano /etc/rc.local
and maybe it works.
This has been a tough journey. I can’t believe something so obvious is so difficult!
Now I have to understand why the damn internet is so slow, I can barely connect to it thru ssh… but at least it starts on startup. If anybody has tips on how to improve slow internet with the qmicli setup, please share