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
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.
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,
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.
Hi Aaron,
You are absolutely correct. That is the issue. I think I have solved the problem however. One line of code was switched the network light off.
(The power remains on the entire time)
I traced it back to ‘power_down (power_key)’
in the second last par of waveshare sms.py demo code I was using as part of my script. When I switch that line off by #commenting it out, the network light stays on.
Thanks for you interest and input Aaron. I hope this little discovery helps anyone else try to implement sms-to-shell with the Waveshare demos.
—————————
Extract from Waveshare wiki 7600x demo
Sms.py
try:
power_on(power_key)
print(‘Sending Short Message Test:’)
SendShortMessage(phone_number,text_message)
print(‘Receive Short Message Test:\n’)
print('Please send message to phone ’ + phone_number)
ReceiveShortMessage() #power_down(power_key)
except :
if ser != None:
ser.close()
GPIO.cleanup()
———————————————
(My apologies for confusing the Waveshare demo with Tim’s modified demo version. I have been combining a lot of sample code from different places. Sorry folks)
Hi Everyone,
I am progressing with implementing the sms-to-shell.py script to automate and get sms messages from my Pi via Waveshare 7600x hat.
I have it working, but when it sends an sms back to me it follows with another sms with a ‘modem status’ type message.
For example: I send it an SMS instruction (using a predefined Keyword shortcut in the sms-to-shell.py),
it then sends me what i asked for (the temperature of my coolroom from the sensor) “Temp Coolroom: 3.5C”
BUT then sends “+CMGS: 50 OK” as a second sms immediately after.
Why am i getting this and how can I stop it?
It is costing me the price of two sms rather than one.
Anybody got any ideas where this reply message is in the code?
I am the author of the sms-to-shell script, so if you have specifc issues, you can always post these to github for wider sharing.
Here’s a few spitball ideas to mull over:
+CMGS: 50 OK means that the message with ID 50 was successfully sent. Look to the message queue of the modem to see what that message ID number was saying. Is it possible that another running script sent a message to the modem directly and this 50 OK is simply the return acknowledgemt being intecepted by sms-to-shell?
The sms-to-shell script expects to be the only operator/manager of the modem’s queue. 3rd party scripts that want to share the modem may require some sort of check/bypass depending on the originator of the message, or perahps 3rd party scripts could simply create outputs to send directly to sms-to-shell (as custom commands from an assumed phone number?).
Regarding the issue of the modem not initialised. Let sms-to-shell manage the power up and initialise of the modem. Also make both scripts a systemd service and make sure the 3rd party script is dependent on sms-to-shell being up and running first with something like this in the unit file:
To be able to run multiple scripts that access the modem and send sms, you could filter specific sms messages sent to the modem within sms-to-shell.
First declare some kind of indentifier that all 3rdp party script messages will contain. You will have to add this to all SMS text output from other scripts
FILTER_ID = "some unique thing in an sms message"
then add this directly above “if phone_number not in ACL” in the process_sms funtion
# Skip processing if the message contains the filter identifier
if FILTER_ID in content:
logger.info("Message skipped due to identifier '%s' in content: %s", FILTER_ID, content)
return
I’ve not tested, but something like this is the general idea to casue the sms-to-shell to ignore proceesing specific messages found in the modem queue whilst still managing the modem’s message queue so it does not clog up. If you do test, let me know how it goes as it could be a new improvement to sms-to-shell
Hi Dave,
Thanks for reaching our. Really do appreciate it.
Great idea to handle any conflicts in the modem, I will give it a go and let you know how I get on.
I do have other scripts (outside of sms-to-shell and use modem) that run and check temperature and current - and if out of range they send sms alert to me and then call me on the phone. (I own a small speciality food business that has a coolroom, and multiple fridges and am using it for monitoring.) However, they only use modem if there is a fault.
Please bear in mind Im a novice coder but have picked up a lot from just having a go. I launched sms-to-shell via crontab @reboot because i really struggled with systemd. I tried to install as Systemd and managed to crash my whole system - the micro sd card would not even reformat. But I made backups. I also tried to modify as Systemd user service.
I will login to Github for sms-to-shell work as i try to move forward and get it all working smoothly. If it’s ok i might ask a few questions later to get sms-to-shell working as recommended via Systemd root.
Cheers, and thanks for the support.
Paul
And you can get our latest projects and tips straight away by following us on: