Hi,
I'm using the r41Z module based on NXP KW41 ble module.
I able to run the demo without issue with Android Application IoT Toolbox :smileyhappy: .
I also succed in added my two driver sensors to my code in the main, and print in debug mode my data into the console.
Now is the time to send my sensors data via ble, and i have to admit that, after few days reverse engineering the code, i'm a bit lost. I have difficulties to find in which file i have to implement my code. I understood i have to add services in .h etc...
My application has this simple behavior:
1)Sleep ( consume few uA to save max battrie)
2)Wake up periodically, advertise....
- if no body interested, go back to sleep for one minute.
- if a central is present, establish connexion, read sensors , send data each 1 second
3) If central is not responding anymore,Go back to 1)
Example seems to work a lot with callback functions and Timer function ( like LED bliking management for example).
There is so much files in the projects i'm a bit lost. I search in all the documentation without to find real developpement info but more example user info.
Doc i used were here : mcuxpresso\01\SDKPackages\SDK_2.2.0_FRDM-KW41Z\docs
The product is really perfect, i really would like to be able to manage it the proper way.
Q1) Is there a document that would explain the framework, which file to works with please and integrate sleep mode , reading of my sensors, periodical wake up ...?
Q2) i'm using the internal regulator to supply my two sensors, is it possible to switch on/off when we want to save batterie when module sleep for example ?
Thanks a lot for your help :smileyhappy:
Florian
Hi,
After using a work around for sprintf into Timer callback function, i implemented my second sensor.
In the same spirit, i allocate a second timer with timer manager Low Power Oscillator.
I jump well in the callback function.
But once again , as my fonction make a lot of float computation with square root etc ... and in for loop 64 times... the program brake and jump in void HardFault_Handler(void) .
I would like to know the real source issue. When i use the same piece of code in the main loop i have no issue.
A solution seems to just raise a flag in interupt, test flag in main loop, and clear it once code executed , but i wonder if i will not be interupted by another vector when i'm notifiying over ble in main function for example ...
So question is: What is the root cause of crahsing when exectue too big/too long code in interupt ( ram leakeage, watchdog ...) and how would you manage this case please?
Thank you :smileyhappy:
I'm studying the architecture of the code that use OSA Queue and message, may be idea is to put a message into queue manage in the main and raise an event via OSASentEvent. Is it the good practice according to you ?
Hello,
1) I debbuged a bit this morning , and i realize the error is pointing to a sprintf ( when i fill the buffer). I don't understand because this line works fine in a C compiler:
sprintf(mySensorServiceConfig.pressure,"%06.3f",sensor.pressure);
With sensor.pressure is a float.
Purpose of this sprintf is to update the 6 digit in gatt_db with a fixed format: xx.yyy means 6 char. My pressure is a char of 7 element to content the null ( end of string char).
2) Also i have seen in the hrs example that there is some caracteristique with string :
Dis_SetManufacturerName(pServiceConfig->serviceHandle, pServiceConfig->manufacturerName);
where :
/*! Device Info - Configuration */
typedef struct disConfig_tag
{
uint16_t serviceHandle;
utf8s_t manufacturerName;
utf8s_t modelNumber;
utf8s_t serialNumber;
utf8s_t hwRevision;
utf8s_t fwRevision;
utf8s_t swRevision;
systemId_t* pSystemId;
regCertDataList_t rcdl;
pnpId_t* pPnpId;
} disConfig_t;
And to update the caracteristique value :
/* Update characteristic value*/
return GattDb_WriteAttribute(handle, manufacturerName.stringLength, (void*)manufacturerName.pUtf8s);
And finally here is the structure of utf8s_t:
typedef struct utf8s_tag
{
uint16_t stringLength;
char *pUtf8s;
}utf8s_t;
We see that it is just a pointer on a char. The probleme is that this code is not used in this example, and this string is never field in, so i can not garanti it works.
According to you, should i use this way of working for string ? Or may first method whith char pressure[7] should work ?
Thanks a lot for your help :smileyhappy:
Hello,
Maybe if you are more familiar with the first method you could use it and I believe it should work. If you have issues while doing so, let me know.
Regards ,
Estephania
Thank you very much,
I confirm that issue cpome from the fact to update the table via the sprintf. If i comment it , i have no more issue.
The strange point is that the sprintf works fine in fact , the value is correctly with the format xx.yyy+null. The code continue to execute, the function to write in database even works, the crash seems to happen when i let run again .
I try to remove the static keyword in front of the declaration of without success:
static sensorConfig_t sensorServiceConfig = { service_tpms,0x11223344,0,1,2,3,4,5,6,0,0,0};
Do you have an example were you pass just a table and not only a single int with the classic format [] ?
Thank you
I have also to mention that the first time i start the service, the function is exectuted without crashing.
As this sprintf is called in the static void SensorMeasurementTimerCallback(void * pParam), i wonder if it not a problem of ram overflow may be or something related with timeout cause it take too much time in the function... I don't know yet. May be sprintf funciton with float etc isnot optimized in term of memory and the fact to execute it in a call back method that comes from interrupt cause issue.
Thanks a lot estephania_martinez , i didnt'come on the forum since i posted it ( forgot to subscribe notifications in case of repply , sorry for that... ) . In between, i made progress and i found the documentation you mentionned.
I have started to implement my own service. I can see it now on my smartphone.
So now, i would like to modificate my variable and send it periodically with notification like hrs does. i took inspiration of batterie service and the tutorial you refer to.
But i have still one issue, i'm not able to return a success on
GattDb_FindCharValueHandleInService
:
bleResult_t Ps_RecordPotentiometerMeasurement (uint16_t serviceHandle, uint8_t newPotentiometerValue)
{
uint16_t handle;
bleResult_t result;
/* Get handle of Potentiometer characteristic */
result = GattDb_FindCharValueHandleInService(serviceHandle,
gBleUuidType128_c, (bleUuid_t*)&potentiometerCharacteristicUuid128, &handle);
It comes from the fact that :
potentiometerCharacteristicUuid128
is not declared. So i found a work around, not really clean cause not done in your example, by adding #include "gatt_db_handles.h" in my_service.c. With that i can at least build . Value in uuid .uuid128[16] seems to be properly filled in ( even if i have a doubt on big or little indian).
In the tutorial, this value is described nowhere too. In my example i'm using the uuid of the service ( and not uuid of my characteristic).
I correctly start the service , proof is that i can see it on my smartphone. So problem seems to come from the function, or uuid declaration , or wrong uuid used.
Do you have may be an idea please ?
Thank you very much
Hello,
Sorry for the delay, did you check this other one as well?
Modify and read characteristics with read and write requests
I believe it might help you as well and will clarify maybe some other details.
Regards,
Estephania
Thanks Estephania,
I succeed to get my integer on my android application by notifiacation.
Now i would like to send a second caracteristique in the same service. I t works fine in integer, but i would like to send a char buffer. Software goes in Harware seg fault . I guess it is linked to the pointer given in argument. Do you have an exemple that send in database string or a buffer of seral values please ?
Here is my sensor config:
/*! Sensor Service - Configuration */
typedef struct sensorConfig_tag
{
uint16_t serviceHandle;
uint32_t deviceID;
char pressure[7]; //here is my string value of 7 elements
float voltage;
int temperature;
uint8_t crc;
} sensorConfig_t;
Hello,
Are you sure you are not making any overflow? Is the issue cause before you send it?
Regards,
Estephania
Hello,
There is some documentation that can be helpful for you
How to create a Custom Profile - Client
How to create a Custom Profile-Server
And from the SDK you can check the BLE Application Developer's Guide.
About the saving [ppower, which sleep mode are you using? The same as the HRS?
Regards,
Estephania