
About a year ago we
launched our small project with alerts about breaks in the Moscow metro.
The main problem in it was sending SMS. We did not expect the project to be liked and we will have 1500+ registrations. In the best case, we counted a man on 300. With this we were pleasantly surprised.
The problem with SMS in the first place was because of the price. One mailing turned out about 3000 rubles. Taking into account the fact that the price of 1 sms 1.5 rubles. There were times when there were problems in the movement of trains every 3 days, i.e. 10 breakdowns per month. 3000 * 10 = 30 000 rubles. Expensive for a project that is not funded.
')
Then we started to reinvent the wheel. Namely, look for tariffs with really unlimited SMS. As a result, we found it. It cost something about 600 rubles per month. Then it was necessary to solve the issue of sending SMS. And here came the time of the ancient nokia 6610i, which was gathering dust in the closet as a memory of the bygone era. But it had to be slightly modified, namely to connect via uart to the laptop in order to send tasks.

Scheme
A pair of diodes is needed here to release the voltage from 5V to ~ 3.4V. The fall on the diodes is a total of 1.6V at a current of 1A. Such a current of Nokia consumes only with active work with the network, and most of the time the drop on them will be about 1.5V.
A large and thick capacitor is needed to smooth the consumption of the phone at the moment when the transmitter is working, and it eats a lot.
And the resistors replace the thermistor and the battery identification pin (BSI), according to which nokia understands that a battery is connected to it.
We did not find suitable resistors, so we collected them from what we had.

For sending, the program gnokii was used, from the name of which it is quite obvious that it was written just for such purposes.
Config from our 6610i:
[global] port = /dev/ttyUSB0 connection = dlr3p model = 6510
Command to send
echo 'text' | gnokii --sendsms number
To send it was possible not only by root, you need to set the appropriate rights to / dev / ttyUSB0
I liked what we could answer, and they answered us. But the problems did not end here, namely, the speed: this dispatch took 4 hours. Therefore, in this way we sent information that is relevant for a long period, for example, about closing a part of the line for repairs. 1 sim card was enough for us for about 3 thousand messages, i.e. on a couple of mailings. Then we were blocked. We called TP and asked for the reasons for blocking, what we were told about - distribution. Once we had one SIM card for 5 mailings, timeouts did more and changed the text. And we were always lucky for beautiful rooms - a trifle, but nice.
And since in the usual case, we have the relevance of information 40 minutes, the newsletter should ideally be in a couple of minutes. Therefore, we decided to make a newsletter on the phone with Android. The main advantage of this solution was speed, though also far from ideal. 1 SMS was sent in 1.5 seconds, which resulted in approximately 37 minutes. Then it was possible to parallelize by connecting another phone and achieve the desired speed. But here we were strangled by the operator who blocked us either in the middle of the first mailing or at the beginning of the second.
The application logic is to periodically receive the job from the server. About once every few minutes, the application turned to the server for a command in json format, which consisted of an array of phone numbers and SMS texts.
We had a stream to pick up the team with a timeout, a stream for sending sms, BrodasReceiver to run after loading. But the project was lost due to prescription, so there will be no complete code. We cut the SMS text to a maximum of 1 SMS - 70 characters (this is for Cyrillic), the server part did it, but just in case the SMS sending was exactly 70 characters long:
SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("NUM", null, "TXT", null, null);
not forgetting the rights to send sms to manifest
<uses-permission android:name="android.permission.SEND_SMS" />
For autorun after switching on, do not forget about the rights:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Register in the manifest:
<receiver android:name=".Boot" android:enabled="true" android:exported="false" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
Boot code:
public class Boot extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { } }
Autostart in case of a dead battery and other similar situations, I’ll forget to start the application after switching on. And only this application lives on this phone, so we are not afraid of some waste in relation to the battery.
Well and in Activity we add start of a flow.
We also allow the application to access the Internet:
<uses-permission android: name = "android.permission.INTERNET" />
And another important point is that in order for our application to work even with the display off, you need to call PowerManager. Otherwise, the system will put the application to sleep at will, in order to save charge, and requests will be executed irregularly.
To do this, add permishn:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Add the code to the Activity:
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP| PowerManager.FULL_WAKE_LOCK| PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "");
And in the flow
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ""); wl.acquire(); , json wl.release();
This method also did not work for a long time, because constantly changing SIM cards was not very convenient and rational - the price tag was growing rapidly and it lost its meaning.
Then we tried to send through Whatsapp, but then the numbers died every 10 messages, and even faster. And registration of 1 number cost 7 rubles. We again began to go out on the same numbers with which we started.
And not so long ago we made a bot for telegrams -
https://telegram.me/msk_metro , everything is the same as with PushBullet, which we connected at the request after the first post on Habré. Only here can we delete messages that have been moderated by chance, but not in PushBullet.