OS Device API to get the product id and product version

I am finalizing a presentation of particle cloud/OTA framework for my company.
I have made designed a simple demo hardware (nothing fancy : an oled screen & a SR104 sonar) with associated software.
Obviously automatic OTA of all devices running a product is a key feature I will demonstrate.
So for demonstration purpose, the oled screen is supposed to display the product id as well as the product version.
My question is simple
PRODUCT_ID(x) and PRODUCT_VERSION(y) allow to define it but is there a system C/C++ API to fetch the current version ?

Obviously, I can design something like:

  1. a small include MyProductInfo.h as
    #define MY_PRODUCT_ID 111
    #define MY_PRODUCT_VERSION 12
  2. make a call at the right place like
    #include “MyProductInfo.h”
  3. in other places, where I need it
    #include “MyProductInfo.h”

but It means I would have to include it EVERYWHERE I plan to use the info. Not very satisfactory to me.
I like the idea : 2 lines of code to set it in a unique place, then available everywhere via a system call.

Any idea ?

Alain Charroux

@Acharroux Welcome to the Particle Community.

I have 8 products and they are all sharing the same code base. In each product firmware page on the console there will be different builds (version of the binary) of the application code for that specific product. The conditional compile for each product is managed through the use of #define statements for the product e.g. #define PRODUCT1 true and #if PRODUCT1 and #endif around product specific code. In that block at the top of the application .ino are #if PRODUCT1 #elif PRODUCT2 that contain statements to declare the PRODUCT_ID() and PRODUCT_VERSION(). So options 1. and 2. in your design approaches. I don’t put them in separate header file. Clearly when the code is changed the version number needs to be manually updated and aligned to the change log. You will be aware that there is a new “Intelligent OTA” update process for production plans. I would suggest you look at threads that discuss the processes around OTA control if you haven’t already done so. The application must only accept OTA flashes when it can safely do so.

You can use the undocumented variables:

uint16_t __system_product_id;
uint16_t __system_product_version;

The values of these global variables are set by the PRODUCT_ID and PRODUCT_VERSION macros. You should just be able to access them with no additional header files, but if not just declare them extern, as in:

extern uint16_t __system_product_version;

I use this technique to publish my product firmware version in my JSON publish data:

jw.insertKeyValue("ver", __system_product_version);
1 Like