TEST MODULE SIM 4G
#include <HardwareSerial.h>
#include <WiFi.h>
#define simSerial Serial0
#define MCU_SIM_BAUDRATE 115200
#define MCU_SIM_TX_PIN 43
#define MCU_SIM_RX_PIN 44
#define MCU_SIM_EN_PIN 41
#define PHONE_NUMBER "" //SĐT của bạn
void sim_at_wait() {
delay(500);
while (simSerial.available()) {
Serial.write(simSerial.read());
}
}
bool sim_at_cmd(String cmd) {
Serial.print("Sending command: ");
Serial.println(cmd);
simSerial.println(cmd);
delay(500); //
sim_at_wait();
return true;
}
bool sim_at_send(char c) {
simSerial.write(c);
return true;
}
void sent_sms() {
sim_at_cmd("AT+CMGF=1");
String temp = "AT+CMGS=\"";
temp += PHONE_NUMBER;
temp += "\"";
sim_at_cmd(temp);
sim_at_cmd("hello from TDLOGY");
sim_at_send(0x1A);
}
void setup() {
pinMode(MCU_SIM_EN_PIN, OUTPUT);
digitalWrite(MCU_SIM_EN_PIN, HIGH);
delay(500);
Serial.begin(115200);
Serial.println("\n\n\n\n-----------------------\nSystem started!!!!");
delay(8000);
simSerial.begin(MCU_SIM_BAUDRATE, SERIAL_8N1, MCU_SIM_RX_PIN, MCU_SIM_TX_PIN);
Serial.println("Checking AT command...");
sim_at_cmd("AT");
Serial.println("Getting product info...");
sim_at_cmd("ATI");
Serial.println("Checking SIM status...");
sim_at_cmd("AT+CPIN?");
Serial.println("Checking signal quality...");
sim_at_cmd("AT+CSQ");
Serial.println("Getting IMSI...");
sim_at_cmd("AT+CIMI");
sent_sms();
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
simSerial.write(c);
}
}
Đây là màn hình monitor sau khi code được nạp
CSQ là chất lượng sóng.
No Comments