Ejemplo n.º 1
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));
}
Ejemplo n.º 2
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);
}
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);
}
void generate_email_body()
{
    os_sprintf(generatedEmailBody, "Triggered Sensors:\n");
    int i;
    for (i = 0; i < triggeredSensorsIter; i++)
    {
        os_sprintf(generatedEmailBody, "%s%s- triggered at: %s\n", generatedEmailBody, 
                   triggeredSensorsNames[i], sntp_get_real_time(triggeredSensorsTimestamps[i]));
    }
}
Ejemplo n.º 5
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);
    }
}
Ejemplo n.º 6
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();
}
Ejemplo n.º 7
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;
}
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);
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
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);
    
}
Ejemplo n.º 11
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));
}