Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with SMS? #14

Open
heavyimage opened this issue Oct 3, 2024 · 10 comments
Open

Integration with SMS? #14

heavyimage opened this issue Oct 3, 2024 · 10 comments

Comments

@heavyimage
Copy link

Hello,

Is it possible to use the new wireless firmware + the clipper LTE module to not only get a pico online but also receive / send SMS?

@Gadgetoid
Copy link
Member

I'm pretty sure that it is, though I'm not sure if there are any relevant limitations with the SIM cards.

The downside is that it would currently involve raw AT commands and I believe you have to set up an additional command channel so that normal commands can still work while in PPP mode. I haven't explored this yet.

https://www.ktron.in/wp-content/uploads/2023/03/A76XX-Series_AT_Command_Manual_V1.06-4.pdf?srsltid=AfmBOorE2r1TGAW2YQfJeWRJXpDzKe2FOL6v9YmGLx-BOVJNm8SRemg5

@heavyimage heavyimage changed the title interation with SMS? Integration with SMS? Oct 3, 2024
@heavyimage
Copy link
Author

Thanks! I've been playing with this for a bit and using some resources (documenting here if anyone wants to try!)

...but I can't seem to get the anything but a timeout in response to the AT+CMGS command that starts the creation of a text message. I think the modem is supposed to reply with ">" indicating it's waiting for a message?

Maybe is a limitation of the 'data only' SIM that came with the clipper?

Here's some very rough code / lines I've been testing with but I can't seem to get past that. Again, for posterity:

# switch to text mode?
print("switching to text mode")
#con._send_at_command("AT+CMGF=1", 1, 10)
# read text mode values?
#con._send_at_command(b"AT+CSMP?", 1, 10)
#AT+CSMP=17,167,0,16
#print("Sending message")
#con._send_at_command('AT+CMGS="[REDACTED]"', 1, 3)

recipient = "[REDACTED]"
message = "Hello, World!"
#con._send_at_command(b'ATZ',1 , 10)
con._send_at_command(b'AT+CMGF=1',1)
con._send_at_command(b'AT+CMGS="' + recipient.encode() + b'"',1, 20)
con._send_at_command(message.encode() + b"")
con._send_at_command(bytes([26]))

@Gadgetoid
Copy link
Member

I think the problem is that _send_at_command will always time out if nothing is returned, but no return value is given until after the message data has been sent.

It also needs a small delay (it would seem) between CMGS and the actual message body, so we can't send it in one transaction.

Try:

con._uart.write(b"AT+CMGS=\"[REDACTED]\"\r")
con._uart.write(b"Hello World\x1a\r")

@Gadgetoid
Copy link
Member

Gadgetoid commented Oct 4, 2024

Or, to slap that into a function (which I'll add to the lte module I think):

def send_text_message(recipient, body, timeout=5.0):
    con._uart.write("AT+CMGS=\"")
    con._uart.write(recipient.encode("ascii"))
    con._uart.write(b"\"\r")
    time.sleep(0.5)
    con._uart.write(body.encode("ascii"))
    con._uart.write(b"\x1a\r")
    con._uart.flush()

    status, data = con._read_result(1, timeout=timeout)

    if status == "TIMEOUT":
        raise CellularError(f"cellular module timed out for SMS command")

    if status not in ["OK"]:
        raise CellularError(f"non 'OK' result for SMS command")

(Edit: don't need to multiply the timeout by 1000, oof)

Gadgetoid added a commit that referenced this issue Oct 4, 2024
Also a quick cleanup of the lte module code.
@heavyimage
Copy link
Author

Hrm, this still isn't working for me :-/

  • Are you using the SIM that came with the clipper module?
  • What is the syntax of the phone number you're using? with +? +44? Just the number?
  • I'd love to submit a PR once I get this working that also includes the ability to read messages -- how are you testing this? Building a whole .uf2 and deploying it?

@Gadgetoid
Copy link
Member

  • I am using a Lebara sim, unsure about our data ones (could be a limitation, I'll ask!)
  • Both work!
  • I am just sticking Python code into Thonny and testing against that
  • to continue, I have a local copy of the lte.py, saved as tlte.py (name is arbitary) and run:
import gc
import tlte as lte
import time
import requests
con = lte.LTE("APN")

Then just hack around on the repl until something works (in Thonny, at least, the context of an executed Python script is kept and you can use those loaded functions/setup connections etc in the repl).

@heavyimage
Copy link
Author

okay thanks! My setup is pretty similar. I'll keep you posted :-)

And thanks for much for the help on this -- happy I was able to nerd snipe you :-)

@Gadgetoid
Copy link
Member

It is, indeed, a limitation of the sims we sell- they're data-only!

@heavyimage
Copy link
Author

AHA! Okay. Cool. I think I've got another one somewhere for exactly this kind of emergency 👀

@Gadgetoid
Copy link
Member

Sounds like a job for an SMS -> MQTT gateway. Something like https://www.instructables.com/Two-way-MQTT-SMS-Bridge-Linkit-One/

Would be an interesting project for the LTE Pi HAT 😆

Gadgetoid added a commit that referenced this issue Nov 21, 2024
Also a quick cleanup of the lte module code.
Gadgetoid added a commit that referenced this issue Nov 21, 2024
Also a quick cleanup of the lte module code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants