The program sends the current location over the cellular network.

Dependencies:   aconno_I2C ublox-at-cellular-interface gnss ublox-cellular-base Lis2dh12 ublox-cellular-base-n2xx ublox-at-cellular-interface-n2xx low-power-sleep

Fork of example-gnss by u-blox

Revision:
9:f943c09d9173
Parent:
8:2bf886335fd0
--- a/main.cpp	Fri Nov 30 16:19:41 2018 +0100
+++ b/main.cpp	Wed Dec 19 15:12:25 2018 +0100
@@ -18,8 +18,10 @@
 #define RED_LED_PIN			(PE_3)
 #define GREEN_LED_PIN		(PE_4)
 #define BLUE_LED_PIN		(PE_1)
+#define ALARM_OFF           (0)
+#define ALARM_ON            (1)
 
-MainStates state = STATE_IDLE;
+volatile MainStates state = STATE_IDLE;
 
 /* File handler */
 FileHandle *fh;
@@ -30,12 +32,12 @@
 char locationGlobal[UDP_MSG_SIZE_B];
 bool gotGnssFlag = false;
 DigitalIn userButton(USER_BUTTON);
-DigitalOut gnssPower(PE_0, 1);
+DigitalOut gnssPower(PE_0, 0);
 
 DigitalOut redLed(RED_LED_PIN);
 DigitalOut blueLed(BLUE_LED_PIN);
 DigitalOut greenLed(GREEN_LED_PIN);
-DigitalOut alarm(PE_14);
+DigitalOut alarm(PE_14, 0);
 InterruptIn buttonInt(USER_BUTTON);
 
 static bool wasAccInt = false;
@@ -47,7 +49,6 @@
 Thread alarmState; 
 Thread alarmOffState; 
 Thread movementState; 
-Thread ledState;
 Thread gnssLocation;
 
 void my_bsp_init()
@@ -55,7 +56,7 @@
     redLed = 1;
     greenLed = 1;
     blueLed = 1;
-    alarm = 0;
+    alarm = ALARM_OFF;
 }
 
 void buttonRiseHandler(void)
@@ -95,24 +96,13 @@
     }
 }
 
-void ledBlinky()
-{
-    while(!gotGnssFlag)
-    {
-        redLed = !redLed;
-        greenLed = !greenLed;
-        Thread::wait(1000);
-    }
-}
-
 int main()
 {
     bool success = false;
     MainStates nextState = STATE_IDLE;
-
-    my_bsp_init();
     
     buttonInt.rise(buttonRiseHandler);
+    my_bsp_init();
 
     printf("Initialising UART for modem communication: ");
     fh = new UARTSerial(MDMTXD, MDMRXD, 9600);
@@ -124,7 +114,7 @@
     printf("...done\r\n");
 
 	gnssPower = 1;
-    ledState.start(ledBlinky);
+    wait_ms(500);
 
     if(gnss.init())
 	{
@@ -132,7 +122,6 @@
         getGPSData(locationGlobal, &gnss);
         printf("I have the location.\r\n");
         gotGnssFlag = true;
-        ledState.terminate();
         // Turn green led only
         greenLed = 0;
         redLed = 1;
@@ -142,16 +131,16 @@
         printf("Unable to initialise GNSS.\r\n");
     }
 
-    greenLed = 1; 
-    blueLed = 0;
-
     Udp udp("52.215.10.12", 3334);
     UBloxSara sara(at, udp);
     printf("Initializing the modem: \r\n");
 	sara.setup();
+    sara.connectNB();
     printf("done...\r\n");
-    sara.connectNB();
 
+    alarm = ALARM_OFF;
+    greenLed = 1; 
+    blueLed = 0;
     myParams_t myParams;
     myParams.gnss = &gnss;
     myParams.sara = &sara;
@@ -195,13 +184,13 @@
                 }
                 else
                 {
-                    alarm = 1;
+                    alarm = ALARM_ON;
                 }
             	break;
             case STATE_ALARM_OFF:
                 nextState = STATE_IDLE;
                 idleState.signal_set(IDLE_SIGNAL);
-                alarm = 0;
+                alarm = ALARM_OFF;
                 blueLed = 0;
 				break;
             case STATE_LIS_DETECTION: