Waveshare 7600X RPi automation via SMS

Hi Tim,
Your tutorials are great thank you.
I have successfully implemented the sms and phone call functions using 7600x hat as per your tutorial 4G and GPS HAT For Raspberry Pi - Waveshare SIM7600X - Tutorial Australia .
I now want to use Dave’s SMS-to-Shell on Github (GitHub - itiligent/SMS-to-Shell: Secure remote control & interactive linux shell access over SMS. (Supports TOTP auth for remote shell commands)) (that you also included a link to) to continuously monitor for incoming sms commands and then to execute my scripts.
My question is; you use the ‘power_on’ and ‘power_down’ in your sample code to send an sms or phone call. This it seems would shut down the modem and then restart it each time and thereby turn off the monitoring by Dave’s script?

I would like to keep the modem on standby to receive any incoming sms instructions and to perform a number of functions in a row (for example receive sms instruction, then check temperature of sensor and send sms reply and then wait and then phone call) Is there a way to do this with the code rather than startup and shutdown the 7600x each time?
I did try removing sections of your sample code, but am unsure how this would impact on the modem. I am not sure what best practice is with the 7600X and which parts of the code are essential.
Any advice regarding this would be greatly appreciated.
Regards
Paul

Hi @Paul264093, Welcome to the Forums!!!

From what I can tell from the sample code and Waveshare’s Product Wiki It shouldn’t matter if the HAT left turned on. Depending on the power jumper the Power con command in the software won’t work and the HAT will stay on as long as the Pi is powered.

Being able to restart the HAT in software may be helpful if it has issues or locks up.

Thanks for your reply Aaron.
I’ve done some more testing and it appears there is definitely an issue with the way the different scripts initialise the modem 7600X HAT.
When I us the sample code from Tim’s Tutorial it uses the ‘power-on’ and ‘power_down’ method. After running the demo code the SMS is sent , the script finishes, and one of the lights on the 7600X turns off. The ‘Network’ light turns off, the ‘Power’ light stays on.
As a comparison, with both lights on to start, I ran David’s test-sms.py (GitHub - itiligent/SMS-to-Shell: Secure remote control & interactive linux shell access over SMS. (Supports TOTP auth for remote shell commands)) which uses a different method to initialise the modem via serial.
“# Initialise modem connection
modem = serial.Serial(MODEM, MODEM_BAUD_RATE, timeout=1)”
David’s method will run multiple times without a problem.
However once I run Tim’s demo (which is pretty much the same as the Waveshare Wiki example) then the ‘Network light’ goes off (power light stays on),
then David’s code does not work.
It all seems to relate to how the code initialises the modem. I really just want to have the modem to stay on ready to receive sms instructions at all time, and to stay on after completing each process ready for the next.
I am pretty new to all the coding, but muddle my way through, recognising as much of how things work as possible.This has however got me stumped. Any ideas for a solution are much appreciated.

Hey @Paul264093,

You are indeed correct that the difference lies in how the HAT is initialised, but it should be relatively easy to reconfigure Tim’s script to run on a timed loop instead, or await a message to respond.

Within GPS.py it seems the get_gps_position() function is designed to only run once after power_on. My thoughts are that you could modify this to run on a loop, or be called whenever another function receives a message.

Specifically,
image

Could be modified to say (in pseudocode):

try:
    power_on
    while:
         check for message received on a timed loop:
               if message received, send response, then wait 20 seconds
               
               if no message received, wait 20 seconds

Maybe give this some thought, if you’re still a bit stumped I’d be happy to offer more help.

Thanks for the advice. I do really appreciate it.
I am however trying to achieve something a bit different.
I want to run the SMS-to-Shell Github program, continuously, which it does.
This will watch the modem for any incoming SMS messages I send. When it gets my SMS it will then execute the command… ( A preset command)
This command will run a script which has two parts; (1) checks temperature from a sensor .
(2) Then sends me the temperature in an SMS using Tim’s script (sends Temperature rather than GPS coordinates)
It all works well, except that Tim’s example script ‘powers on’ the modem which is already running and then ‘powers off’ the modem 7600x HAT ( which does not actually turn off the power, just the network light)
Then the Shell-to-SMS stops working because the 7600X network light is turned off.
The solution I think is how to modify Tim’s sample script to just; check the modem is running -then send the SMS and end script.
I am trying to modify Tim’s example, because the modem scripting is a bit complicated and I am only a cut and paste beginner coder.
I hope that explains things better. I am confident there is a way.