Hello, I am trying to understand the publish/subscribe system through BM nodes. Currently, I just want to send the on board temperature and power data that i receive from one Dev Kit to another Dev Kit.
I have found the source code for the bm_pub function, but I am having trouble implementing it and getting it compiled. I have added the following lines of code to the main loop within the hello_world_guide_5 app from the Dev Kit guides:
void setup(void) {
/* USER ONE-TIME SETUP CODE GOES HERE */
Welcome @ggrinn1! Youâve got the right idea; your code is mostly correct. There are some small changes required though.
One issue I see is that you need to move the initial declaration of the topic and temperaturetopictype constants out of the setup function so that code inside the loop function can access them.
Also the data â the second argument to bm_pub â needs to be a pointer. You can see this in the source code for bm_pub because there is a * before the data argument. One simple change to your code that achieves this is to prepend & to the temperature variable, so that you pass the address of the temperature variable instead of the temperature value.
For a more detailed payload than a simple number, youâll want to encode your data into some byte buffer and pass a pointer to the buffer. Iâm looking for an example in the source code that I could point you to, but theyâre all overly complicated. Iâll add to my task list to post a simplified example this week.
Let us know if that helps, and donât hesitate to ask more questions.
Thank you so much! The publish app successfully built and now I am onto the subscribe portion. I am following the same approach and using the hello_world_guide_5 app for the receiving Dev Kitâs âsubscribeâ source code. I have the following:
error: expected primary-expression before âcallback_functionâ
35 | bm_sub(topic, bm_cb_t callback_function);
I looked on the internet and I am thinking this is because of the bm_cb_t signature, but I could be wrong. Also, I am not too sure how to handle the data, but I am assuming it comes out of the second argument of bm_sub and I can process it in the callback_function.
The call to bm_sub needs to run only once, so it should be in setup, not in loop. This call basically says, âWhen a message arrives in the future with the given topic, please pass it to the given callback.â
The callback function needs a particular signature, defined in bm_pubsub.h here:
Itâs a little complicated looking, but basically your callback function needs to accept 7 arguments. You can copy the exact contents of the argument list from that header file, like this: