Read movement and time sensors
Answer
12/7/17 2:36 PM

Hello community,

i need some help to start off with the XDK. 

I want to read the movement data connected with the time data and get them together in another program to display them there. 

So basically i want that the XDK saves the current time to the current movement value and give them out in the console (later live via Wifi or Bluetooth). 

I would appreciate if you guys could tell me if this is possible and give me maybe a quick start.

So that you don´t get me wrong i don´t want you guys to program this for me but i don´t want to waste much time if it´s not even possible.

 

Thank you guys in advance.

 

Regards

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/8/17 9:23 AM as a reply to Christian.

Hello Christan,

First I'd like to welcome you to the XDK community. Your use case sounds very interesting and it should be possible to implement it with the XDK. Furthermore, I think you could sense the movement data with the accelerometer and the gyroscope of the XDK.

For more information about how to program both sensors, I recommend taking a look at the corresponding section in the sensor guide.

Regarding the time stamps, please note that there is no real time clock on the XDK and that they can be implemented in more than one way.

You could, for example, use the function xTaskGetTickCount() to receive the current system ticks after the application boots and calculate the time in milliseconds from them.

An implementation could be as follows:

uint32_t currentTime = xTaskGetTickCount()/portTICK_PERIOD_MS;

An alternative to this would be to receive the current time via NTP by using the UDP protocol.

Nevertheless, since you are a beginner, I strongly recommend going through the first steps and freeRTOS guide to get familiar with XDK programming.

Please let me know if that was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo

+1 (1 Vote)
RE: Read movement and time sensors
Answer
12/11/17 1:14 AM as a reply to Franjo Stjepandic.

Hello Franjo,

thank you very much for your reply.

I will test the things out you mentioned and reply here if there are any problems with it.

Hopefully this works. :-)

Thanks!

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/11/17 5:03 PM as a reply to Christian.

Hello Christian,

I am glad to hear that I could help you.

Please feel free to ask, if you have further questions.

Kind regards,
Franjo

+1 (1 Vote)
RE: Read movement and time sensors
Answer
12/12/17 8:05 PM as a reply to Franjo Stjepandic.

Hello Franjo,

i tested the things you mentioned. I guess it could work this way but in the meantime i want to ask another question regarding my idea.

I saw that the program "SendAccelDataOverUdpAndBle" would be the perfect program to start off with my project. I just need to add the time-factor and the other sensors, which would be easy to implement i think. 

But in fact i have very little experience with the Udp programming. Maybe you could help me here again? I just want to connect the XDK with my Router (which works perfectly) and send the AccelerationData and the other data to my computer over Wifi. The console says "Udp sending successful" but how do i get this data to my pc and show it in a textfile or something like that?

So short form: I want to record, send the data over udp, get it from the protocol in a file or something else and display it on the screen to read it out with another program

I dont know if this is a stupid question but i really didnt do anything with these protocols in the past.

I would really appreciate if you could help me again.

Thanks in advance!!

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/13/17 5:10 PM as a reply to Christian.

Hello Christian,

UDP is, with TCP, one of the two most commonly used protocols for transferring data via the internet. Most application protocols (MQTT, HTTP, etc) use TCP or UDP as their basis.

Since you only want to store data in a file, I would recommend using the python socket library. An example for a simple receiving script for UDP can be found here.

To read and write to csv files with python, take a look at the documentation here.

In general, programming with a certain protocol is usually a question of finding a library in your preferred language. And luckily, there are libraries for everything for most languages. At least for everything that is widely and commonly used, such as most protocols.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/14/17 3:54 PM as a reply to Franjo Stjepandic.

Hello Franjo,

this worked. Thank you for your help!

Do you know how to send an Array over Udp filled with Strings? 

If i send only one String it isn´t a problem. But when i send an Array like: 

static char *stringArray[3];
    stringArray[0] = "a";
    stringArray[1] = "b";
    stringArray[2] = "c";

I get in my receiving console only something like this:

´é ¸é ¼é

I guess my receiver cant convert the incoming data into a String.

It would be very hard to send every single dataset in one "sendTo"  command. I would get maybe 20 incoming Udp packages per second. So an Array would be nice.

 

Thanks in Advance!

0 (0 Votes)
RE: Read movement and time sensors
Answer
12/15/17 2:06 PM as a reply to Christian.

Hello Christian,

there are two issues with the code you posted.

The first issue that you declared the array as follows:

static char *stringArray[3];

In C, when you declare an array, it is already implicitly a pointer to the first element of the array, i.e. a pointer to the first position. But if you also use the asterisk (*), you declare a pointer on the pointer. So your datatype is actually the pointer to a pointer to data, instead of a pointer to data. Just remove the asterisk, and this will be fixed.

The compiler should actually be printing warnings, saying that you're using the wrong type, if you were trying to assign elements of type char as the pointers. But in actualitiy, you are assigning strings, not char arrays. A char is, in actuality, just a number of the size of one byte. See the following code snippet and comments:

char *my_string = "a" // resolves to a pointer to the array {'a', '\0'}
char my_character = 'a' // resolves to the decimal value 97

Changing the double quotes to single quotes will fix this issue.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo

0 (0 Votes)