NimBLE-Arduino icon indicating copy to clipboard operation
NimBLE-Arduino copied to clipboard

compilation error "operator '&&' has no right operand" and "#if with no expression"

Open pabloandresm opened this issue 6 months ago • 5 comments

Since version 2.3.1 I am receiving both errors described in the title multiple times. In my project I have "CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y" and "CONFIG_BT_NIMBLE_ROLE_BROADCASTER=n"

The nimconfig.h does this: / Cannot use server without advertise / #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) && !defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) #define CONFIG_BT_NIMBLE_ROLE_BROADCASTER #endif

And in several parts of the code (like NimBLEAdvertisementData.cpp) you have things like this: #if (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(DOXYGEN) ... #endif

...and the error appears in the second && complaining about CONFIG_BT_NIMBLE_ROLE_BROADCASTER with "operator '&&' has no right operand"

There are 2 possible solutions here:

  1. or either you do "#define CONFIG_BT_NIMBLE_ROLE_BROADCASTER 1" instead of "#define CONFIG_BT_NIMBLE_ROLE_BROADCASTER" in the nimconfig.h
  2. or either you replace all appearances of "#if (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(DOXYGEN)" by using "defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER )" instead of plain "CONFIG_BT_NIMBLE_ROLE_BROADCASTER"

pabloandresm avatar Jun 11 '25 20:06 pabloandresm

Are you using esp-idf? If so please use https://github.com/h2zero/esp-nimble-cpp instead of this repo.

h2zero avatar Jun 11 '25 20:06 h2zero

I am using esp-idf v5.4.1 Included in my project's idf_component.yml a line "h2zero/esp-nimble-cpp: ^2.3.1" under "dependencies:" I am not using ArduinoIDE. I am not using PlatformIO. This issue is not present if I use version 2.3.0 of nimble.

pabloandresm avatar Jun 11 '25 20:06 pabloandresm

Okay, I see now, this issue belongs in esp-nimble-cpp and I will fix it there now. The problem is that these were supposed to be removed but got missed:

/* Cannot use client without scan */
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) && !defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
#define CONFIG_BT_NIMBLE_ROLE_OBSERVER
#endif

/* Cannot use server without advertise */
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) && !defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
#define CONFIG_BT_NIMBLE_ROLE_BROADCASTER
#endif

h2zero avatar Jun 11 '25 20:06 h2zero

Hello. But there is something I do not understand with your pull request https://github.com/h2zero/esp-nimble-cpp/pull/343

In that case, if I do CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y and CONFIG_BT_NIMBLE_ROLE_BROADCASTER=n, I cannot do NimBLEServer::startAdvertising(). How do I advertise if I only want to be PERIPHERAL and not BROADCASTER?

If I understand correctly, under BLE, the PERIPHERAL ROLE alone has to allow advertising and connection. And the BROADCASTER ROLE alone allows only advertising without connection.

So if I only use PERIPHERAL, how do I advertise? as the method ::startAdvertising() is gone?

pabloandresm avatar Jun 12 '25 14:06 pabloandresm

The reason to allow this is because you could be a central and a peripheral with no need to advertise. In your case you need to be able to advertise so you must enable the broadcaster role.

h2zero avatar Jun 12 '25 14:06 h2zero

Closing this as resolved.

h2zero avatar Sep 02 '25 20:09 h2zero