int NtpSync(void){ /* Ophalen van pool.ntp.org */ isSyncing = true; setTimeZone(50); httpGet("/gettimezone.php", parsetimezone); _daylight = 0; printf("Timezone is: %d", TIME_ZONE); if(TIME_ZONE == 50) { return 0; } NutDelay(100); //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)"); timeserver = inet_addr("213.154.229.24"); for (;;) { if (NutSNTPGetTime(×erver, &ntp_time) == 0) { break; } else { NutSleep(400); puts("Fout bij het ontvangen van de tijd"); } } //puts("Opgehaald.\n"); ntp_datetime = localtime(&ntp_time); printf("NTP time is: %02d:%02d:%02d\n", ntp_datetime->tm_hour, ntp_datetime->tm_min, ntp_datetime->tm_sec); printf("NTP date is: %02d.%02d.%02d\n\n", ntp_datetime->tm_mday, (ntp_datetime->tm_mon + 1), (ntp_datetime->tm_year + 1900)); X12RtcSetClock(ntp_datetime); NtpWriteTimeToEeprom(*ntp_datetime); isSyncing = false; validTime = true; return 1; }
int main(void) { WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); LcdBackLight(1); PrintStr("Starting System"); Uart0DriverInit(); Uart0DriverStart(); LogInit(); CardInit(); char custom[48] = ALL; LoadCustomChars(custom, 6); X12Init(); if (X12RtcGetClock(&gmt) == 0) { LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); } if (At45dbInit()==AT45DB041B) { // ...... } RcInit(); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs hartbeat interrupt ClearLcdScreen(); //Nieuwe threads aanmaken NutThreadCreate("t01", Thread1, NULL, 512); NutThreadCreate("time", TimeUpdater, NULL, 512); //Start netwerk int i = initNetworkDHCP(); LogMsg_P(LOG_INFO, PSTR("Ethernet Startup Message: [%d]"),i); //Haal Internet tijd op pgmt = getNTPTime(); X12RtcSetClock(&pgmt); //LogMsg_P(LOG_INFO, PSTR("New RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec ); /* * Increase our priority so we can feed the watchdog. */ NutThreadSetPriority(1); /* Enable global interrupts */ sei(); /******************NETWERK**TEST*****************************************************/ //Maak nieuwe socket TCPSOCKET *sock; sock = NutTcpCreateSocket(); //Connect met google.nl LogMsg_P(LOG_INFO, PSTR("Connecting client")); clientConnect(sock); //Zend http req clientSend(sock,buffer,sizeof(buffer)); //Ontvang response in buffer --> grotere buffer (1500)= crash-->heapsize??(8k ram) char rcvbuffer [500]; int rec; rec = clientReceive(sock,rcvbuffer,sizeof(rcvbuffer)); LogMsg_P(LOG_INFO, PSTR("received [%d]"),rec); //0 terminate buffer(string) //rcvbuffer[499] = 0; //Print buffer(http response enz) LogMsg_P(LOG_INFO, PSTR("received [%s]"),rcvbuffer); //Sluit connectie clientClose(sock); /***********************************************************************************/ //Main gui besturing?? for (;;) { NutSleep(100); WatchDogRestart(); } return(0); }