Codice: invio delle coordinate con parsing

Abbiamo unito lo sketch del parsing con quello delle coordinate, il problema principale che abbiamo riscontrato è stato individuare le parti importanti dei due codici e unirle in modo corretto.

Il codice:

#define TINY_GSM_MODEM_SIM808

int pon=9;

#define SerialMon SerialUSB

#define SerialAT Serial1

#define TINY_GSM_DEBUG SerialMon

#define SMS_TARGET “+393391356849”

const char apn[] = “YourAPN”;
const char user[] = “”;
const char pass[] = “”;

#include <TinyGsmClient.h>

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif

void setup() {

SerialMon.begin(9600);

delay(3000);
DBG(“BeeSafe ON…”);

pinMode(pon, OUTPUT);
digitalWrite(pon, HIGH);
delay(3000);
digitalWrite(pon, LOW);
<<<<
delay(3000);

TinyGsmAutoBaud(SerialAT);
}

void loop() {

DBG(“Initializing modem…”);
if (!modem.restart()) {
delay(10000);
return;
}
bool res;
String modemInfo = modem.getModemInfo();
DBG(“Modem:”, modemInfo);

//pin 1234

String imei = modem.getIMEI();
DBG(“IMEI:”, imei);

String cop = modem.getOperator();
DBG(“Operator:”, cop);

IPAddress local = modem.localIP();
DBG(“Local IP:”, local);

int csq = modem.getSignalQuality();
DBG(“Signal quality:”, csq);

int battLevel = modem.getBattPercent();
DBG(“Battery lavel:”, battLevel);

float battVoltage = modem.getBattVoltage() / 1000.0F;
DBG(“Battery voltage:”, battVoltage);

String gsmLoc = modem.getGsmLocation();
DBG(“GSM location:”, gsmLoc);

String gsmTime = modem.getGSMDateTime(DATE_TIME);
DBG(“GSM Time:”, gsmTime);
String gsmDate = modem.getGSMDateTime(DATE_DATE);
DBG(“GSM Date:”, gsmDate);

String ussd_balance = modem.sendUSSD(“*111#”);
DBG(“Balance (USSD):”, ussd_balance);

String ussd_phone_num = modem.sendUSSD(“*161#”);
DBG(“Phone number (USSD):”, ussd_phone_num);

#if defined(TINY_GSM_MODEM_SIM808)
modem.enableGPS();
String gps_raw = modem.getGPSraw();
modem.disableGPS();
DBG(“GPS raw data:”, gps_raw);
#endif

#if defined(SMS_TARGET)
res = modem.sendSMS(SMS_TARGET, String(“Hello from BeeSafe -> IMEI: “) + imei);
DBG(“SMS:”, res ? “OK” : “fail”);

#endif

while (1){
#if defined(TINY_GSM_MODEM_SIM808)
modem.enableGPS();
String gps_raw = modem.getGPSraw();

DBG(“GPS raw data:”, gps_raw);

String input = ;
int counter = 0;
String pieces[30];
int ultimavirgola = 0;
int a=0;
for (a = 0; a < input.length(); a++) {

if (input.substring(a, a+1) == “,”) {

pieces[counter] = input.substring(ultimavirgola, a);

ultimavirgola = a + 1;

counter++;

}

if (a == input.length()-1) {
pieces[counter] = input.substring(ultimavirgola, a);

}

}

#endif
#if defined(SMS_TARGET)
res = modem.sendSMS(SMS_TARGET, String(“GPS raw data: “) + gps_raw);
DBG(“SMS:”, res ? “OK” : “fail”);

#endif
int i=600;
while (i>0){
delay (1000);
i–;
DBG(“Invio sms tra “,i);
DBG(” secondi”);
}
}
#if defined(CALL_TARGET)
DBG(“Calling:”, CALL_TARGET);

// This is NOT supported on M590
res = modem.callNumber(CALL_TARGET);
DBG(“Call:”, res ? “OK” : “fail”);

if (res) {
delay(1000L);

// Play DTMF A, duration 1000ms
modem.dtmfSend(‘A’, 1000);

for (char tone=’0′; tone<=’4′; tone++) {
modem.dtmfSend(tone);
}

delay(5000);

res = modem.callHangup();
DBG(“Hang up:”, res ? “OK” : “fail”);
}
#endif

modem.gprsDisconnect();
if (!modem.isGprsConnected()) {
DBG(“GPRS disconnected”);
} else {
DBG(“GPRS disconnect: Failed.”);
}

modem.poweroff();
DBG(“Poweroff.”);

while (true) {
modem.maintain();
}
}

Lascia un commento