ตอนนี้ผมใช้บอร์ด Arduino UNO R3 กับโมดูล 3G Shield (UC20-G) รบกวนพี่ๆเพื่อนๆแนะนำทีครับ ผมต้องใช้ Library อันไหน เพราะ Blybrary ของ Blynk ไม่มีสำหรับตัวโมดูลนี้อะครับ
ลองศึกษาจากโค้ตตัวอย่างดูครับ
#define BLYNK_PRINT Serial
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "YourAPN";
char user[] = "";
char pass[] = "";
// Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1
// or Software Serial on Uno, Nano
//#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX
TinyGsm modem(SerialAT);
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set GSM module baud rate
SerialAT.begin(115200);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
modem.restart();
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, user, pass);
}
void loop()
{
Blynk.run();
}
ขอบคุณครับ
ช่วยดูหน่อยครับ เจอปัญหา
ลองทำโปรเจค
esp8266+Neo-06 GPS+SIM800L v2
—หลังส่ง sms เข้าไปหรือโทรเข้าไป (ได้) serial monitor แสดง reset ดังนี้
wdt reset
load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8
tail 0
chksum 0x2b
csum 0x2b
v00044e70
~ld…
+++++++++++code program++++++++++++++++
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
const String PHONE_NUMBER = “+669xxxxxxxx”;
// Define RX/TX pins for GSM Module
#define GSM_RX_PIN D5
#define GSM_TX_PIN D6
SoftwareSerial sim800(GSM_RX_PIN, GSM_TX_PIN);
// Define RX/TX pins for GPS Module
#define GPS_RX_PIN D7
#define GPS_TX_PIN D8
SoftwareSerial neogps(GPS_RX_PIN, GPS_TX_PIN);
TinyGPSPlus gps;
String receivedCommand = “”;
void setup() {
Serial.println(“Start of setup”);
Serial.begin(115200);
Serial.println(“Arduino serial initialize”);
sim800.begin(9600);
Serial.println(“SIM800L serial initialize”);
neogps.begin(9600);
Serial.println(“GPS serial initialize”);
sim800.listen();
neogps.listen();
sim800.println(“AT+CMGF=1\r”); // Set SMS mode to text
delay(1000);
Serial.println(“Setup complete.”);
Serial.println(“End of setup”);
}
void loop() {
//ESP.wdtFeed(); // ESP8266.wdtFeed()
while (sim800.available()) {
parseSMS(sim800.readString());
}
if (receivedCommand == “get”) {
checkGPSCommand();
// …
receivedCommand = “”;
//delay(1000); // …
}
}
void parseSMS(String sms) {
Serial.println(“Received SMS: " + sms); // Display the received SMS in Serial Monitor
sms.trim();
if (sms.startsWith(”+CMTI")) {
int index = sms.indexOf(“,”);
String temp = sms.substring(index + 1);
temp.trim();
temp = “AT+CMGR=” + temp + “\r”;
sim800.println(temp);
sim800.flush();
} else if (sms.startsWith(“+CMGR”)) {
extractSMS(sms);
}
}
void extractSMS(String sms) {
int index = sms.indexOf(“,”);
String senderNumber = sms.substring(index + 2, index + 15);
senderNumber.trim();
index = sms.indexOf(“\n”);
String message = sms.substring(index + 1);
message.trim();
Serial.println("Sender Number: " + senderNumber);
Serial.println("Message: " + message);
if (senderNumber == PHONE_NUMBER) {
processCommand(message);
}
}
void processCommand(String command) {
// …
command.trim();
if (command.equalsIgnoreCase(“get”)) {
receivedCommand = command;
Serial.println("Received command: " + receivedCommand);
}
}
void checkGPSCommand() {
Serial.println(“Checking GPS Command”);
// …
if (receivedCommand == “get”) {
// …
receivedCommand = “”;
// ...
while (neogps.available()) {
if (gps.encode(neogps.read())) {
if (gps.location.isValid()) {
Serial.println("Sending Location SMS");
sendLocationSMS();
} else {
Serial.println("Invalid GPS Location");
}
} else {
Serial.println("GPS Data Not Received");
}
}
}
}
void sendLocationSMS() {
Serial.print(“Sending Location SMS…”);
if (gps.location.isValid()) {
sim800.print(“AT+CMGS=”" + PHONE_NUMBER + “”\r");
delay(1000);
sim800.print(“Google Maps”);
sim800.print(gps.location.lat(), 6);
sim800.print(“,”);
sim800.print(gps.location.lng(), 6);
sim800.write(0x1A); // …
sim800.flush();
unsigned long startMillis = millis();
while (millis() - startMillis < 10000) { // …
if (sim800.available()) {
String response = sim800.readString();
Serial.println("Response from GSM module: " + response);
break;
}
}
Serial.println(“GPS Location SMS Sent Successfully.”);
} else {
Serial.println(“Invalid GPS data”);
}
}
…