B4R Question When are libraries loaded? Inline C - #define

barx

Well-Known Member
Licensed User
Longtime User
In relation to this Post https://www.b4x.com/android/forum/threads/mqtt-connect-to-thingspeak.89453/#post-566216
More importantly, the process of editing the file to change the MQTT_MAX_PACKET_SIZE.
I have a little question (well, 2 actually).

When are libraries loaded?

In the file that I needed to edit, the item in subject is defined like this:

B4X:
// MQTT_MAX_PACKET_SIZE : Maximum packet size
#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 256
#endif

As you can see it only defines the variable if it isn't already defined. So, I'm thinking, maybe we could define this in b4r using inline C? Then when the lib is loaded it won't re-define it.

I believe this would be better because as it is, if I edit the file like I have, when I install a new version of b4r, the file be overwritten and my project will break again. Where as if it is defined in code within the project, it will always work.

Maybe if this can't work with b4r as it is, then a new solution could be implemented. Thinking maybe a special module that gets loaded before the libs?
 

barx

Well-Known Member
Licensed User
Longtime User
Good morning @Erel
The above solution doesn't seem to work.

Here is what I tried in order to cover all bases.
I ran my project before making any edits as I have changed some other bits last night so wanted to make sure my code was good - MQTT sent ok
I edited the file back to it's original state (setting to 128) and ran project to prove the issue- MQTT failed
I added the line above in the Main module head and ran project - MQTT failed
I edited the above line setting to 256 (you wrote 255) and ran project - MQTT failed
I commented out the line and edited the file again, setting to 256 - MQTT sent ok

This might seem a bit long winded but as I say I like to cover all bases and being an electrician it is drilled into us to 'Prove, test, Prove Again!'

I'm happy to try any other ideas
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Hi Barx, have you tried to encrease stackbuffersize. Maybe the buffer is allocated in stack...

Thanks for the reply @tigrot , yes I have already tried that thank you but it isn't related.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
It means that your only option for now is to change it in the library source.

No worries, thanks.

Maybe something worth looking at in a future release....
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…