Civlo85 / gsmHat

Using the Waveshare GSM/GPRS/GNSS Hat for Raspberry Pi with Python
MIT License
61 stars 26 forks source link

Cant use any function #6

Open Luke050 opened 3 years ago

Luke050 commented 3 years ago

I have installed your module correctly. My sim card is in HAT and it works (LED is on every 3 seconds).I turned on ttyS0 and I know it works.

when i execute your sample script:

from gsmHat import *
gsm = GSMHat('/dev/ttyS0', 115200)
Number = '+some_number'
gsm.Call(Number)

but nothing happens after that.

i did some testing. and I can see that while executing this script AT+CMGF=1 is written to /dev/ttyS0 and then get the answer OK but nothing else. each time it executes the script (SMS or call) there is only AT+CMGF=1 OK

so i installed minicom and when it executes the call command directly call/ Hang up works : minicom -D /dev/ttyS0 ATD+some_number; OK ATH OK

log:

2021-05-17 22:29:43,581 - gsmHat.gsmHat - INFO - Serial connection to /dev/ttyS0 established
2021-05-17 22:29:43,582 - gsmHat.gsmHat - INFO - Worker started
smartroad commented 2 years ago

I'm having the exact same issue. There is no serial data being sent to the hat. I have attached my logic analyser and tested with the sample code from pyserial:

`>>> import serial

ser = serial.Serial('/dev/ttyUSB0') # open serial port print(ser.name) # check which port was really used ser.write(b'hello') # write a string ser.close() # close port`

and I can see that is being transmitted, the RX led flashes and the LA shows the "hello" in binary form.

Using the examples from the readme neither of the LEDs flash and I don't see any data on the TX/RX lines.

smartroad commented 2 years ago

Further trial and error, I am using the code:


gsm = GSMHat('/dev/ttyS0', 115200)

Number = '+MYNUMBER'
Message = 'Hello mobile world'

# Send SMS
print("Sending: "+Message+" - To: " + Number)
gsm.SMS_write(Number, Message)

where MYNUMBER is actually my phone number. I added the print statement to check it was running and in the debug log I get:

2021-10-16 11:11:07,161 - gsmHat.gsmHat - INFO - Worker started
2021-10-16 11:11:07,167 - gsmHat.gsmHat - DEBUG - Sent to hat: AT+CMGF=1

if I remove the print statement I just get:

2021-10-16 11:09:44,879 - gsmHat.gsmHat - INFO - Worker started

So with the print statement the script is doing something but looking at the logic analyser it is showing the Pi transmits "AT+CMGF=1" with a line feed, the Hat then replies "AT+CMGF=1"CRLF"OK"CRLF

It doesn't seem the script is sending the actual text data to be sent?

smartroad commented 2 years ago

Forgot to say I am using Raspberry Pi Lite OS (latest off of the RPi site at time of writing) and using a Pi Zero W

smartroad commented 2 years ago

Right I have found the problem! Basically you need the script to keep on running long enough for it to actually send the instructions to the HAT. So taking my test code:


Number = '+MYNUMBER'
Message = 'Hello mobile world'

# Send SMS
print("Sending: "+Message+" - To: " + Number)
gsm.SMS_write(Number, Message)

and adding a while true loop at the end:


Number = '+MYNUMBER'
Message = 'Hello mobile world'

# Send SMS
print("Sending: "+Message+" - To: " + Number)
gsm.SMS_write(Number, Message)

while(True):
    a=0

will make the system actually send the message! At the moment it seems as long as your code is designed to run on an infinite loop (or at least run a few commands after the 'gsm' request, then it should send.

So @Luke050 it would seem all you need to do (assuming you still have the issue) is get the code to continue working after your request to call a number.

Swevrs commented 2 years ago

I had the same problem, but with the while loop i could not get the program to finnish so I just added the time function an set it to sleep for 5 sec. time.sleep(5) instead