forked from alokshaw/TTGO-T-Call
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arduino_sim800.ino
145 lines (124 loc) · 3.91 KB
/
Arduino_sim800.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <Arduino.h>
#include <Wire.h>
#include <sim800.h>
#include <WiFi.h>
#include <gprs.h>
#define T_CALL
#if defined(T_CALL)
#define UART_TX 27
#define UART_RX 26
#define SIMCARD_RST 5
#define SIMCARD_PWKEY 4
#define SIM800_POWER_ON 23
#else
#define UART_TX 33
#define UART_RX 34
#define SIMCARD_RST 14
#define SIMCARD_PWKEY 15
#define SIM800_POWER_ON 4
#endif
#define UART_BANUD_RATE 9600
#define I2C_SDA 21
#define I2C_SCL 22
#define IP5306_ADDR 0X75
#define IP5306_REG_SYS_CTL0 0x00
HardwareSerial hwSerial(1);
GPRS gprs(hwSerial, SIMCARD_PWKEY, SIMCARD_RST, SIM800_POWER_ON);
bool setPowerBoostKeepOn(int en)
{
Wire.beginTransmission(IP5306_ADDR);
Wire.write(IP5306_REG_SYS_CTL0);
if (en)
Wire.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
else
Wire.write(0x35); // 0x37 is default reg value
return Wire.endTransmission() == 0;
}
void wifi_test()
{
WiFi.mode(WIFI_STA);
WiFi.disconnect();
int n = WiFi.scanNetworks();
if (n == 0) {
Serial.println("no networks found");
return;
}
Serial.println("Found " + String(n) + " networks");
}
void setup()
{
Serial.begin(115200);
#if defined(T_CALL)
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
String info = "IP5306 KeepOn " + String((isOk ? "PASS" : "FAIL"));
Serial.println(info);
#endif
hwSerial.begin(UART_BANUD_RATE, SERIAL_8N1, UART_RX, UART_TX);
Serial.println("Setup Complete!");
wifi_test();
if (gprs.preInit()) {
Serial.println("SIM800 Begin PASS");
} else {
Serial.println("SIM800 Begin FAIL");
}
Serial.println("Test motor ...");
int i = 3;
while (i--) {
hwSerial.print("AT+SPWM=0,1000,1\r\n");
delay(2000);
hwSerial.print("AT+SPWM=0,0,0\r\n");
}
delay(200);
if (0 != gprs.init()) {
Serial.println("Not checked out to SIM card...");
while (1);
}
// Switch audio channels
hwSerial.print("AT+CHFA=1\r\n");
delay(2);
hwSerial.print("AT+CRSL=100\r\n");
delay(2);
hwSerial.print("AT+CLVL=100\r\n");
delay(2);
hwSerial.print("AT+CLIP=1\r\n");
delay(2);
Serial.println("Init success");
}
bool isCallIn = false;
void loop()
{
if (hwSerial.available()) {
const char *s = hwSerial.readStringUntil('\n').c_str();
if (strstr(s, "OK" ) != NULL) {
Serial.println("SIM OK");
} else if (strstr(s, "+CPIN: NOT READY") != NULL) {
Serial.println("SIM +CPIN: NOT READY");
} else if (strstr(s, "+CPIN: READY") != NULL) {
Serial.println("SIM +CPIN: READY");
} else if (strstr(s, "+CLIP:") != NULL) {
Serial.printf("SIM %s\n", s);
} else if (strstr(s, "RING") != NULL) {
delay(200);
hwSerial.write("ATA\r\n");
Serial.println("SIM RING");
} else if (strstr(s, "Call Ready") != NULL) {
Serial.println("SIM Call Ready");
} else if (strstr(s, "SMS Ready") != NULL) {
Serial.println("SIM SMS Ready");
} else if (strstr(s, "NO CARRIER") != NULL) {
Serial.println("SIM NO CARRIER");
} else if (strstr(s, "NO DIALTONE") != NULL) {
Serial.println("SIM NO DIALTONE");
} else if (strstr(s, "BUSY") != NULL) {
Serial.println("SIM BUSY");
} else {
Serial.print(s);
}
Serial.println("==========");
}
if (Serial.available()) {
String r = Serial.readString();
hwSerial.write(r.c_str());
}
}