How can I do sections of this smarter? Things like
Serial.println("sending at+cgpsrst=1");
Serial1.write('a');
Serial1.write('t');
Serial1.write('+');
Serial1.write('c');
Serial1.write('g');
Serial1.write('p');
Serial1.write('s');
Serial1.write('r');
Serial1.write('s');
Serial1.write('t');
Serial1.write('=');
Serial1.write('1');
Serial1.write(13);
Serial1.write(10);
I use Serial to talk between PC and the 1284P, and Serial1 between the 1284P and the DFRobot module.
I couldn't figure it out last night, so I ended up with the attached working code for this DFRobot SIM908 GSM/GPS card:
Their code samples sucked.
Code attached. (actual phone # removed)
Results:
Starting GPS/GSM 'warmup' delay 123456789101112
GPS ready for AT?
received: +CFUN:1+CPIN:READY+PACSP:1CallReadyGPSReÿ.........
yes - sending AT
received: atOK
sending at+cgpspwr=1
received: at+cgpspwr=1OK
sending at+cgpsrst=1
received: at+cgpsrst=1OK
Setup complete
sending at+cgpsstatus?
received: at+cgpsstatus?+CGPSSTATUS:Location3DFixOK....
sending at+cgpsinf=4
received:
at+cgpsinf=44,4222.032117,N,7131.696846,W,063328.000
Sending Text:
sending at+cmgf=1
received: at+cmgf=1OK
sending at+cmgs=phone_number with number in quotes
received: at+cmgs="508xxxxxxx">
sending truck # and location, time message
received: TRUCK:0001,42.22.032117,N,71.31.696846,W,TIME:06:33GMT
+CMGS: 70
OK
There's a lot of debug statements in there, almost all of the above, but the end result that shows up on your phone is:
TRUCK:0001,42.22.032117,N,71.31.696846,W,TIME:06:33GMT
which I think I parsed out nicely for human readability.
One thing I haven't figured out is catching all the incoming data here:
received: +CFUN:1+CPIN:READY+PACSP:1CallReadyGPSReÿ.........
(I strip out spaces, CR, and LF from what I store to make it easier to grab the data pieces I want)
where I think I'm losing part of GPS READY coming in during the warmup delay. Gotta catch it in a couple pieces or something so the 64 byte buffer doesn't over flow (which is what I think is occurring).
A couple things like the TRUCK # and the Phone Number I want to be in arrays at the top of the sketch so they can be easily tweaked vehicle by vehicle and by phone number if needed.
Occasionally the card reports "NORMAL POWER DOWN" and sometimes ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ for all characters, I've managed to recognize that and added this
Serial.println("resetting...");
asm volatile ("jmp 0");
to autoreset the processor, and recover automatically, that was a sweet discovery last night.
GPS_GSM_only.ino (10.3 KB)