Developer Portal Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    Accessing C Values in Mita

    pele
    Occasional Visitor

    Accessing C Values in Mita

    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:

    • get a timestamp

    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?

    • log console output

    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?

    Tags (3)
    1 REPLY 1
    Padmapriya
    Long-established Member

    Re: Accessing C Values in Mita

    Hello Pele,

    • Why do you need to get timestamp ? SNTP time is required only when secured MQTT communication is done. Are you trying to establish secured communication with server ?
    • Why do you need to access the SNTP timestamp in mita ?
      • The timestamp generated by the mita code cannot be accessed in mita
    • One way to use timestamp is to write mita code which generates timestamp. This can be done by defining 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);
    }

     

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist