init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
Diff: main.cpp
- Revision:
- 12:8345612bf867
- Parent:
- 11:60eb0ff945f2
- Child:
- 13:29f67f256709
--- a/main.cpp Sat Dec 15 20:09:19 2018 +0000 +++ b/main.cpp Sun Dec 16 01:06:14 2018 +0000 @@ -48,8 +48,11 @@ static char RET_motionData[100] __attribute__((section("noinit"),zero_init)); //EVENT HANDLING +static time_t RET_eventInterval_location_log __attribute__((section("noinit"),zero_init)); static time_t RET_eventTime_location_log __attribute__((section("noinit"),zero_init)); static time_t RET_eventTime_location_bc __attribute__((section("noinit"),zero_init)); + +static time_t RET_eventInterval_environmental_log __attribute__((section("noinit"),zero_init)); static time_t RET_eventTime_environmental_log __attribute__((section("noinit"),zero_init)); static time_t RET_eventTime_environmental_bc __attribute__((section("noinit"),zero_init)); static time_t RET_eventTime_activity_bc __attribute__((section("noinit"),zero_init)); @@ -67,7 +70,7 @@ //PERIPHERALS //------------------------------------------------------------------------------ //BLE myble; -WatchdogTimer watchdog(65.0); //Do not set to less than 4500ms or can cause issues with softdevice +extern WatchdogTimer watchdog(240.0); //Do not set to less than 4500ms or can cause issues with softdevice //SERIAL DEBUG? #if CONSOLE_DEBUG Serial uart(PN_UART_TX, PN_UART_RX, 115200); @@ -145,12 +148,15 @@ RET_mode_prev = RET_mode; RET_RTCunixtime = 0; RET_RTCmicros = 0; + + RET_eventInterval_environmental_log = 0; RET_eventTime_location_log = 0; RET_eventTime_location_bc = 0; RET_eventTime_environmental_log = 0; RET_eventTime_environmental_bc = 0; RET_eventTime_activity_bc = 0; RET_eventTime_wakeFromDormant = 0; + RET_motionPendingOffState = 0; RET_motionPendingOnState = 0; RET_motionTriggered = 0; @@ -254,42 +260,48 @@ //EVENTS //Location - if(time(NULL) > RET_eventTime_location_log && RET_eventTime_location_log > 0) { + if(RET_RTCunixtime > RET_eventTime_location_log && RET_eventTime_location_log > 0) { //getdata_environmental(); //event_location_log(); } - if(time(NULL) > RET_eventTime_location_bc && RET_eventTime_location_bc > 0) { + if(RET_RTCunixtime > RET_eventTime_location_bc && RET_eventTime_location_bc > 0) { //getdata_battery(); //event_location_broadcast(); } //Environmental - if(time(NULL) > RET_eventTime_environmental_log && RET_eventTime_environmental_log > 0) { - //event_environmental_log(); + if(RET_RTCunixtime > RET_eventTime_environmental_log && RET_eventTime_environmental_log > 0) { + Filesystem filesystem(PN_SPI_MOSI,PN_SPI_MISO,PN_SPI_CLK,PN_SPI_CS1); + SI7060 temperature(PN_I2C_SDA,PN_I2C_SCL); + float temperature_c = temperature.getTemperature(); + DEBUG("Temperature log: %u,%f \n", RET_RTCunixtime,temperature_c); + filesystem.addLogEntry_temperature(RET_RTCunixtime,temperature_c); } - if(time(NULL) > RET_eventTime_environmental_bc && RET_eventTime_environmental_bc > 0) { + if(RET_RTCunixtime > RET_eventTime_environmental_bc && RET_eventTime_environmental_bc > 0) { //event_environmental_bc(); + //Filesystem filesystem(PN_SPI_MOSI,PN_SPI_MISO,PN_SPI_CLK,PN_SPI_CS1); } //Activity - if(time(NULL) > RET_eventTime_activity_bc && RET_eventTime_activity_bc > 0) { + if(RET_RTCunixtime > RET_eventTime_activity_bc && RET_eventTime_activity_bc > 0) { //event_activity_bc(); } break; case MODE_DORMANT : - if (time(NULL) > RET_eventTime_wakeFromDormant) { + if (RET_RTCunixtime > RET_eventTime_wakeFromDormant) { RET_mode = MODE_NORMAL; } - break; + break; case MODE_BUTTONPRESS1 : - LED1blink(2,300); + LED1blink(1,300); RET_mode = RET_mode_prev; break; case MODE_BUTTONPRESS2 : - LED1blink(4,300); + LED1blink(3,300); RET_mode = RET_mode_prev; break; case MODE_BUTTONHOLD : LED1blink(10,300); - RET_mode = RET_mode_prev; + RET_eventTime_wakeFromDormant = (RET_RTCunixtime + (48*3600)); //48hrs + RET_mode = MODE_DORMANT; break; default : RET_mode = MODE_SETUP; @@ -333,13 +345,30 @@ if (RET_coldBoot != 1) gotoSleep(30000); //THIS HAS TO BE THE FIRST ITEM IN THE MAIN LOOP watchdog.kick(); - Filesystem filesystem(PN_SPI_MOSI,PN_SPI_MISO,PN_SPI_CLK,PN_SPI_CS1); + //TEST SPACE + Modem modem(PN_UART_TX, PN_UART_RX, PN_UART_CTS, PN_UART_RTS, PN_GSM_PWR_KEY, PN_VREG_EN); + if (modem.on()) { + if (modem.registerOnNetwork(3,60000)) { + if (modem.USSDsend("blahblah", 2)) { + while(1) { + char* response = modem.USSDreceive(105000); + DEBUG("response: %s",response); + } + } + } else { + //modem failed to register on network + } + } else { + //Modem failed to turn on + } - //GET TEMPERATURE - SI7060 temperature(PN_I2C_SDA,PN_I2C_SCL); - float temperature_c = temperature.getTemperature(); - DEBUG("temp: %f \n", temperature_c); - filesystem.addLogEntry_temperature(RET_RTCunixtime, 10.5); + + + while (1) { + Thread::wait(60000); + watchdog.kick(); + } + //MAIN LOGIC DEBUG("mode: %i time: %i, %i, %i, %i \n", RET_mode, RET_RTCmicros, RET_RTCunixtime, RET_buttonHoldTime, RET_buttonPressCount);