Developer Portal Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    E-Bike Datalogger - some hints required

    Highlighted
    New Poster

    E-Bike Datalogger - some hints required

    Hello!

    I want to log some datapoints to file while riding. Accessing these values should not make any troubles to me. But writing these to file.. I really don't know how to get started with "local storage".

    I'm not an Java or HTML developer, I only have some basic knowlage. So I'm dependent on help.

    I want to take the grid Example and would like to write every 5 seconds Speed and User Power to a new line, separated with tabulator.

    for now the filename could be hardcodet, but do I have to specify a path? or how does the SDK know where to write the file?

    Thanks in advance

    Dennis

    2 REPLIES 2
    Highlighted
    Community Moderator

    Re: E-Bike Datalogger - some hints required

    Hello dkeipp,

    Thank you for posting your question.

    If we understand it correctly, your goal is to persist some data (the speed and the user power). Unfortunately, it is not possible to write directly to a file using HTML5 technologies. Your options would be the following:

    1. Saving the data to local storage and then displaying it when off-ride
    2. Sending the data to a database through an API

    The easiest solution to get started probably is #1. As you probably now, localStorage is a piece of memory in your browser, in which the stored data is saved across browser sessions.

    You would probably implement something as follows:

    function SaveDataToLocalStorage(currentSpeed, currentUserPower)
    {
        var speedValues = [];
        var userPowerValues = []:
    
        // Parse the serialized data back into an aray of objects
        speedValues = JSON.parse(localStorage.getItem('speedData')) || [];
        userPowerValues = JSON.parse(localStorage.getItem('userPowerData')) || [];
    
        // Push the new data (whether it be an object or anything else) onto the array
        speedValues.push(currentSpeed);
        userPowerData.push(currentUserPower);
    
        // Re-serialize the array back into a string and store it in localStorage
        localStorage.setItem('speedData', JSON.stringify(speedValues));
        localStorage.setItem('userPowerData', JSON.stringify(userPowerValues));
    }
    Highlighted
    New Poster

    Re: E-Bike Datalogger - some hints required

    Thanks for this snippet! I think it will help me.

    I'm not sure the script is running in the background (Not tested anything yet). So if I switch for example to navigation my module will not be executed anymore.. is that correct? if so, can I do anything that my module (the datalogger) will be executed in the background?

     

    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