Add CommandMgr with HTTP GET queue + HttpClient.getJson

This commit is contained in:
2025-09-03 16:47:09 +10:00
parent aac68aa77c
commit 2c09289eaa
5 changed files with 254 additions and 2 deletions

View File

@@ -1,11 +1,26 @@
#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
@@ -14,6 +29,11 @@ void setup() {
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);
@@ -21,6 +41,7 @@ void setup() {
void loop() {
SmsMgr::pollUrc(); // non‑blocking URC scan; handles +CMTI
CommandMgr::poll(30000); // every 30s
SmsMgr::pollUnread(); // optional safety poll
delay(250);
}