📜 ⬆️ ⬇️

Free SMS sending from Arduino without GSM module



It took me to send an SMS from arduinin to my phone. Yes, so that would be no problems with GSM, SIM cards and payment. Under the cut that came out of it.

Since GSM is not suitable, you will have to send via the Internet. In the bins there was a super cheap Wi-Fi module ESP8266. You can read about its pre-setting in this excellent article link .
First of all, it’s useful to google various internet services for sending SMS. There were many services, but there was no suitable one among them. Either 10 SMS per day, or want money. And the captcha arduinine too tough. But here I accidentally stumbled upon an interesting service of my mobile operator (MTS BY) - for only $ 1 you can connect the service of receiving email in the form of SMS link . Well, it didn’t work out completely free of charge, and after the payment I received an email address of the form 375XXYYYYYYY@sms.mts.by (where XX and YYYYYYY are the network code and number). That is, it all came down to banal sending email from arduino.

But it was not there. It turns out recently that all self-respecting mail servers refuse to accept mail on port 25 and without encryption. But I didn’t want to get involved with others, as well as being attached to my home server. Here is such a service link . In the basic free version they give 6k letters per month, which is enough for my home use with my head. After registration, we go to the settings and see the smtp server address, port, login and password generated to us.
')
Quickly rolled a sketch, send email 375XXYYYYYYY@sms.mts.by and ... Bummer. I send to ordinary mail - comes. I tried this way and that to alter the title - all the same, the letters disappear in the abysses of the MTS servers, obviously getting into the boiler of the spam filter.

So you need to "wash" the mail. As a service of washing, I chose (silently hated by me for advertising) mail.ru. For cleaning in the mail settings, in the section “Filters and forwarding”, created a new rule:
Settings
After creating the filter, it was necessary to activate it by entering the code that came in the form of an email-SMS to the phone.
This is the moment of triumph - I am sending an email from Arduinin, and in a minute the phone is heard with a joyful warning signal, while scaring the cat passing by.

Further boring technical details.
I took the Arduino Mega 2560 as a board, since there are as many as three additional serial ports (although you can also use regular UNO, only debugging will be more difficult).
ESP8266 is connected: GND -> GND, VCC and CH_PD -> + 3.3V, RX -> TX3, TX -> RX3. The speed of the ESP8266 is tuned to 115200 baud.
To communicate with the smtp server you need to encode your username and password in Base64.
You can use the Linux console:
openssl enc -base64 <<< 'email@gmail.com'
openssl enc -base64 <<< 'password'
Or some online service, such as a link .
Well, actually the sketch code. After switching on, SMS is sent and the code goes into an eternal loop. Additional libraries are not used.
Code
#define SSID "wi-fi_login" //  SSID #define PASS "wi-fi_password" //   Wi-Fi #define SMTPServer "s02.atomsmtp.com" //smtp  #define SMTPPort "2525" // smtp  #define MailLogin "smtp_example@gmail.com" //   smtp #define MailLoginBase64 "dWd1LCBrb25lNG5vCg==" //  smtp  Base64 #define MailPasswordBase64 "aHJlbiB0YW0K" //   smtp  Base64 #define MailRelay "example@mail.ru" //    "" email #define PhoneNumber "375290000000" //   #define Message "Hello from Arduino!" // #define SERIAL_RX_BUFFER_SIZE 256 #define SERIAL_TX_BUFFER_SIZE 256 void setup() { delay(2000); Serial3.begin(115200); Serial3.setTimeout(5000); Serial.begin(115200); //   Serial.println("Init"); Serial3.println("AT+RST"); //   ,    if(WaiteString("Ready", 5000)) { while(Serial3.available()) { Serial3.read();} Serial.println("WiFi - Module is ready"); }else{ Serial.println("Module dosn't respond."); while(1); } delay(100); Serial3.println(" AT+CIPMODE=0"); WaiteString("OK"); while(Serial3.available()) { Serial3.read();} Serial3.println("AT+CIPMUX=1"); WaiteString("OK"); while(Serial3.available()) { Serial3.read();} // try to connect to wifi boolean connected = false; for(int i=0;i<5;i++) { if(connectWiFi()) { connected = true; break; } } if (!connected) { while(1); } } void loop() { String cmd = "AT+CIPSTART=0,\"TCP\",\""; cmd += String(SMTPServer); cmd += "\"," + String(SMTPPort); Serial3.println(cmd); if(WaiteString("Linked", 5000)) { while(Serial3.available()) { Serial3.read();} Serial.println("Link"); } else { Serial.println("Link fail"); while (1); } if (WaiteString("OK", 2000)) { while(Serial3.available()) { Serial3.read();} } else { while (1); } Send("HELO 1.2.3.4", true); Send("AUTH LOGIN", true); Send(MailLoginBase64, true); Send(MailPasswordBase64, true); Send("MAIL FROM:<" + String(MailLogin) + ">", true); Send("RCPT TO:<" + String(MailRelay) + ">", true); Send("DATA", true); Send("Subject:SMS", false); Send("To:\"" + String(PhoneNumber) + "\" <" + String(PhoneNumber) + "@sms.mts.by>", false); Send("From: <" + String(MailLogin) + ">", false); Send("", false); Send(Message, false); Send(".", true); Send("QUIT", true); while(1) {}; } boolean connectWiFi() { Serial3.println("AT+CWMODE=1"); while (!Serial3.available()) { delay(10);} while (Serial3.available()) {Serial3.read();} String cmd="AT+CWJAP=\""; cmd+=SSID; cmd+="\",\""; cmd+=PASS; cmd+="\""; Serial3.println(cmd); if(WaiteString("OK", 8000)){ Serial.println("Connected to WiFi."); return true; }else{ Serial.println("Can not connect to the WiFi."); return false; } } bool Send(String S, bool wait) { Serial3.print("AT+CIPSEND=0,"); Serial3.println(S.length()+2); while (!Serial3.available()) { delay(10);} if(Serial3.find(">")){ }else{ Serial3.println("AT+CIPCLOSE=0"); delay(1000); return false; } Serial3.print(S + "\r\n");//   if (WaitString("OK", 15000)) { if (wait) { WaitString("+IPD", 15000); while(Serial3.available()) { Serial3.read();}} return true;} else { return false;} } void WaiteString(String S) { int L = S.length(); String T = String(" "); while(1) { if (Serial3.available()) { char c = Serial3.read(); T = T + String(c); if (T.length() > L) T = T.substring(1); if (S.charAt(0) == T.charAt(0)) if (S.compareTo(T) == 0) return; } else { delay(1); } } } bool WaiteString(String S, int Time) { int L = S.length(); String T = String(" "); while(Time>0) { if (Serial3.available()) { char c = Serial3.read(); T = T + String(c); if (T.length() > L) T = T.substring(1); if (S.charAt(0) == T.charAt(0)) if (S.compareTo(T) == 0) return true; } else { delay(1); Time--; } } return false; } String WaiteString(int Time) { String T = String(""); while(Time>0) { if (Serial3.available()) { char c = Serial3.read(); T = T + String(c); } else { delay(1); Time--; } } return T; } 

Source: https://habr.com/ru/post/245805/


All Articles