Hi,
I am trying to store accelerometer data in sd card for every 100 millisecond. For that, I have written down this code

every 100 milliseconds {
var x = accelerometer.x_axis.read();
var y = accelerometer.y_axis.read();
var z = accelerometer.z_axis.read();
 sd.writer.write(`${x}, ${y}, ${z} \n`);
}

 But now, I want this loop to be stopped after 1 minute. Can anyone here help with how to implement this in MITA?
Also, I would love to store the time stamp in the sdcard. If someone can help me with that also, I would be thankful.

0 (0 Voti)
RE: How to stop an event after certain time in XDK Mita
Risposta
29/07/19 15.15 come risposta a Ankit Chanda.

Hello Ankit Chanda,

Logically you can compute, the number of times you need to loop to reach 1 minute. Based on the value, you can add a for loop in your Mita code to read every 100 ms, till the count is reached.

0 (0 Voti)
RE: How to stop an event after certain time in XDK Mita
Risposta
30/07/19 7.27 come risposta a Padmapriya G.
But I think inside a for loop, its prohibited to write a event block. Will be thankful if you can give a hint with the code. 
0 (0 Voti)
RE: How to stop an event after certain time in XDK Mita
Risposta
30/07/19 13.19 come risposta a Ankit Chanda.

Hello Ankit,

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);
}

 

And regarding looping also, you can implement native c function to increment and maintain count.

 

0 (0 Voti)