Waveshare 7600X RPi automation via SMS

Hi Dave

Not terribly painful.
Not using Linux or RPi. This sometimes happens when I copy and paste from a web page or whatever straight into an Arduino sketch on the Arduino IDE. Seems to copy some hidden funnies in the process. Deleting suspect line then re typing seems to get rid of whatever is in there upsetting the compilation process. Does not happen all the time but when it does not compile when it is exactly (cannot be exact or it would work) the same as a working sketch retyping is my first fix attempt. Mostly works.
Cheers Bob

1 Like

Hi Dave,

I tested the FILTER ID idea you suggested as below, but it didn’t solve the
AT Commands that are occurring as a followup SMS after the intended SMS.

I am happy to test any other ideas you feel might be worth trying.

I tested using your ‘Test-SMS.py’ as F7 shortcut in ‘sms-to-shell.py’

I got ;
(1st SMS)
This is a test sms

(then 2nd SMS)

+CMGS: 96

OK

OK

I am puzzled as to what is making it send the AT response SMS after the initial SMS.

I also tested waveshare’s 7600X HAT ‘demo code’ SMS.py
and got three separate SMS of AT Commands telling me what it was doing.
So same problem but with more verbose AT response.


I feel a little context might be useful, just so you have an overview of how I am using
‘sms-to-shell’
I am using the ‘sms-to-shell’ script to monitor for my incoming sms commands.
I am adding my own commands to the ‘keyboard shortcuts’ built into your code.
For example: I send ‘F1’ as an sms to the modem.
‘sms-to shell’ gets the sms and executes the command for F1
This runs a python script that gets the temperature from a sensor and sends it back to me as an SMS; “Current coolroom temp is 4.5C”

I also have other commands that send a CSV spreadsheet temperature log via email and other things like that.
Interesting the email script sends me an SMS with:

‘Email with CSV sent
OK’

I gave it no instruction in my code to SMS anything to me.
The end part of my code is:

print (‘Email with CSV sent’)
so it is apparently getting the response from there


For your reference;
[Below is my placement of the test code within your program - so you can see if I put it in the correct place.]

I put this at the top with the Script parameters

FILTER_ID = “Z1Z”
####then included the ‘Z1Z’ in the SMS message that went to the modem for sending.

Excerpt from ‘sms-to-shell.py’ to show you where I put the code for testing.

Between these two pars.

Print debug information

    print("Received SMS:")
    print("Phone number:", phone_number)
    print("Command:", content)
    # Log the phone number, time, date, and command received
    logger.info('D: %s T: %s Ph: %s Command: %s',
                time.strftime('%Y-%m-%d'), time.strftime('%H:%M:%S'), phone_number, content)
    

    # 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
    

    # Check if the phone number is allowed
    if phone_number not in ACL: # make ACL a black list by reversing line to "if phone_number in ACL:"
        # Phone number not allowed, send rejection message
        rejection_message = "Access denied"
        send_sms_response(modem, phone_number, rejection_message)
        logger.warning("D: %s T: %s UNAUTHORISED ACCESS ATTEMPT Ph: %s Command: %s",
                    time.strftime('%Y-%m-%d'), time.strftime('%H:%M:%S'), phone_number, content)
        return

Any ideas welcome. Cheers Paul

Thats quite a brain dump, but unfortunately you’ve not offered the most relevant info and are thus overlooking root of the issue… The verbose output from the test script and the actual activities perfomed by your temperature script are more relevant than anything else here.

With the CSV email script, to me it looks like sms-to-shell is doing exaclty what is is supposed to… that is… repeat script shell output a command. You will need to tune your scripts in consideration of the shell output that will be gernerated by these, and how to discard unwanted sms shell output in cases if you dont want any SMS returned eg /dev/null, 2>&1 etc.

With the temperature script, you need to dive into the meaning of +CMGS: 96 to better apreciate the command flows you are sending to the modem. This sort of error indicates a mistiming/misordering of commands - indicating a confilct of instructions fed to the modem. Bottom line is that the temperature script also wants to interact with the modem by sending commands to it… but these are not sanity checked or parsed by sms-to-shell’s loop, but as sms-to-shell monitors the modem queue it still tries to deal with them… hence errors and duplications. This is a conflict sms-to-shell cant handle, and remember modems are too dumb to care where instructions come from.

EDIT: My filtering suggestion can be done but will need work to capture all scenarios with how your other scripts are accessing the modem. It seems like you were filtering a shortcut command output, but if that command runs another script that inserts more commands to the modem - this will always bypass the filter and leave items in the modem loop that skip the filter. The only way to do this would be to add to some logic to qualify every step in the script, and also ensure that 3rd party script output also included suitably identifiable content.

All this is getting complex, and if you think laterally about what you want to achieve…its actually very simple…

