Skip to content

Commit d6fe098

Browse files
committed
Arduino firmware for SMS OTP.
1 parent e42b4ca commit d6fe098

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed

sms-otp-firmware/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
],
7+
"unwantedRecommendations": [
8+
"ms-vscode.cpptools-extension-pack"
9+
]
10+
}

sms-otp-firmware/include/firmware.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef FIRMWARE_H
2+
#define FIRMWARE_H
3+
4+
#include <SoftwareSerial.h>
5+
#include <SIM900.h>
6+
7+
static SoftwareSerial shieldSerial(7, 8);
8+
static SIM900 sim900(&shieldSerial);
9+
10+
void sendOTP(String number, String email, String otp);
11+
12+
#endif

sms-otp-firmware/platformio.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:uno]
12+
platform = atmelavr
13+
board = uno
14+
framework = arduino
15+
lib_deps = nthnn/SIM900@^1.0.0

sms-otp-firmware/src/firmware.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <firmware.h>
2+
3+
void sendOTP(String number, String email, String otp) {
4+
Serial.println(sim900.sendSMS(number, "Your one-time password (OTP) is " + otp +
5+
". Do not share your OTP to anyone. If you did not request for your OTP, report at " +
6+
email + ".\n\n(Sent via QLBase)") ? F("SENT") : F("ERR")
7+
);
8+
}

sms-otp-firmware/src/main.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <Arduino.h>
2+
#include <firmware.h>
3+
4+
void setup() {
5+
Serial.begin(9600);
6+
}
7+
8+
void loop() {
9+
if(Serial.available() > 0) {
10+
String serialString = Serial.readString();
11+
serialString.trim();
12+
13+
int delim1 = serialString.indexOf(F(",")),
14+
delim2 = serialString.lastIndexOf(F(","));
15+
16+
sendOTP(
17+
serialString.substring(0, delim1),
18+
serialString.substring(delim1 + 1, delim2),
19+
serialString.substring(delim2 + 1)
20+
);
21+
}
22+
}

0 commit comments

Comments
 (0)