I have a "bareboard" ATMega328PB with the following devices:
SIM800L GSM Modem
Quectel L80 GPS Module
LS2DH12 Accelerometer
I am using the following libraries:
Main Sketch:
#include <Adafruit_SleepyDog.h>
#include <Vcc.h>
#include "SIM800L.h"
#include <Wire.h>
#include "SparkFun_LIS2DH12.h"
SPARKFUN_LIS2DH12 accel;
Accelerometer Sketch:
#include <Adafruit_SleepyDog.h>
#include <Wire.h>
#include "SparkFun_LIS2DH12.h"
I have written 2 sketches (to ensure everything works) that I must now combine into one sketch.
Both sketches work as intended when run by themselves.
However, as soon as I add "#include <Wire.h>" to the main sketch, I have a problem with getting the data.
The Main sketch:
#include <Adafruit_SleepyDog.h>
#include <Vcc.h>
#include "SIM800L.h"
//#include <Wire.h>
//#include "SparkFun_LIS2DH12.h"
//SPARKFUN_LIS2DH12 accel;
Vcc vcc;
float v;
// Acc Stuff
int countAcc;
int accCounter = 0;
int accCount = 20;// Change this for final
int accInterval = 30000;// Change this for final
bool currAcc = false;
bool txRunning = false;
bool txParked = false;
bool txStart = false;
bool txStop = false;
String statusAcc = "";
//*******************
#define MAXIMUM_GPS_DURATION_SEC 1200//
#define MAXIMUM_REG_DURATION_SEC 240
char gpsValid[2];
float myLatGeo;
float myLonGeo;
char latNS[2];
char lonEW[2];
char latHex[9];
char lonHex[10];
int myKMPH;
int mySignal;
String txSignal;
char txSpeed[4];
String msgTX;
char txVolts[3];
int myVolts;
const char URL[] = "http://majorxxxxxxx.dedicated.com:5000";
const char CONTENT_TYPE[] = "application/text";
const char APN[] = "flick";
volatile int watchdog_counter;
int wakeCount;
String msgID;
String myDeviceID = "IS005";
#define SIM800_RST_PIN 11
SIM800L* sim800l;
int BUZZER = 2;
int GPS_PWR = 5;
boolean AT_cmd_result = false;
#define DEBUG true
//String response = "";
boolean status;
bool ModuleState = false;
void setup()
{
Serial.begin(9600);
Serial.println("BOOT");
// Initialize the hardware Serial1
Serial1.begin(38400);
delay(1000);
Serial.print(F("CutOut-L80-800L-HTTP"));
Serial.println(myDeviceID);
// Wire.begin();
pinMode(GPS_PWR, OUTPUT);// GPS Pin
digitalWrite(GPS_PWR, HIGH);// GPS OFF
// pinMode(SIM800_RST_PIN, OUTPUT);// 800L Reset Pin
// digitalWrite(SIM800_RST_PIN, HIGH);// 800L On
pinMode(BUZZER, OUTPUT);
// BUZZER - BOOT
digitalWrite(BUZZER, HIGH);
delay(100);
digitalWrite(BUZZER, LOW);
intSIM800L();
getPowerMode();
setPowerNormal();
delay(1000);
getRegistered();
// BUZZER - READY
digitalWrite(BUZZER, HIGH);
delay(100);
digitalWrite(BUZZER, LOW);
delay(100);
digitalWrite(BUZZER, HIGH);
delay(100);
digitalWrite(BUZZER, LOW);
sleep800L();
getGPSrmc();
msgID = "90";
sendHTTP();
/*
wakeCount 5 == ~1 minute
wakeCount 10 == ~2 minute
wakeCount 25 == ~5 minute
wakeCount 50 == ~10 minute
wakeCount 75 == ~13 minute
wakeCount 86 == ~15 minute
wakeCount 172 == ~30 minute
*/
wakeCount = 50;
}
void intSIM800L() {
// Line with the debug enabled on the Serial
sim800l = new SIM800L((Stream *)&Serial1, SIM800_RST_PIN, 200, 512, (Stream *)&Serial);
Serial.println(F("Start of test protocol"));
// Wait until the module is ready to accept AT commands
while (!sim800l->isReady()) {
Serial.println(F("Problem to initialize AT command, retry in 1 sec"));
delay(1000);
}
// Active echo mode (for some module, it is required)
// sim800l->enableEchoMode();
Serial.println(F("Module ready"));
}
void getPowerMode() {
// Check Power Mode
Serial.print(F("Power Mode "));
Serial.println(sim800l->getPowerMode());
delay(500);
/* POWER MODES
"AT+CFUN?" // Check the current power mode
"AT+CFUN=0" // Switch minimum power mode
"AT+CFUN=1" // Switch normal power mode
"AT+CFUN=4" // Switch sleep power mode
*/
}
void setPowerNormal() {
// Set Power Mode NORMAL
Serial.println(sim800l->setPowerMode(NORMAL));
}
void getSignal()
{
unsigned long startCSQ = millis();
while (millis() - startCSQ < 2000)
{
char incomingByte;
String strSignal;
Serial1.println("AT+CSQ");
if (Serial1.available()) {
delay(100);
while (Serial1.available()) {
incomingByte = Serial1.read();
strSignal += incomingByte;
}
delay(10);
}
int pos0 = strSignal.indexOf(':');
int pos1 = strSignal.indexOf(',');
String SignalStrength;
SignalStrength = strSignal.substring(pos0 + 1, pos1);
SignalStrength.trim();
Serial.print("SignalStrength: ");
Serial.println(SignalStrength);
if (SignalStrength != "") {
Serial.print(F("Signal Len: "));
Serial.println(SignalStrength.length());
if (SignalStrength.length() <= 1) {
SignalStrength = "0" + SignalStrength;
}
if (SignalStrength.length() == 2) {
mySignal = (atoi(SignalStrength.c_str()));
txSignal = mySignal;
}
}
if (SignalStrength == "") {
txSignal = "15";
}
Serial.print(F("txSignal: "));
Serial.println(txSignal);
}
}
void getRegistered() {
NetworkRegistration network = sim800l->getRegistrationStatus();
while (network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
delay(1000);
network = sim800l->getRegistrationStatus();
}
if (network == 5) {
Serial.print(F("Network: "));
Serial.println(network);
}
/*
case '0' : return NOT_REGISTERED;
case '1' : return REGISTERED_HOME;
case '2' : return SEARCHING;
case '3' : return DENIED;
case '5' : return REGISTERED_ROAMING;
default : return NET_UNKNOWN;
*/
}
void loop() {
Watchdog.sleep();// sleepNOW(); //Go to sleep!
watchdog_counter++;
Serial.print(F("Wake Count Set: "));
Serial.println(wakeCount);
delay(50);
Serial.print(F("Sleep Count: "));
Serial.println(watchdog_counter);
delay(50);
if (watchdog_counter >= wakeCount)
{
Serial.println(F("800L Awake"));
delay(50);
// intSIM800L();
// getPowerMode();
// setPowerNormal();
awake800L();
getGPSrmc();
msgID = "91";
sendHTTP();
watchdog_counter = 0;
}
}
void sleep800L() {
// Set Power Mode SLEEP
Serial.println(sim800l->setPowerMode(SLEEP));
Serial1.println(F("AT+CSCLK=2"));
Serial.println(F("800L Going to SLEEP "));
delay(100);
}
void awake800L() {
Serial.println(sim800l->setPowerMode(NORMAL));
Serial1.println(F("AT"));
delay(500);
Serial1.println(F("AT"));
delay(500);
Serial1.println(F("AT+CSCLK=0"));
Serial.println(F("Going to AWAKE "));
sendATcmd("AT+CFUN=1", 10, "OK");
}
void sendHTTP() {
myVolts = Vcc::measure(1000, 1100);
myVolts = (myVolts / 100);
msgTX = ""; // Clear Tx Message
awake800L();
delay(1000);
getSignal();
delay(1000);
Serial1.println(F("AT"));
delay(500);
Serial.println(F("--------------------GET Message----------------------"));
if (txSignal == "0"){
txSignal = "15";
}
msgTX += String(latHex);
msgTX += "#";
msgTX += String(latNS);
msgTX += "#";
msgTX += lonHex;
msgTX += "#";
msgTX += String(lonEW);
msgTX += "#";
msgTX += String(myVolts);
msgTX += "#";
msgTX += msgID;
msgTX += "#";
msgTX += myDeviceID;
msgTX += "#";
// msgTX += String(mySignal);
msgTX += txSignal;
msgTX += "#";
msgTX += String(txSpeed);
Serial.println(msgTX);
int lenTX = msgTX.length();
Serial.print(F("msgTX.length: "));
Serial.println(lenTX);
char tx[msgTX.length() + 1]; // Create a char array big enough including the terminating NULL
strcpy(tx, msgTX.c_str()); // Place incoming route in char array
char *PAYLOAD = tx;
// Setup APN for GPRS configuration
bool success = sim800l->setupGPRS(APN);
while (!success) {
success = sim800l->setupGPRS(APN);
delay(5000);
}
Serial.println(F("GPRS config OK"));
// Establish GPRS connectivity (5 trials)
bool connected = false;
for (uint8_t i = 0; i < 5 && !connected; i++) {
delay(1000);
connected = sim800l->connectGPRS();
}
Serial.println(F("Start HTTP POST..."));
// Do HTTP POST communication with 10s for the timeout (read and write)
uint16_t rc = sim800l->doPost(URL, CONTENT_TYPE, PAYLOAD, 10000, 10000);
if (rc == 200) {
// Success, output the data received on the serial
Serial.print(F("HTTP POST successful ("));
Serial.print(sim800l->getDataSizeReceived());
Serial.println(F(" bytes)"));
Serial.print(F("Received : "));
Serial.println(sim800l->getDataReceived());
} else {
// Failed...
Serial.print(F("HTTP POST error "));
Serial.println(rc);
}
// Serial1.println("AT+HTTPTERM");
sendATcmd("AT+HTTPTERM", 10, "OK");
// Close GPRS connectivity (5 trials)
bool disconnected = sim800l->disconnectGPRS();
for (uint8_t i = 0; i < 5 && !connected; i++) {
delay(1000);
disconnected = sim800l->disconnectGPRS();
}
if (disconnected) {
Serial.println(F("GPRS disconnected !"));
} else {
Serial.println(F("GPRS still connected !"));
}
delay(5000);
sleep800L();
}
String sendData(String &command, const int timeout, boolean debug)
{
String response = "";
Serial1.println(command);
delay(20);
long int time = millis();
while ((time + timeout) > millis())
{
while (Serial1.available())
{
char c = Serial1.read();
response += c;
}
}
if (DEBUG)
{
Serial.print(response);
delay(100);
}
return response;
}
bool sendATcmd(String AT_cmd, int AT_cmd_maxTime, char readReply[])
{
int trycnt = 0;
bool status = false;
Serial.print(F("AT command:"));
Serial.println(AT_cmd);
delay(50);
while (trycnt < AT_cmd_maxTime) {
Serial1.println(AT_cmd);
if (Serial1.find(readReply)) {
AT_cmd_result = true;
break;
}
++trycnt;
}
Serial.print(F("Result:"));
if (true == AT_cmd_result) {
Serial.print(AT_cmd);
Serial.println(F(" DONE"));
status = true;
} else {
Serial.println(F("FAILED"));
}
AT_cmd_result = false;
return status;
}
bool moduleStateCheck()
{
int i = 0;
bool moduleState = false;
for (i = 0; i < 5; i++)
{
String msg = String("");
Serial1.println("AT");
if (msg.indexOf("OK") >= 0)
{
Serial.println("A9G was ON.");
moduleState = true;
return moduleState;
}
delay(1000);
}
return moduleState;
}
void getGPSrmc() {
// Wake Up GPS
digitalWrite (GPS_PWR, LOW); // turn POWER_GPS ON
delay(1000);
Serial.println("Got to getGPS");
// RMC Only
Serial.println("$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29");
delay(2000);
char gpsResponse[82] = {0}; // 80 chars + null terminator
const unsigned char MAX_gpsCOUNT = 1;
unsigned char gpsCount = 0;
bool gpsSuccess = false;
do {
for (int s = 0; s < MAXIMUM_GPS_DURATION_SEC; s++) {
do {
while (Serial.available()) gpsResponse[0] = Serial.read();
}
while (gpsResponse[0] != '$'); // Wait for response message
for (unsigned char c = 0; c < sizeof(gpsResponse) - 1; c++) {
while (!Serial.available());
gpsResponse[c] = Serial.read(); // Capture response character
if (gpsResponse[c] == '\r') gpsResponse[c] = 0x00; // Ignore CR
if (gpsResponse[c] == '\n') break; // LF means the end of one line of response
}
Serial.println(gpsResponse);
delay(50);
//GNRMC,070932.860,A,2551.3716,S,02810.7482,E,0.84,290.21,081122,,,A*7C
const char* foundGPS = "GPRMC";
char* p;
p = strstr (gpsResponse, foundGPS);
if (p) {
// Check that GPS has a Valid message (A==Valid / V==Not Valid)
strncpy(gpsValid, gpsResponse + 17, 1);
gpsValid[1] = '\0';
if (gpsValid[0] == 65) {// A==Dec 65
// Get Latitude
char gpsLat[10];
strncpy(gpsLat, gpsResponse + 19, 4);
strncpy(&gpsLat[4], gpsResponse + 24, 4);
gpsLat[8] = '\0';
float myLatGeo0 = atof(gpsLat);
float myLatGeo1 = myLatGeo0 / 1000000;
float latNmea = myLatGeo1 * 100;
uint16_t wholeDegrees = 0.01 * latNmea;
myLatGeo = wholeDegrees + (latNmea - 100.0 * wholeDegrees) / 60.0;
Serial.print("Lat DD.dddd: ");
Serial.println(myLatGeo, 6);
delay(50);
Serial.print("Lat DEC: ");
Serial.println(gpsLat);
delay(50);
sprintf(latHex, "%08lX", atol(gpsLat));
Serial.print("Lat HEX: ");
Serial.println(latHex);
delay(50);
// Get NS
strncpy(latNS, gpsResponse + 29, 1);
latNS[1] = '\0';
Serial.print("NS: ");
Serial.println(latNS);
// Get Longitude
char gpsLon[10];
strncpy(gpsLon, gpsResponse + 31, 5);
strncpy(&gpsLon[5], gpsResponse + 37, 4);
gpsLon[9] = '\0';
float myLonGeo0 = atof(gpsLon);
float myLonGeo1 = myLonGeo0 / 1000000;
float lonNmea = myLonGeo1 * 100;
uint16_t wholeDegreesLon = 0.01 * lonNmea;
myLonGeo = wholeDegreesLon + (lonNmea - 100.0 * wholeDegreesLon) / 60.0;
Serial.print("Lon DD.dddd: ");
Serial.println(myLonGeo, 6);
delay(50);
Serial.print("Lon DEC: ");
Serial.println(gpsLon);
delay(50);
sprintf(lonHex, "%08lX", atol(gpsLon));
Serial.print("Lon HEX: ");
Serial.println(lonHex);
delay(50);
// Get EW
strncpy(lonEW, gpsResponse + 42, 1);
lonEW[1] = '\0';
Serial.print("EW: ");
Serial.println(lonEW);
delay(50);
int i = 0;
char *start_pch, *end_pch;
char extracted_str[16];
start_pch = gpsResponse - 1;
end_pch = strstr (gpsResponse, ",");
while ( end_pch != NULL ) {
memset (extracted_str, 0, 16);
strncpy (extracted_str, start_pch + 1, end_pch - start_pch - 1); //<----
Serial.print(++i);
Serial.print(": ");
Serial.println(extracted_str);
start_pch = end_pch;
end_pch = strstr (end_pch + 1, ",");
if (i == 8) {
myKMPH = atoi(extracted_str);
myKMPH = myKMPH * 1.852;
sprintf(txSpeed, "%03d", myKMPH);
Serial.print("txSpeed: ");
Serial.println(txSpeed);
//to print out the last value
memset (extracted_str, 0, 16);
strncpy (extracted_str, start_pch + 8, strlen(start_pch));
// Serial.print(++i);
// Serial.print(": ");
// Serial.println(extracted_str);
}
}
gpsSuccess = true;
break; // Not continue if found A (65)
}// END if (gpsValid[0] == 65)
} else {
gpsSuccess = false;
}
}// END for (int s = 0; s < MAXIMUM_GPS_DURATION_SEC; s++)
Serial.print("gpsCount: ");
Serial.println(gpsCount);
delay(50);
} while (++gpsCount < MAX_gpsCOUNT && gpsSuccess);
Serial.println("GPS Timeout");
// Switch GPS OFF
Serial.println("GPS OFF");
delay(50);
digitalWrite (GPS_PWR, HIGH); // turn POWER_GPS OFF
}
void readBattery()
{
myVolts = Vcc::measure(1000, 1100);
sprintf(txVolts, "%02d", myVolts);
}
Output of Main sketch with "#include <Wire.h>" commented out:
BOOT
CutOut-L80-800L-HTTPIS005
SIM800L : Reset
SIM800L : Prepare internal buffer of 200 bytes
SIM800L : Prepare reception buffer of 512 bytes
Start of test protocol
SIM800L : Send "AT"
SIM800L : End of transmission
SIM800L : Receive "AT
OK
"
Module ready
Power Mode SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 4
"
3
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 4
"
SIM800L : Send "AT+CFUN=1"
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 1
"
1
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,2
"
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,2
"
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,2
"
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,2
"
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,1
"
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 1
"
SIM800L : Send "AT+CFUN=4"
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "
OK
"
0
800L Going to SLEEP
Got to getGPS
$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29
GPRMC,052126.426,V,,,,,0.00,0.00,260623,,,N*4C
GPRMC,052127.426,V,,,,,0.00,0.00,260623,,,N*4D
GPRMC,052143.000,A,2550.4029,S,02811.3935,E,1.48,45.11,260623,,,A*46
Lat DD.dddd: 25.840047
Lat DEC: 25504029
Lat HEX: 0185291D
NS: S
Lon DD.dddd: 28.189891
Lon DEC: 028113935
Lon HEX: 01ACFC0F
EW: E
1: GPRMC
2: 052143.000
3: A
4: 2550.4029
5: S
6: 02811.3935
7: E
8: 1.48
txSpeed: 001
9: 45.11
10: 260623
11:
12:
gpsCount: 0
GPS Timeout
GPS OFF
SIM800L : Send "AT+CFUN?"
SIM800L : Receive timeout
0
Going to AWAKE
AT command:AT+CFUN=1
Result:AT+CFUN=1 DONE
SignalStrength: 0
Signal Len: 1
txSignal: 0
SignalStrength: 31
txSignal: 31
--------------------GET Message----------------------
0185291D#S#01ACFC0F#E#40#90#IS005#31#001
msgTX.length: 40
SIM800L : Send "AT+SAPBR=3,1,"Contype","GPRS""
SIM800L : End of transmission
SIM800L : Receive "AT+SAPBR=3,1,"Contype","GPRS"
OK
"
SIM800L : Send "AT+SAPBR=3,1,"APN","flick""
SIM800L : End of transmission
SIM800L : Receive "AT+SAPBR=3,1,"APN","flick"
OK
"
GPRS config OK
SIM800L : Send "AT+SAPBR=1,1"
SIM800L : End of transmission
SIM800L : Receive "AT+SAPBR=1,1
ERROR
"
SIM800L : Send "AT+SAPBR=1,1"
SIM800L : End of transmission
SIM800L : Receive "AT+SAPBR=1,1
ERROR
"
SIM800L : Send "AT+SAPBR=1,1"
SIM800L : End of transmission
SIM800L : Receive "AT+SAPBR=1,1
ERROR
"
SIM800L : Send "AT+SAPBR=1,1"
SIM800L : End of transmission
SIM800L : Receive "AT+SAPBR=1,1
OK
"
Start HTTP POST...
SIM800L : Send "AT+HTTPINIT"
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPINIT
OK
"
SIM800L : Send "AT+HTTPPARA="CID",1"
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPPARA="CID",1
OK
"
SIM800L : Send "AT+HTTPPARA="URL","http://majorxxxxxxx.dedicated.com:5000"
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPPARA="URL","http://majorxxxxxxx.dedicated.com:5000"
OK
"
SIM800L : Send "AT+HTTPPARA="REDIR",1"
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPPARA="REDIR",1
OK
"
SIM800L : Send "ATI"
SIM800L : End of transmission
SIM800L : Receive "ATI
SIM800 R14.18
"
SIM800L : initiateHTTP() - Support of SSL enabled
SIM800L : Send "AT+HTTPSSL=0"
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPSSL=0
OK
"
SIM800L : Send "AT+HTTPPARA="CONTENT","application/text""
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPPARA="CONTENT","application/text"
OK
"
SIM800L : Send "AT+HTTPDATA=40,10000"
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPDATA=40,10000
DOWNLOAD
"
SIM800L : doPost() - Payload to send : 0185291D#S#01ACFC0F#E#40#90#IS005#31#001
SIM800L : Send "AT+HTTPACTION=1"
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPACTION=1
OK
"
SIM800L : End of transmission
SIM800L : Receive "
+HTTPACTION: 1,200,0
"
SIM800L : readHTTP() - HTTP status 200
SIM800L : readHTTP() - Data size received of 0 bytes
SIM800L : Send "AT+HTTPREAD"
SIM800L : End of transmission
SIM800L : Receive "AT+HTTPREAD
OK
"
HTTP POST error 705
AT command:AT+HTTPTERM
Result:AT+HTTPTERM DONE
SIM800L : Send "AT+SAPBR=0,1"
SIM800L : End of transmission
SIM800L : Receive "AT+SAPBR=0,1
OK
"
GPRS disconnected !
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 1
"
SIM800L : Send "AT+CFUN=4"
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "
OK
"
0
800L Going to SLEEP
Output of Main sketch with "#include <Wire.h>" uncommented:
BOOT
CutOut-L80-800L-HTTPIS005
SIM800L : Reset
SIM800L : Prepare internal buffer of 200 bytes
SIM800L : Prepare reception buffer of 512 bytes
Start of test protocol
SIM800L : Send "AT"
SIM800L : Receive timeout
Problem to initialize AT command, retry in 1 sec
SIM800L : Send "AT"
SIM800L : End of transmission
SIM800L : Receive "AT
OK
"
Module ready
Power Mode SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 4
"
3
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 4
"
SIM800L : Send "AT+CFUN=1"
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 1
"
1
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,2
"
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,2
"
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,2
"
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,2
"
SIM800L : Send "AT+CREG?"
SIM800L : End of transmission
SIM800L : Receive "AT+CREG?
+CREG: 0,1
"
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "AT+CFUN?
+CFUN: 1
"
SIM800L : Send "AT+CFUN=4"
SIM800L : Send "AT+CFUN?"
SIM800L : End of transmission
SIM800L : Receive "
OK
"
0
800L Going to SLEEP
Got to getGPS
$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29
GPRMC,032913.748,V,,,,,2.26,224.88,270623,,,N*4C
GPRMC,032914.748,A,2551.3421,S,02810.7647,E,1.53,0.77,270623,,,A*7E
Lat DD.dddd: 25.855701
Lat DEC: 25513421
Lat HEX: 01854DCD
NS: S
Lon DD.dddd: 28.179414
Lon DEC: 028107647
Lon HEX: 01ACE37F
EW: E
1: GPRMC
2: 032914.748
3: A
4: 2551.3421
5: S
6: 02810.7647
7: E
8: 1.53
txSpeed: 001
9: 0.77
10: 270623
11:
12:
gpsCount: 0
GPS Timeout
GPS OFF
SIM800L : Send "AT+CFUN?"
SIM800L : Receive timeout
0
Going to AWAKE
AT command:
Result: DONE
SignalStrength:
txSignal:
SignalStrength:
txSignal:
SignalStrength:
txSignal:
SignalStrength:
txSignal:
SignalStrength:
txSignal:
--------------------GET Message----------------------
#S##E
msgTX.length: 5
Once the Wire.h library is included, I have a problem in obtaining the required data.
The Accelorometer sketch which works great:
#include <Adafruit_SleepyDog.h>
#include <Wire.h>
#include "SparkFun_LIS2DH12.h"
SPARKFUN_LIS2DH12 accel;
// Acc Stuff
int countAcc;
int accCounter = 0;
int accCount = 20;// Change this for final
int accInterval = 30000;// Change this for final
bool currAcc = false;
bool txRunning = false;
bool txParked = false;
bool txStart = false;
bool txStop = false;
String statusAcc = "";
//*******************
String msgID;
String myDeviceID = "IS005";
void setup() {
// Initialize Serial Monitor for debugging
Serial.begin(9600);
while (!Serial);
Wire.begin();
// Acc Stuff
if (accel.begin() == false)
{
Serial.println("Accelerometer not detected. Are you sure you did a Wire1.begin()? Freezing...");
while (1)
;
}
accel.enableTapDetection();
accel.setTapThreshold(10);//(40); //7-bit value. Max value is 127. 10 is a little low. 40 is ok. 100 is a bit hard.
while (accel.isTapped() == true)
delay(10); //Clear any initial event that may be in the buffer
}
void loop() {
Watchdog.sleep();
countAcc++;
Serial.print("countAcc: ");
Serial.println(countAcc);
delay(100);
// Serial.print("msgID: ");
// Serial.println(msgID);
// delay(50);
if (countAcc >= 4) {
countAcc = 0;
getAcc();
}// END if (countAcc >= 4)
}
void getAcc() {
accCounter = 0;
unsigned long start = millis ();
while (millis () - start <= accInterval)
{
if (accel.isTapped())
{
accCounter++;
// Serial.print("Tap: ");
// Serial.println(accCounter);
while (accel.isTapped() == true)
delay(10); //Wait for event to complete
}
}
Serial.println("Acc Timeout");
delay(50);
if (accCounter == 0) {
currAcc = false;
}
if (accCounter >= accCount) {
currAcc = true;
}
if (!currAcc) {
Serial.print("statusAcc: ");
Serial.println(statusAcc);
delay(50);
if ((statusAcc == "") || (statusAcc == "STOPPED")) {
statusAcc = "PARKED";
msgID = "94";
Serial.print("Tx: ");
Serial.println(msgID);
delay(50);
}
else if ((statusAcc == "RUNNING") || (statusAcc == "STARTED")) {
statusAcc = "STOPPED";
msgID = "93";
Serial.print("Tx: ");
Serial.println(msgID);
delay(50);
}
}// END if (!currAcc) {
if (currAcc) {
Serial.print("statusAcc: ");
Serial.println(statusAcc);
delay(50);
if (statusAcc == "PARKED") {
statusAcc = "STARTED";
msgID = "92";
Serial.print("Tx: ");
Serial.println(msgID);
delay(50);
}
else if (statusAcc == "STARTED") {
statusAcc = "RUNNING";
// msgID = "91";
// Serial.print("Tx: ");
// Serial.println(msgID);
// delay(50);
}
}// END if (currAcc) {
// Serial.print("statusAcc: ");
// Serial.println(statusAcc);
// delay(50);
countAcc = 0;
}
Initial output from Accelerometer sketch:
countAcc: 1
countAcc: 2
countAcc: 3
countAcc: 4
Acc Timeout
statusAcc:
Tx: 94
countAcc: 1
countAcc: 2
countAcc: 3
countAcc: 4
I know the code needs work - cleaning up unused variables etc. etc
Once I can get the combined sketch working, I can attend to that.