This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to write and save the data in .txt file on my computer?

Hi guys,

Based on the examples that I found in Zephyr samples documentation, I created the program where I am able to measure the voltage and temperature, and then send the data via BLE to my mobile phone. Now, I am interested to know how can I save the values (for example the voltage values) in .txt file on my computer? I tried to use the regular code in C as I did so many times before, but I am still not able to flash my board and run the code. There are multiple errors such as:

1) note: 'fopen' is defined in header '<stdio.h>'; did you forget to '#include <stdio.h>'? - even if I have already included this library

2) warning: assignment to 'FILE *' {aka 'int *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
   64 |  voltage_value = fopen("voltage_values.txt", "a+");

3) warning: passing argument 2 of 'fprintf' makes pointer from integer without a cast [-Wint-conversion]
84 | fprintf(voltage_value, batt_mV);

Is there maybe the different code for nRF52832 board and Zephyr? Can you maybe give me some advice or even send me an example which will be definitely the better option. I am looking forward to hear your answer.

Best regards,

Adnan.

Parents
  • I created the program where I am able to measure the voltage and temperature, and then send the data via BLE to my mobile phone. Now, I am interested to know how can I save the values (for example the voltage values) in .txt file on my computer?

     So how is the nRF connected to your computer? Or do you intend to transfer the file from the mobile phone to the computer? I am not sure I understand your setup.

    BR,

    Edvin

  • The board is connected via USB to my computer and I just want to write some values (in this case the voltage) in .txt file and save that file to my computer, for example in the same folder where my example is. For the second example, I will use the external power source (in my case the environment emulator) and try to do the same thing. This is the simple example in regular C, but as I mentioned I tried using that code but unsuccessfully. Do you understand better now, what I need. 

    Thanks in advance for any type of help.

    Best regards,

    Adnan.

  • I use the nRF52832 DK board. I just use the existing solutions that are included in Zephyr samples and mix 2 or 3 different samples (read the voltage, measure the temperature, and send the data via BLE). I found that is possible to use MicroPython for creating and reading files in Zephyr. I only need that, to create a txt file, read the temperature, write this file in the file, and close it. That's only what I need for now. And after that, I will be possible to open that file in my application folder. Is that possible with my board and Zephyr, but to program that in embedded C, not in MicroPython.

    If you still cannot understand what I need, this is the link where I found these functions in MicroPython: http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/filesystem.html

    Thanks in advance and best regards, 

    Adnan.

  • Aduka_27 said:
    I found that is possible to use MicroPython for creating and reading files in Zephyr.

     That will not work on the nRF52832. Remember that the code is running on the nRF52832 chip, and not on your computer. Since the nRF52832 is not connected to your computer, it can not access the file system on your computer. I am sorry.

    BR,

    Edvin

  • What you can look into, but this is a bit outside what we give support for, is to see if you can create an application running on Windows that connect to your device over BLE, read the temperature and save that to a .txt file on your computer.

    BR,

    Edvin

  • Thank you very much for this answer and advice. Also, on the official website (link: https://docs.zephyrproject.org/2.3.0/reference/file_system/index.html) I found this File Systems and they explained something that is quite similar to regular C method. Can you take a look on this link and see if I can use that?

    Also, is there a possibility to use NVM (non-volatile memory) and there to create a file and store these values?

    Thanks in advance and best regards,

    Adnan.

  • Aduka_27 said:
    Also, is there a possibility to use NVM (non-volatile memory) and there to create a file and store these values?

     

    Yes. That is possible. But that would be stored on the nRF. Not the computer. The part that I am trying to explain is that the application you are writing in Zephyr is running on the microcontroller, and it is not connected to your computer. Yes, it is connected via the programmer, but that is only for programming and logging purposes.

Reply
  • Aduka_27 said:
    Also, is there a possibility to use NVM (non-volatile memory) and there to create a file and store these values?

     

    Yes. That is possible. But that would be stored on the nRF. Not the computer. The part that I am trying to explain is that the application you are writing in Zephyr is running on the microcontroller, and it is not connected to your computer. Yes, it is connected via the programmer, but that is only for programming and logging purposes.

Children
Related