Esempio n. 1
0
/*
 * Wait for a correct time, and report it.
 * Don't wait longer than ... for it.
 */
time_t GetTime::getTime() {
  time_t t;
  int count = 0;

  t = sntp_get_current_timestamp();
  while (t < 0x1000) {
    count++;
    if (count > max_count)
      return 0;
    delay(initial_delay);
    t = sntp_get_current_timestamp();
  }
  return t;
}
Esempio n. 2
0
static void ICACHE_FLASH_ATTR
sntp_timer_cb(void *arg)
{
    uint32_t time = sntp_get_current_timestamp();
    os_printf("time:%d\t - %s",
    		time, sntp_get_real_time(time));
}
Esempio n. 3
0
static void ICACHE_FLASH_ATTR test_timer_cb()
{
	int32_t cs = sntp_get_current_timestamp();

	os_printf("Current timestamp: %d\r\n", cs);
	os_printf("Current Time: %s\r\n\r\n", sntp_get_real_time(cs));
	os_timer_arm(&test_timer, 3000, 0);
}
Esempio n. 4
0
time_t time(time_t * t)
{
    time_t seconds = sntp_get_current_timestamp();
    if (t)
    {
        *t = seconds;
    }
    return seconds;
}
Esempio n. 5
0
void ICACHE_FLASH_ATTR
rtc_timezone(uint8_t timezone)
{
  sntp_stop();
//  if (true == sntp_set_timezone(sysCfg.timezone))
  sntp_set_timezone(timezone);
  sntp_init();
  myrtc = sntp_get_current_timestamp();
}
Esempio n. 6
0
time_t ICACHE_FLASH_ATTR time()
{
	int t = sntp_get_current_timestamp();
	if (t < SANE_TIME) return 0;
	// they hard coded a GMT+8 timezone
	// we want to work with GMT all the way thru.
	t -= 8 * 60 * 60;
	return(t);
}
Esempio n. 7
0
void ICACHE_FLASH_ATTR onesec(void *arg)
{
	int i;
	struct time_entry *t;
	int recompute = 0;
	static int first_compute = 0;
	if (!first_compute)
	{
		if (time() > SANE_TIME)
		{
			first_compute = 1;
			compute_times();
		}
		os_printf("waiting for sane_time %d %d\n",sntp_get_current_timestamp(),time());
		return;
	}
	for (i = 1; i <=8; i++)
	{
		if (countdown[i-1])
		{
			countdown[i-1]--;
			if (countdown[i-1] == 0)
			{
				set_relay(i,0,0);
			}
		}
	}

	time_t now = time();
	for (i = time_count, t = times; i > 0; i--, t++)
	{
		//os_printf("zone=%d now=%d ontime=%d recompute=%d ctr=%d\n",t->zone,now, t->ontime, recompute, i);
		if (now >= t->ontime)
		{
			recompute++;

			if (t->zone == 100)
			{
				start_reset();
			}
			else if (t->zone == 101)
			{
				set_all_relays_off();
			}
			else
			{
				set_relay(t->zone,1,t->duration);
			}
		}
	}

	if (recompute) compute_times();

}
Esempio n. 8
0
// calculate offset used in gettimeofday
static void ensureBootTimeIsSet()
{
    if (!s_bootTime)
    {
        time_t now = sntp_get_current_timestamp();
        if (now)
        {
            s_bootTime =  now - millis() / 1000;
        }
    }
}
Esempio n. 9
0
void sntpfn()
{
    u32_t ts = 0;
    ts = sntp_get_current_timestamp();
    os_printf("current time : %s\n", sntp_get_real_time(ts));
    if (ts == 0) {
        //os_printf("did not get a valid time from sntp server\n");
    } else {
            os_timer_disarm(&sntp_timer);
            MQTT_Connect(&mqttClient);
    }
}
void ntp_setup(void)
{
    tv_t tv;
    tz_t tz;
	time_t sec;

    if(!network_init)
		return;

	if(ntp_init == 0)
    {
        ip_addr_t *addr = (ip_addr_t *)os_zalloc(sizeof(ip_addr_t));
		ipaddr_aton("192.168.200.1", addr);
		sntp_setserver(1,addr);
		ipaddr_aton("192.168.200.240", addr);
		sntp_setserver(2,addr);
        sntp_init();
        os_free(addr);
		ntp_init = 1;
        DEBUG_PRINTF("NTP:1\n");
    }
	if(ntp_init == 1)
	{
		// they hard coded it to +8 hours from GMT
		sec = sntp_get_current_timestamp();
		if(sec > 10)
		{
			ntp_init = 2;
		}
	}
    if(ntp_init == 2)
    {
		sntp_stop();
		DEBUG_PRINTF("NTP:2\n");

		// they return GMT + 8
        sec = sec - (8UL * 3600UL);

		// we are GMT - 4
        sec = sec - (4UL * 3600UL);

        tv.tv_sec = sec;
        tv.tv_usec = 0;
        tz.tz_minuteswest = 0;

        settimeofday(&tv, &tz);

        DEBUG_PRINTF("SEC:%ld\n",sec);
        DEBUG_PRINTF("TIME:%s\n", ctime(&sec));
		ntp_init = 3;
    }
}
Esempio n. 11
0
int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
{
    (void) unused;
    (void) tzp;
    if (tp)
    {
        if (!timeshift64_is_set)
            tune_timeshift64(sntp_get_current_timestamp() * 1000000ULL);
        uint64_t currentTime_us = timeshift64 + micros64();
        tp->tv_sec = currentTime_us / 1000000ULL;
        tp->tv_usec = currentTime_us % 1000000ULL;
    }
    return 0;
}
Esempio n. 12
0
//Called from the wifi callback, Set the clock from NTP
void ICACHE_FLASH_ATTR NIXE_Set_Clock_Wifi() {
    sntp_setservername(0, "se.pool.ntp.org"); // set server 0 by domain name
    sntp_setservername(1, "0.europe.pool.ntp.org"); // set server 1 by domain name
    sntp_set_timezone(+1);
    sntp_init();
    
    uint32 current_stamp;
    current_stamp = sntp_get_current_timestamp();
    os_printf("sntp: %d, %s \n",current_stamp, sntp_get_real_time(current_stamp));
    //Update the External RTC via i2c
    
    // init tm Struct
    /*
    
    
    time->tm_sec
    time->tm_min
    time->tm_hour
    time->tm_wday
    time->tm_mday
    time->tm_mon
    time->tm_year
    */
    time_t unix = sntp_get_current_timestamp();

    //nixietime = gmtime(&unix); //gmtime not in sdk..
    tm_sec +
    tm_min*60
    tm_hour*3600
    tm_yday*86400 +
    (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 -
    ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400
    
    ds1307_setTime(nixietime);
    
}
Esempio n. 13
0
void ICACHE_FLASH_ATTR
rtc_second()
{
  // NTP Sync every hour at x:0:10
  if (rtcTime.Minute == 0) {
    if ((rtcTime.Second == 10) && !ntpsync) {
      ntpsync = 1;
      myrtc = sntp_get_current_timestamp() -1;
      INFO("sntp: %d, %s \n", myrtc, sntp_get_real_time(myrtc));
    }
    if (rtcTime.Second == 40) ntpsync = 0;
  }
  myrtc++;
  convertTime();
}
Esempio n. 14
0
/**
 * Simple logging function.
 *
 * Would be nice the add TCP client logging later and/or formatting of the
 * timestamp.
 */
void ICACHE_FLASH_ATTR console(char *fmt, ...)
{
	uint32 timestamp;

	timestamp = sntp_get_current_timestamp();

	va_list argp;
	va_start(argp, fmt);

	ets_uart_printf("%10.10u:", timestamp);
	ets_uart_printf(fmt, argp);
	// syslog(LOG_DEBUG | LOG_LOCAL0, fmt, argp);

	va_end(argp);
}
Esempio n. 15
0
uint32_t ICACHE_FLASH_ATTR NTP_Time(PACKET_CMD *cmd)
{
  
  uint32   current_stamp = 0;
  char    *time          = NULL;
  uint16_t crc;

  current_stamp = sntp_get_current_timestamp();
  time          = sntp_get_real_time(current_stamp);

  crc = CMD_ResponseStart(CMD_NTP_TIME, cmd->callback, 0, 1);
  crc = CMD_ResponseBody(crc, (uint8_t*)time, os_strlen(time));
  CMD_ResponseEnd(crc);

  return 0;
}
Esempio n. 16
0
void ICACHE_FLASH_ATTR
at_queryCmdNTP(uint8_t id)
{
    uint8 buffer[255] = {0};
    time_t tim = (time_t)sntp_get_current_timestamp();
    struct tm *t;
    if (tim > 0) {
	t = localtime(&tim);
	os_sprintf(buffer, "NTP Time: %02d:%02d:%02d %02d.%02d.%04d %s (%d)sec\r\n", t->tm_hour,t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon + 1, t->tm_year + 1900, weekday[t->tm_wday], tim);
	at_port_print(buffer);
	at_response_ok();
    } else {
	os_sprintf(buffer, "NTP Error: (0)\r\n");
	at_port_print(buffer);
	at_response_error();
    }
}
irom static app_action_t application_function_ntp_dump(const string_t *src, string_t *dst)
{
	ip_addr_t addr;
	int timezone;

	timezone = sntp_get_timezone();
	addr = sntp_getserver(0);

	string_cat(dst, "> server: ");
	string_ip(dst, addr);

	string_format(dst, "\n> time zone: GMT%c%d\n> ntp time: %s",
			timezone < 0 ? '-' : '+',
			timezone < 0 ? 0 - timezone : timezone,
			sntp_get_real_time(sntp_get_current_timestamp()));

	return(app_action_normal);
}
void updateWebpage()
{ 
    int i;
    char* temp = "<title>ESP8266 Home Monitor</title>\n";

    // display whether the alarm is armed or disarmed
    if (alarmArmed)
        os_sprintf(generatedWebpage, "%s<b>Alarm state: </b>ARMED!<br>\n", temp);
    else
        os_sprintf(generatedWebpage, "%s<b>Alarm state: </b>not armed<br>\n", temp);

    if (triggeredSensorsIter > 0)
    {
        os_sprintf(generatedWebpage, "%s<br><b>Triggered Sensors:</b><br><ol>\n", generatedWebpage);
        for (i = 0; i < triggeredSensorsIter; i++)
        {
            os_sprintf(generatedWebpage, "%s<b><li>%s</b> - triggered at: %s</li>\n", generatedWebpage, 
                       triggeredSensorsNames[i], sntp_get_real_time(triggeredSensorsTimestamps[i]));
        }
        //end the ordered list
        os_sprintf(generatedWebpage, "%s</ol><br>\n", generatedWebpage);
    }
    else
        os_sprintf(generatedWebpage, "%s<br>No triggered sensors\n",generatedWebpage);

    // the clear button
    os_sprintf(generatedWebpage, 
        "%s<br>\n<form action=\"clear\"><input type=\"submit\" value=\"Clear\"></form>", 
        generatedWebpage);
    // the arm button
    os_sprintf(generatedWebpage, 
        "%s\n<form action=\"arm\"><input type=\"submit\" value=\"Arm Alarm\"></form>", 
        generatedWebpage);
    // the disarm button
    os_sprintf(generatedWebpage, 
        "%s\n<form action=\"disarm\"><input type=\"submit\" value=\"Disarm Alarm\"></form>", 
        generatedWebpage);
    // time page was last updated
    os_sprintf(generatedWebpage, 
        "%s\n<br>\nLast updated at: %s\n",
        generatedWebpage, sntp_get_real_time(sntp_get_current_timestamp()));

    set_webpage(generatedWebpage);
}
Esempio n. 19
0
ICACHE_FLASH_ATTR
void
syslog_send(int fac_pri, const char *fmt, ...)
{
	va_list ap;
	static char syslogpkt[128];
	static char timestr[64];
	const char *hostname;
	char *p;
	sint8 rc;

	if ((hostname = syslog_hostname) == NULL)
		hostname = "esp8266";

	os_strcpy(timestr, sntp_get_real_time(sntp_get_current_timestamp()));

	/*
	 * "Thu Sep 03 03:33:33 2015\n"
	 *  0123456789012345678901234
	 */
	if (timestr[8] == '0')
		timestr[8] = ' ';
	timestr[19] = '\0';

	sprintf(syslogpkt, "<%d>%s %s ",
	    fac_pri, &timestr[4], hostname);

	for (p = syslogpkt; *p != '\0'; p++)
		;

	va_start(ap, fmt);
	ets_vsprintf(p, fmt, ap);
	va_end(ap);

	for (p = syslogpkt; *p != '\0'; p++)
		;

	rc = espconn_sent(&syslog_espconn, syslogpkt, p - syslogpkt);
}
static void ICACHE_FLASH_ATTR
scheduler_check_tasks(void)
{
#ifdef DEBUG
    os_printf("[debug] scheduler_check_tasks\r\n");
#endif

    /* if the epoch time is not set, try again the next time when this function is called */
    if (sntp_get_current_timestamp() == 0) {
        os_printf("[error] scheduler_check_tasks: epoch time not set, cannot execute scheduled tasks! retrying in %u secs..\r\n", scheduler_timer_ms / 1000);

        /* turn on the red led */
        LED_toggle(RED_LED, LED_ON);

        return;
    }

    /* turn off the red led */
    LED_toggle(RED_LED, LED_OFF);

    /* get the current time */
    date_time_t date_time;
    epoch_to_date_time(&date_time, sntp_get_current_timestamp());

#ifdef DEBUG
    os_printf("[debug] scheduler_get_current_date: second: [%u] | minute: [%u] | hour: [%u] | day: [%u] | month: [%u] | year: [%u]\r\n",
        date_time.second, date_time.minute, date_time.hour, date_time.day, date_time.month, date_time.year);
#endif

    /*
     * the following code outlines the scheduler every 5 minutes on 0,5,10,15,20,25,30,35,40,45,50,55
     */
    if (scheduler_timer_ms == 1000) {
        /* if the seconds are on 0, update the timer to 1 minute */
        if (date_time.second == 0) {
            /* if the the minutes are on 0,5,10,15,20,25,30,35,40,45,50,55 update the timer to 5 minutes */
            if ((date_time.minute == 0) || (date_time.minute == 5) || (date_time.minute == 10) || (date_time.minute == 15) || 
                (date_time.minute == 20) || (date_time.minute == 25) || (date_time.minute == 30) || (date_time.minute == 35) ||
                (date_time.minute == 40) || (date_time.minute == 45) || (date_time.minute == 50) || (date_time.minute == 55)) {

#ifdef DEBUG
                os_printf("[debug] scheduler_get_current_date: updating scheduler to every 5 minutes.\r\n");
#endif

                /* disarm the timer */
                os_timer_disarm(&scheduler_timer);

                /* 5 minutes (300000ms) */
                scheduler_timer_ms = 300000;

                /* re-arm the timer and execute the scheduler every 5 minutes */
                os_timer_setfn(&scheduler_timer, (os_timer_func_t *)scheduler_check_tasks, NULL);
                os_timer_arm(&scheduler_timer, scheduler_timer_ms, 1);
            } else {
#ifdef DEBUG
                os_printf("[debug] scheduler_get_current_date: updating scheduler to every minute.\r\n");
#endif

                /* disarm the timer */
                os_timer_disarm(&scheduler_timer);

                /* 1 minute (60000ms) */
                scheduler_timer_ms = 60000;

                /* re-arm the timer and execute the scheduler every minute */
                os_timer_setfn(&scheduler_timer, (os_timer_func_t *)scheduler_check_tasks, NULL);
                os_timer_arm(&scheduler_timer, scheduler_timer_ms, 1);
            }
        } else {
            /* do nothing */
            return;
        }
    } else if (scheduler_timer_ms == 60000) {
        /* check if the timer is outlined correctly, if not reschedule it again */
        if (date_time.second != 0) {
            /* disarm the timer */
            os_timer_disarm(&scheduler_timer);

             /* reset it after 5 secs */
            os_timer_disarm(&scheduler_reset_timer);
            os_timer_setfn(&scheduler_reset_timer, (os_timer_func_t *)scheduler_reset_scheduler_timer, NULL);
            os_timer_arm(&scheduler_reset_timer, 5000, 0);
        }

        /* if the the minutes are on 0,5,10,15,20,25,30,35,40,45,50,55 update the timer to 5 minutes */
        if ((date_time.minute == 0) || (date_time.minute == 5) || (date_time.minute == 10) || (date_time.minute == 15) || 
            (date_time.minute == 20) || (date_time.minute == 25) || (date_time.minute == 30) || (date_time.minute == 35) ||
            (date_time.minute == 40) || (date_time.minute == 45) || (date_time.minute == 50) || (date_time.minute == 55)) {

#ifdef DEBUG
            os_printf("[debug] scheduler_get_current_date: updating scheduler to every 5 minutes.\r\n");
#endif

            /* disarm the timer */
            os_timer_disarm(&scheduler_timer);

            /* 5 minutes (300000ms) */
            scheduler_timer_ms = 300000;

            /* re-arm the timer and execute the scheduler every 5 minutes */
            os_timer_setfn(&scheduler_timer, (os_timer_func_t *)scheduler_check_tasks, NULL);
            os_timer_arm(&scheduler_timer, scheduler_timer_ms, 1);
        }
    } else if (scheduler_timer_ms == 300000) {
        /* check if the timer is outlined correctly, if not reschedule it again */
        if (date_time.second != 0) {
            /* disarm the timer */
            os_timer_disarm(&scheduler_timer);

             /* reset it after 5 secs */
            os_timer_disarm(&scheduler_reset_timer);
            os_timer_setfn(&scheduler_reset_timer, (os_timer_func_t *)scheduler_reset_scheduler_timer, NULL);
            os_timer_arm(&scheduler_reset_timer, 5000, 0);
        }
    }

    /* if the queue post interval is 5, post the queue every 5 minutes */
    if (queue_post_interval == 5) {
        if ((date_time.minute == 0) || (date_time.minute == 5) || (date_time.minute == 10) || (date_time.minute == 15) ||
            (date_time.minute == 20) || (date_time.minute == 25) || (date_time.minute == 30) || (date_time.minute == 35) ||
            (date_time.minute == 40) || (date_time.minute == 45) || (date_time.minute == 50) || (date_time.minute == 55)) {

            /* if it's 00:00 reset all counters */
            if ((date_time.hour == 0) && (date_time.minute == 0)) {
                interrupt_reset_total_energy_state();
            }

            /* for some reason it can happen that the energy states are not correctly reset on 00:00,
             * so for the time being we are gonna do an extra check/reset
             */
            if ((date_time.hour == 0) && (date_time.minute == 5)) {
                if (interval_pulse_count != pulse_count) {
                    /* reset the pulse_count to the interval_pulse_count */
                    os_printf("[error] scheduler_check_tasks: pulse_count [%u] not equals interval_pulse_count [%u] at 00:05, syncing values..\r\n",
                        pulse_count, interval_pulse_count);

                    pulse_count = interval_pulse_count;
                }
            }

            /* update the post queue */
            queue_update_post_queue();

            /* reset the power and interval pulse count variables */
            interrupt_reset_power_state();

            if (OUTPUT_CLIENT == PVOUTPUT) {
                /* try to post the queue items and if it's successfull empty the queue */
                queue_post_items_to_pvoutput();
            } else if (OUTPUT_CLIENT == THINGSPEAK) {
                /* try to post the queue items and if it's successfull empty the queue */
                queue_post_items_to_thingspeak();
            }
        }
    } else if (queue_post_interval == 15) {
        /* if the queue post interval is 15, post the queue every 15 minutes */
        if ((date_time.minute == 0) || (date_time.minute == 15) || (date_time.minute == 30) || (date_time.minute == 45)) {
            /* if it's 00:00 reset all counters */
            if ((date_time.hour == 0) && (date_time.minute == 0)) {
                interrupt_reset_total_energy_state();
            }

            /* for some reason it can happen that the energy states are not correctly reset on 00:00,
             * so for the time being we are gonna do an extra check/reset
             */
            if ((date_time.hour == 0) && (date_time.minute == 15)) {
                if (interval_pulse_count != pulse_count) {
                    /* reset the pulse_count to the interval_pulse_count */
                    os_printf("[error] scheduler_check_tasks: pulse_count [%u] not equals interval_pulse_count [%u] at 00:15, syncing values..\r\n",
                        pulse_count, interval_pulse_count);

                    pulse_count = interval_pulse_count;
                }
            }

            /* update the post queue */
            queue_update_post_queue();

            /* reset the power and interval pulse count variables */
            interrupt_reset_power_state();

            if (OUTPUT_CLIENT == PVOUTPUT) {
                /* try to post the queued items and if it's successfull empty the queue */
                queue_post_items_to_pvoutput();
            } else if (OUTPUT_CLIENT == THINGSPEAK) {
                /* try to post the queue items and if it's successfull empty the queue */
                queue_post_items_to_thingspeak();
            }
        }
    }
}
Esempio n. 21
0
void ntp_setup(void)
{
    tv_t tv;
    tz_t tz;
	time_t sec;
	struct ip_info getinfo;


	// Wait until we have an IP address before we set the time
    if(!network_init)
		return;

	if(ntp_init == 0)
    {
        ip_addr_t *addr = (ip_addr_t *)safecalloc(sizeof(ip_addr_t),1);

		// form pool.ntp.org
		ipaddr_aton("206.108.0.131", addr);
		sntp_setserver(1,addr);
		ipaddr_aton("167.114.204.238", addr);
		sntp_setserver(2,addr);

#if 0
		// Alternate time setting if the local router does NTP
		if(wifi_get_ip_info(0, &getinfo))
		{
			printf("NTP:0 GW: %s\n", ipv4_2str(getinfo.gw.addr));
			printf("NTP:0 IP: %s\n", ipv4_2str(getinfo.ip.addr));
			sntp_setserver(1, & getinfo.gw);
			sntp_setserver(2, & getinfo.ip);
		}
		else
		{
			printf("NTP:0 failed to get GW address\n");
			return;
		}
#endif

        if( sntp_set_timezone(0) )
		{
			printf("NTP: set_timeone OK\n");
			sntp_init();
            safefree(addr);
		    ntp_init = 1;
            printf("NTP:1\n");
		}
		else
		{
			printf("NTP: set_timeone Failed\n");
		}
    }

	if(ntp_init == 1)
	{
		// they hard coded it to +8 hours from GMT
		if( (sec = sntp_get_current_timestamp()) > 10 )
		{
			sntp_stop();
			ntp_init = 2;
		}
	}
	if(ntp_init == 2)
	{
		time_t s;

		tm_t *p;

		printf("NTP:2\n");

		// they return GMT + 8
        // sec = sec - (8UL * 3600UL);

        tv.tv_sec = sec;
		printf("ntp_init: %s\n", asctime(gmtime(&sec)));
		printf("ntp_init: %s\n", ctime_gm(&sec));

        tv.tv_usec = 0;
        tz.tz_minuteswest = 300;
		tz.tz_dsttime = 0;

        settimeofday(&tv, &tz);

        printf("SEC:%ld\n",sec);
        printf("TIME:%s\n", ctime(&sec));
		printf("Zone: %d\n", (int) sntp_get_timezone());
		ntp_init = 3;

		set_dst(tv.tv_sec);

		print_dst_gmt();
		print_dst();

		p = gmtime(&tv.tv_sec);
		mktime(p);
		printf("Localtime: %s\n", asctime(p));
    }
}
Esempio n. 22
0
LOCAL void ICACHE_FLASH_ATTR sntp_cb() {
	uint32 current_stamp;
	current_stamp = sntp_get_current_timestamp();
	os_printf("sntp: %d, %s \n",current_stamp, sntp_get_real_time(current_stamp));
}
Esempio n. 23
0
// Command handler for time
static void ICACHE_FLASH_ATTR
cmdGetTime(CmdPacket *cmd) {
  cmdResponseStart(CMD_RESP_V, sntp_get_current_timestamp(), 0);
  cmdResponseEnd();
  return;
}
static void ICACHE_FLASH_ATTR loop(os_event_t* events)
{
    if (!initFinished)
    {
        // loop by adding this function to the task queue
        system_os_post(user_procTaskPrio, 0, 0);

        if(is_wifi_connected())
        {
            user_init2();
            initFinished = true;
        }

        return;
    }

    static bool pendingEmailAlert = false;
    // check unprocessed OOK packets to see if there are any newly
    //   triggered sensors
    bool newTriggerings = false;
    while(packets_available(&unprocessedPackets))
    {
        uint32 packet = packet_pop(&unprocessedPackets);
        char* source = my_strdup(ook_ID_to_name(packet));
        // check if the current packet is a new triggering
        bool packetIsNewTriggering = true;

#ifdef PRINT_OOK_PACKETS_DEBUG
        os_printf("%x\r\n", packet);
#endif
        // check for the key fob signals for arming/disarming
        if (packet == ARM_CODE)
            arm_alarm();
        else if (packet == DISARM_CODE)
            disarm_alarm();
        // must be some other code, or invalid
        else if (source != NULL && alarmArmed)
        {
            int i, j;
            // ensure that an already-triggered sensor is not duplicated in list
            for (i = 0; i < triggeredSensorsIter; i++)
            {
                if (triggeredSensorsNames[i] != NULL)
                    for (j = 0; source[j] == triggeredSensorsNames[i][j]; j++)
                    {
                        // reached the end of both strings and they've been the
                        // same all along
                        if (source[j] == '\0')
                            packetIsNewTriggering = false;
                    }
            }
            if (packetIsNewTriggering)
            {
                triggeredSensorsNames[triggeredSensorsIter] = source;
                triggeredSensorsTimestamps[triggeredSensorsIter] = sntp_get_current_timestamp();
                triggeredSensorsIter += 1;
                newTriggerings = true;
            }
            else
                os_free(source);
        }
    }

    if (newTriggerings)
    {
        updateWebpage();
        pendingEmailAlert = true;
    }

    // checked so that a pending email alert is cancelled if the "disarm" button is pressed after a
    //   sensor has been triggered
    if(!alarmArmed)
        pendingEmailAlert = false;
    
    if (pendingEmailAlert)
    {
        if (triggeredSensorsIter > 0 &&
            sntp_get_current_timestamp() - triggeredSensorsTimestamps[0] > ALERT_EMAIL_DELAY)
        {
            generate_email_body();
            send_email("ESP8266 Alarm", generatedEmailBody); 
#ifdef PRINT_EMAIL_DEBUG
            os_printf("trying to send email\n");
#endif
            pendingEmailAlert = false;
        }
    }

    // loop by adding this function to the task queue
    system_os_post(user_procTaskPrio, 0, 0);
}