Hacker News new | past | comments | ask | show | jobs | submit login
Simple Raspberry Pi Powered SMS Gateway (blog.haschek.at)
250 points by DeathArrow on Dec 5, 2021 | hide | past | favorite | 82 comments



The article is interesting in general, but this line really needs more than "works like a charm": `usb_modeswitch -W -v 12d1 -p 14fe -K -P 14ac -M "55534243000000000000000000000011060000000000000000000000000000"`

I mean, I believe you, but ... what on earth IS all of that?


Here's what it sounds like. Most of these types of devices (USB/3G) are "multimode" devices. That is, they can act like either USB storage or a USB 3G/4G device. On Windows, that's handy because it can come up as storage and then the end user can install the drivers right from the device, and the drivers then handle the "mode switching" from storage to 3G/4G-device. It's basically a way to bootstrap operation without requiring driver downloads.

This "usb_modeswitch" program handles that for linux. It sniffs the USB traffic and switches the mode to 3G/4G for you. All the crazy args are whatever was in the Windows config file. The -v 12d1 is the "VID" (vendor ID) of the device to sniff traffic for. The -p arg is similar, but the "PID" (product ID). The -P 14ac is the "PID" to switch to to get from storage to 3G/4G device. The -M <long-string> is the magic payload sent to the device to make it switch.


It has to be said here, that usb_modeswitch software already recognises most modems and has those magic strings saved in a file, and does the switch automagically.

Only if you have a relatively new or rare modem, you need to find the magic string yourself (or even reverse engineer it from a windows setup), to make it work.


This is a USB Mass Storage SCSI Command Block Wrapper packet as far as I can google out. Content looks like "Test Unit Ready 0001 0001 10 flag=true link=false". Could be completely wrong. Thank you for pointing this out, this is interesting.

55 53 42 43: "USBC"

00 00 00 00: CBW Tag

00 00 00 00: Transfer length

00 00 00 00: CBW direction, LUN, CBW CB length, CBW Command Block

00 00 00 11: CBW CB(cont.)

06 00 00 00: (same)

00 00 00 00: (same)

00 00 00 00: (same)

00 00 00 : (same)

---

00 00 00 00 11 06: TUR LUN0 RSVD RSVD RSV1 0001 0110

00 00 00 00 00 00: TUR LUN0 RSVD RSVD RSVD 00RS VD00

00 00 00 00 00 00: TUR LUN0 RSVD RSVD RSVD 00RS VD00

00 00: ?


I made something similar a few years back with a Pi 1 and a GSM "hat".

It came with a C SDK so I had to write AT commands to communicate directly with the modem and it worked great until I didn't need it anymore.

Its purpose was to text me when my power or internet connection went down at home then I could respond with commands such as to shutdown the servers etc.

When power/network came back it would text me the new address so I wouldnt need an outside service for DDNS.

The biggest challenge with the whole setup was finding a SIM from a provider who would let me top it up once per year and maybe send half a dozen texts in that time without deactivating the SIM, for a reasonable price.


The plans obviously exist at least at the wholesale level.

These: https://shop.blues.io/collections/development-kits/products/...

Come with pre paid 10 year internet data plans - but with a 500MB data limit (which you can top up), all for $79 including the hardware and interface board.

In raw bytes, that'd be enough to send 1000 140character SMS messages a day every day for 10 years. Realistically, there's probably a 10x or 100x overhead for the TCP/SSL/transport/application layers, but you'd probably still get al least 10 140byte payloads a day for a decade with one of those.

(Full disclosure, I have no affiliation with Bluers.io, but I did impulse buy one of those when they first appeared on my radar, which is sitting in the huge pile in my Box Of Unstarted Projects And Broken Dreams.)


Thanks! Now I have a Good Name[tm] for my "junk" box(es). :-)


> The biggest challenge with the whole setup was finding a SIM from a provider who would let me top it up once per year and maybe send half a dozen texts in that time without deactivating the SIM, for a reasonable price

Good point - so-called "pre-paid" SIMs seem to be hidden subscriptions nowadays. Does anyone have a table of suitable low-usage, long-term SIM vendors?


You might want to say what location you are in for a truly useful answer.

In the UK at least most providers keep the SIM active if it sees some activity in a given space of time¹ irrespective of top-up activity². So if “low” use stretches as far as one text every month or two maybe just have it send an “I'm still here” message regularly. Also acts as a double-check that not getting alerts means all is OK instead of that the alerting service is broken.

