Get Current System Time in MITA
Antwort
23.03.19 19:43

Hi,

I am trying to log sensor data into SD card with the current system timestamp.

May I know is there a method in MITA to get current system time?

 

 

0 (0 Stimmen)
RE: Get Current System Time in MITA
Antwort
25.03.19 14:19 als Antwort auf Park Chuan Chiu.

Hi Park Chuan Chiu,

There is no time module as such in Mita for now to retreive the current system time. One way to get system time is to define a native function in Mita which gets time from C implementation. You must setup WiFi to get time from NTP server like "0.de.pool.ntp.org".

1. Implement native function in application.mita. Learn about it https://www.eclipse.org/mita/language/foreignfunctioninterface/#native-functions

native unchecked fn setupTime(): void header "systime.h";

2. Create systime.h in the EclipseMitaApplication project which holds the setupTime() declaration.

3. Create systime.h in the EclipseMitaApplication project which holds the setupTime() definition of sntp implementation. Modify the implementation to return the timestamp to Mita application to write into SD card.

#include "BCDS_WlanNetworkConfig.h"
#include "Serval_Sntp.h"
#define SNTP_DEFAULT_PORT				UINT16_C(123)
#define SNTP_DEFAULT_ADDR				"0.de.pool.ntp.org"
static void onTimeReceive(Ip_Address_T* sourceIp, Ip_Port_T sourcePort, uint32_t timestamp) {
	printf("Timestamp: %lu\n\r", timestamp);
}
static void onSent(Msg_T *msg_ptr, retcode_t status) {
	printf("sent status: %d\n\r", status);
}
void setupTime(void) {
    Sntp_initialize();
    Sntp_start(Ip_convertIntToPort(123), onTimeReceive);
    Ip_Address_T destAddr;
    WlanNetworkConfig_GetIpAddress((uint8_t *) SNTP_DEFAULT_ADDR, &destAddr);
    Sntp_getTime(&destAddr, Ip_convertIntToPort(SNTP_DEFAULT_PORT), onSent);
}
0 (0 Stimmen)