CAR_GPS_TRACKER/backup/CAR_GPS_TRACKER (Copy).ino

47 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "src/core/NetMgr.hpp"
#include "src/core/HttpClient.hpp"
#include "src/core/SmsMgr.hpp"
#include "src/core/CommandMgr.hpp"
static String DEVICE_IMEI = "";
static const char* APN = "hologram";
static const char* BASE_URL = "http://laravel-server.lab.audasmedia.com.au";
static const char* PATH = "/api/gps";
static String queryImei() {
String r = NetMgr::sendAT("AT+CGSN", 3000);
// Response often includes the IMEI line + OK; take the first 15-digit line
int s = 0;
for (int i=0;i<(int)r.length();++i) {
if (isDigit(r[i])) { s = i; break; }
}
String imei = r.substring(s, s+15);
imei.trim();
return imei;
}
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, 16, 17); // RX=16, TX=17
NetMgr::powerOnSIM7080(4); // PWRKEY pin 4
NetMgr::attachAndPdp(APN); // LTE reg + CNACT + DNS
SmsMgr::setup(); // enable text mode + URCs
DEVICE_IMEI = queryImei();
if (DEVICE_IMEI.length()==0) DEVICE_IMEI = "860016049744324"; // fallback if needed
CommandMgr::configure(BASE_URL, DEVICE_IMEI);
String json = "{\"device_id\":\"sim7080g-01\",\"lat\":-33.865143,"
"\"lng\":151.2099,\"speed\":12.5,\"altitude\":30.2}";
HttpClient::postJson(BASE_URL, PATH, json);
}
void loop() {
SmsMgr::pollUrc(); // nonblocking URC scan; handles +CMTI
CommandMgr::poll(30000); // every 30s
SmsMgr::pollUnread(); // optional safety poll
delay(250);
}