1: the GiffGaff one I used for pure data for a week-and-a-half when my landline was down in2020, shut off after three months and a few nagging texts IIRC

2: though if you don't top-up once per month you usually drop onto the basic tariff, so no more “unlimited texts”, but if you are topping up that infrequently that is probably fine


What would be the answer in the US?


https://www.twilio.com/iot/super-sim-card is one example.

Search for “US M2M SIM” for more vendors.


Looking at B2B IoT services is one way to find prepaid SIM plans that don't require monthly top-ups, but usually you have to buy 5+ SIMs so it doesn't necessarily fit the single-device use-case...


Instead of paying for a separate SIM, I've been piggybacking on the "data only" SIMs that Google Fi let's you add to a normal subscription. No extra per-SIM fees, and you just pay for whatever data it uses at $10/gb.

More details on my modem, monitoring setup, and IPMI backhaul strategy using Wireguard here: http://jsharkey.org/ipmi/


That sounds like a nice idea. Unfortunately I don't believe anything similar exists here in the UK.

I can pay my mobile provider an extra £7.50 per month for a "second SIM" to share the allowance from my main SIM (you're effectively paying to rent another number).

It's not a terrible expense, but for something I need to send an SMS maybe 1 per quarter is a little much. I guess if you look at it as a "service" it's not bad, but this was a home thing, nothing critical would be lost if I couldn't get my home IP until I got home. Now I use DDNS using a small piece of Go code I wrote to update the domain on my Digital Ocean account as a form of "free" DDNS, it runs on my router on connect/reboot.


It surprises me how many people are willing to let Google know their home address.


You don't need Google Fi for Google to know your home address. An Android phone will do that. Or Chrome. Or really just broadcasting wifi. Really the problem is you have a home address and someone will sell it to Google.


I like what you did there. Google is a given, a person having a home address is the problem, the collection method is a variable solution.


They already know.


I like the country wide LoRa networks that are coming up helping with this purpose, all you need is like 1kb per month lol


A good free way to achieve this is to use Signal. This project https://github.com/AsamK/signal-cli enables you to send Signal messages from the command line, including from Raspberry Pis. It obviously needs an internet connection to work, but has the added bonus of being more secure than SMS.


Neat tech, but probably not super appropriate for this person's particular application, which involved detecting network outages.


I'm guessing if that USB Modem can send SMS, it can almost certainly also get a TCP connection. (It is probably easier to find a sensibly priced SIM/plan that lets you sand a handful of SMS messages a year compared to one with a ultra low data usage internet connection though.)


Just a heads up to anyone thinking of doing this in prod.

We had a USB connected 3G dongle as SMS modem for years, every other month someone had to head over to the DC and re-seat the thing. Because it just stopped working. I don't think they're designed to be connected 24/7.

We eventually switched to an Ethernet connected SMS modem. Much more reliable, and it was actually made for production, had a longer antenna you could fix on top of a rack cabinet.


Can you point me to some brand who sell those?


Not that one, it was many years ago and I have moved on from that department since.

But it was also purchased in Sweden, from a Swedish retailer, so not sure what good this would do you.

A quick google gives me Induo [1] who make industrial 3G modems, with serial connection among others.

1. https://www.induo.com/produkt/modem/3g-modem/


I wrote a similar project this year that runs on my router, in python. I communicates with ModemManager over dbus. I use a Quectel EC25 LTE modem, it forwards incoming SMS to an https webhook as JSON. It listens to http requests to provide an outgoing SMS gateway. It also provides automatic failover for the WAN link, for when Comcast craps out. On another machine I have python script that bridges with prosody, to provide an SMS-XMPP bridge. It works well, receives messages faster than the SMS api services that I have tried, and since it's a real mobile number it works everywhere for 2FA.

ModemManager is great, abstracting away manufacturer specific implementation details. The same script is also working on a Pi connected to The Franklin T9 hotspot that I got for free from T-Mobile, running in QMI mode.

I wish it were easier to bridge voice with asterisk, but from what I have seen it is necessary to run asterisk on the same device and communicate directly with the modem, with modem specific tweaks and custom built modules.


I’d be curious to know what carriers I could use with the dongle here in the USA..? I’ve been trying to make an IoT project and being that T-Mobile is shutting down their 3G GSM there’s only a few IoT devices that are licensed and approved for use with Verizon and AT&T for the 4G band. :/


Shouldn't be anything special to what you were doing with 3G, there are dozens of cheap 4G dongles or hat and certification isn't really any more special (heck Verizon even recommends and shows how to set up and configure a particular $30 5G/4G modem they connect to a Pi in their ThingSpace tutorial).

As far as plans every major carrier has 4G IoT plans, prepaid or not depending on what you want. Also look into places like Databalaze if you're doing something at scale commercially.


It’s been a while since I’ve checked ThingSpace but looking at it now they have the SixFab hat listed..

Few years ago I bought the 4G hat from SixFab because it was marketed as being Verizon certified but it never worked. I’ll have to look into things again…


Gammu seems like an ideal candidate for a Home Assistant integration or add-on. Could use incoming SMS as triggers and outgoing as notification methods.


iirc, i can send AT command directly to ttyUSB0

https://openwrt.org/docs/guide-user/advanced/sms-from-shell

no need to install gammu etc


> MMS or Multimedia Messages are supported by gammu but they are stored in a binary format I have yet to find documentation on how to make something usable out of it for download. Any info in it is greatly appreciated.

You could look at this implementation: mmsd-tng [1]. It is used to handle MMSes on the PinePhone for instance.

[1] https://gitlab.com/kop316/mmsd/


Why not have even less moving parts? Nearly every SMS/MMS address is backed by an email address. Look up email to sms gateway list and go for it, sans dongle.


Sending an email requires a data connection, which might not be available when the power goes out.

When there's a local power cut, most people switch to using cellular data, overloading the local backhaul. The same problem doesn't affect outbound SMS.


This is great for situations where your Raspberry Pi doesn't have any other internet access. But if you do have and ethernet drop or Wi-Fi you can also use your carrier's email to SMS gateway!

For example "[YOUR-PHONE-NUMBER]@txt.att.net"

https://www.dialmycalls.com/blog/send-text-messages-email-ad...


As long as it isn't critical that your carrier's gateway is operating normally.

I have a customer that routinely emails through various carier's SMS gateways, and has reports several times a month that their messages aren't getting through and ask us to verify everything was handed off correctly. It always was handed off good, but their gateway is backlogged or broken for that half day or day.

This echos my direct experience years ago (before I made my own solution similar to this setup).


That's pretty straightforward and nice. I'm curious if there are some good references to where the cheapest US SIM+plan would be if you only care about sending SMS messages.


Back in the day - 15 years ago - I built web apps for clients that sent SMS by merely sending an email to the email alias for that SMS destination. Is that no longer possible?


An LTE-M pi-hat would be awesome! Usually the biggest challenge for projects like this is to find cheap and available modems that can actually be used with reasonable GSM carriers.




5 years ago, I built the same SMS gateway without using the AT command "Explicitly" [0], but by letting Kannel handle that for me. Thus, I had an endpoint generally usable. Kannel is still used by Mobile Network Operators in Africa.

[0]: https://hackernoon.com/build-an-sms-center-with-python-kanne...


Is there a generic app I can install on my phones that lets me push notifications to them from curl?

It would be incredibly useful if Apple (or a third party app) gave people a way to POST to some secret URL and have the form data show up as a notification.

I can think of a billion one-off projects that would benefit from this. The smoker/ribs are done, the pool is up to temperature, a post-interview email from that recruiter has finally arrived, etc.


If you're on Android, there's Gotify [1]. You can self-host the server and install the app on either the Play Store, F-Droid, or just by downloading the APK.

[1]: https://gotify.net/


[replying to myself]

Notifications from macOS are possible with osascript:

https://github.com/lodestone/ims/blob/4bb2566224af53904c7267...

Or in brief:

  osascript -e 'tell application "Messages" to send "Hello World" to buddy "J Appleseed"'


There is Push Bullet but they removed it from apple app store last year. Too bad. It's actually fit your use case very well. https://docs.pushbullet.com/#create-push


I use Pushover for this: https://pushover.net/


You can probably achieve the same effect with the telegram API and an afternoon of coding.


No.

That would take value add away from apple et all.

Install Xorg.


I wonder if I can integrate this with a matrix server so I can send/receive SMS from a carrier-issued SIM via a Matrix client like Element.


I’m not sure if anyone actually looked at the code for the PHP-based API-gateway, but as a TLDR: it’s trivially injectable to give RCEs and not really hardeneded nor is input sanitized properly at all.

I realize this is meant for deployment on a local trusted network, but I still think that’s worth putting somewhere in big bold fonts.


I'd love to get a setup like this with voice calls also supported. I'd like to be able to recieve my calls and texts on any device as I can with email/irc/matrix etc


If you don't absolutely need this to originate from a mobile subscription with your name on it, you can for far less money get a DID ("direct inwards dial"; the term colloquially means a virtual mobile number) with any of the numerous VoIP providers out there. Most of them not only provide in- and outbound calls on those DIDs, but also ditto for SMSes. The interface for voice calls is almost exclusively SIP, and for SMSes it's usually an HTTP-based API.


If you go this route, make sure you absolutely know how to, and that you absolutely lock this down. SIP toll fraud is still a problem and if it happens to you, it can get destructively expensive.

https://www.twilio.com/learn/voice-and-video/toll-fraud


Common sense obviously applies. With a cell phone, don't call back to unknown numbers ringing once or twice ("wangiri"). With a SIP trunk, don't allow remote anonymous access.


Yeah I suppose it's really easy to call this common-sense, it probably should be common-sense.

Yet at the same time, if it were common-sense in practice, I probably wouldn't have a job.


These services are great, except for the sites with mandatory sms 2fa that refuse to send to voip phone numbers (I'm looking at you, Apple).


If you use XMPP checkout https://jmp.chat/ .


This is pretty interesting, I'm going to give it a go setting something like this up with ejabberd and their asterisk fork, that way I can use my own sim cards.


My first though when i read this was "um... Twilio, Telnyx and Signalwire all do texting... why do i need... (facepalm) network down... ahhh!!! Bookmarked!" very handy!


I was looking to get a dedicated Waveshare GSM HAT for the Pi but Twilio is so dirt cheap that I never really got into messing around with a DIY solution.


At 6 cents/SMS, I find Twilio and similar services way too expensive. Compare that to the unlimited SMS plan that I can get for 2€/month here in France, and setting up a gateway like that becomes very attractive.

In my experience it's very unstable however. Sending and receiving SMS can take anywhere from 5 to 30 seconds, and the modem can't do both at the same time. I tried configuring gammu's timeouts, loop delays and whatnot, but couldn't get something that's reliable enough for production.


Free's €2 per month is probably one of the best mobile deal in the world :). Beware though, last I checked using their SIM card in something not a mobile phone was against Fred's ToS. I don't know if it have since changed.


I can send unlimited SMS for free with my 5€ monthly plan, so why should I pay?


Hey DeathArrow.

Very very strange I'm the author of the article and I created this post and got the first few comments then when I reloaded the page it says you posted it and I can't upvote the post like it was my own.

What gives? Do you work for ycombinator or somehing? Or did you post it shortly before me and the mods combined our posts and attributed it to you?


Mods combining posts and choosing the wrong winner sounds most plausible. Just email them and they'll make the correction because they do a dang good job.


> ...a dang good job.

I see what you did there.


I don't know what happened. I don't work for HN. You can ask the moderating team.

I just read your article, thought it might be of interest to HN and posted the link here.


Does anyone know of an inexpensive plan in the US to use with a setup similar to this that sends dozens of text messages/month?


I was investigating solutions for sensor SMS notifications & the best IoT type SIM plan that I came across was https://www.hologram.io/pricing/flexible-data . $1.50/line per month, $0.19/outbound SMS, data is pricey.

If you need more SMS, the next cheapest I've used is RedPocket Mobile-- https://www.ebay.com/itm/2-50-Mo-Red-Pocket-Prepaid-Plan-200... - $30/yr for 200 voice/1000 texts/200mb per month on T-Mobile's network.


US Mobile has very cheap plans, and you can build your own.


Ultramobile PayGo - $3 per month on a month to month basis, 100 mins talk, 100 texts, 100 mb data.


Id love something like this with meshtastic/Lora support to link a mesh to cell via SMS


Some dongles can be hackable so the RPi is not a necessary requirement.


Whats the max throughput here? Would the carrier be the bottleneck?


I have read that the typical consumer wireless account is for "personal use" and is limited to a "few hundred" SMS messages per day. The service provider may define exactly what "personal use" means at their discretion.


Sure, they will throttle or suspend your SIM if you send out an abnormal number of SMSs to prevent spam.


Is there something similar but for Whatsapp?



Funnily enough that was the route I was initially going to go but I got scared because I read that the project is a violation of the ToS and your number _might_ get blocked if you use these third party clients.

That's why I wrote the article on how to do it via SMS with a Pi. I tried to send myself notifications from NodeRed


> I read that the project is a violation of the ToS

Could you find that source? Curious precisely what part of ToS it violates.





Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: