Hey everyone,
I'm using Mita on XDK with MQTT Client and SD Card.
Can I use C variables/values in mita?
What I'm trying to do is:
during setup of the MQTTclient is a SntpTimeCallback performed, storing the current time in the variable timezoneISO8601format : 2019-08-01T14:00:26
Console Output: ConnectivityMQTTMqttclient.c:199] MQTT_Enable : Getting time successful. Current time is 2019-08-01T14:00:26Z˜>
Can I access this variable in mita?
the mita generated C-Code performs console Outputs like
printf("[ERROR, %s:%d] MQTT_Enable : MQTT init session failed: %x\n", __FILE__, __LINE__, mqttRetcode);
exception = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_MQTT_INIT_INTERNAL_SESSION_FAILED);
Is there a way to access it via mita?
Solved! Go to Solution.
Hello Pele,
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);
}