Why not, instead, simply write your script to generate simple shell output that displays the temp info…then this shell output will be automatically picked up by sms-to-shell and relayed back over sms?

Bottom line, you must avoid any other scripts fighing over access to the modem. Let sms-to-shell be the only script that processes anything going to the modem, and tune your script outputs to suit this approach.

3 Likes

Hi Dave,
Sorry for the essay, I was trying to give as much info as possible hoping it would shed some light on the problem.

I’m not quite sure where to go from here,
as my knowledge and troubleshooting skills in this area are limited.

As even the simplest scripts, including your Test-SMS.py are returning an AT content second SMS. It doesn’t feel to me that the scripts are the main cause as they are all so different, yet producing the same problem.
I could be wrong, but feels like something they all share in common would be the problem.

Does sms-to-shell get feedback from the scripts it runs via the shortcuts eg F1 ?

Is it possible for the modem to have an echo function active in its normal operation (like ATE) that is causing this kind of problem?
Otherwise would it be worth resetting the modem back to default? (Not that I have changed anything)
I am thinking of wiping the whole card and starting from scratch. However if the issue is in the modem, that may need a reset. So that I can rule out some possible causes.
I have emailed Waveshare to see if they can offer some assistance, however I am not holding my breath for that one.
Thankyou for your patience and assistance
Cheers Paul

2 Likes

Some extra background that might help explain:

  1. Sms-to-shell is a framework that very carefully sets up a series of modem environmental settings via AT command, and also carefully manages the modem’s queue of read messages so it does not run out of memory and hang or drop new commands.

  2. sms-to-shell has several delicate steps that each monitor, read, parse and respond. I am trying to explain how against this quite manmaged backdrop you are blasting extra unmanaged commands at the modem. It is just not reasonble to expect things to work here as sms-to-shell can only pick up and try to parse the extra messages, but with no corresponding shell commmand.

  3. I reiterate: Your issue relates to the fact that two seprate scripts are sending and reading from the same modem, it a bit like marrying two ladies at once! Your test script is also quite possibly adjusting various other modem settings on the fly via AT command that will also conflict with what settings sms-to-shell expects - this might explain the 96 error. I cant put it any more clearly - this is the root of the “common” problem you are experiencing.

How to solve:
Re-write your scripts to get the results you are looking for and skip the part where they send their results the modem. Instead, have your scripts either echo a result to the shell or add it to a file that is to be emailed. Any script called from the shortcuts will have its output replayed back to you by sms-to-shell… (you just need to make sure that this output is controlled and does not spam you.)

1 Like

I forgot to mention

+ATZ resets the modem to factory. Do this EVERY time you play with a test script.

There’s a lot to learn with modems and AT. FYI a lot of those downloaded test scripts will set up conflicting AT settings and mess up your default settings. Fun fact - in learning how to work with the Waveshare modem I had to deploy a Chinese version of Windows to be able install and to run their published management tools to decode the default hex/chinese character map. sms-to-shell resets all modem defaults to ensure a character set native to html and western language defaults. So, as I’ve been saying… its not just a matter of blasting away with python when it comes to AT.

Look here for more on AT that I figures out when writing sms-to-shell

1 Like

Thanks Dave,
Sounds like you did everything short of actually learning Chinese.
Appreciate all the work that’s gone into the program. It was obvious from looking at it first time that it was a very comprehensive bit of software. Thanks for sharing it.

And thankyou for the previous explanation. The more I understand the role of the different components the more I learn.
Cheers
Paul

2 Likes

Hi Dave,

Good news is I’ve made some progress following your helpful info. Thankyou.

I have been working on applying your advise to;
“Re-write your scripts to get the results you are looking for and skip the part where they send their results the modem.”

I have had some success.
I send sms to sms-to-shell, it then runs ‘F4’ which includes two commands. (writes temperature from sensor to text file, waits 3sec, then CAT command reads text and I receive the output to my phone.)
It may not be elegant but it works and I get the result with just one sms.

This solves part of the functionality I need. (I did try echo, but lacked the know-how to make it work)

I have one more issue to solve.
I need to get an alert via sms from the host raspberry pi, if temperature is out of range. (when there is no power or internet. I have UPS etc all sorted.)

My questions are;

Is it possible to trigger one of the ‘sms-to-shell’ shortcut commands (eg. ‘F1’)
from the host raspberry pi (instead of external sms)?

Is it possible to send an sms from sms-to-shell as a shortcut command?

My thinking is:
Maybe there a way to keep the alert message sending in-house in the sms-to shell framework to avoid modem conflicts.
I could email, but I really need an immediate alert.

Hope Im not doing your head in with my work in progress.
Im sure you have other things to do besides.
Any suggestion however are greatly appreciated.
Cheers
Paul

1 Like