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

Source code (main.c) of "thingy91_nbiot_legacy_pco_dfu"

Hi everyone!

I'm running my Nordic Thingy 91 with "thingy91_nbiot_legacy_pco_dfu" and it works great!

Now, i want to make some specifics editions in the main code in order to add one new feature for my project. My question is:

Where can i find the "main.c" file to add my new function? And then compile and flash.

Parents
  • Hi, Alejandro!

    All the samples running on the Thingy:91 are present in the nRF Connect SDK. To be able to change, compile and flash new code for the device you should follow the installation guidelines for the SDK. The specific sample you are referring to is the nRF9160 Asset Tracker. To compile the sample for the Thingy:91 follow the guide on how to compile and program from source code.

    EDIT here: it should be enough to build the application with the following command, as it will use a preconfigured overlay for the Thingy:91:
     

    west build -b thingy91_nrf9160ns


    If you would like the Legacy PCO functionality you must change CONFIG_LTE_LEGACY_PCO_MODE from "n" to "y" in prj_thingy91_nrf9160ns.conf.

    Please ask if you have any other questions.

    Best regards,
    Carl Richard

  • I understand, thanks Carl!

    I want to recicle the Asset Tracker application that it's currently running but including one function that sets one of GPIOs as 1 (logically True) or 0 (logically False) when the device receives in an specific topic a message like {"lights":"on"}.

    How can I set as 1 or 0 an specific GPIO from the main.c?

  • Hi again, Alejandro!

    It's my pleasure! I was not clear on the exact way to build for Thingy:91 in my previous comment. See the edit for updated info!

    When the Thingy:91 Asset Tracker receives data from a subscription it will get the event CLOUD_EVT_DATA_RECEIVED in the cloud_event_handler in main.c. As the data is in JSON format it should be decoded using the cJSON library. You can see how this is handled in the cloud_decode_command(...) which is called in case of the aforementioned event. 

    For simple prototyping I recommend that you do a check in main.c on the resulting root object from cJSON_Parse(...) to see if the contents match your desired command and then just do the GPIO operation there. However, you should ultimately study how commands from the cloud are handled in the cloud_codec module and try to implement your functionality in that manner.

    As for GPIO you can take a look at this implementation using the onboard NMOS transistors. Here is also a thread on the available GPIOs.

    Good luck and do tell if you need any more help!

    Best regards,
    Carl Richard

Reply
  • Hi again, Alejandro!

    It's my pleasure! I was not clear on the exact way to build for Thingy:91 in my previous comment. See the edit for updated info!

    When the Thingy:91 Asset Tracker receives data from a subscription it will get the event CLOUD_EVT_DATA_RECEIVED in the cloud_event_handler in main.c. As the data is in JSON format it should be decoded using the cJSON library. You can see how this is handled in the cloud_decode_command(...) which is called in case of the aforementioned event. 

    For simple prototyping I recommend that you do a check in main.c on the resulting root object from cJSON_Parse(...) to see if the contents match your desired command and then just do the GPIO operation there. However, you should ultimately study how commands from the cloud are handled in the cloud_codec module and try to implement your functionality in that manner.

    As for GPIO you can take a look at this implementation using the onboard NMOS transistors. Here is also a thread on the available GPIOs.

    Good luck and do tell if you need any more help!

    Best regards,
    Carl Richard

Children
Related