Thanks; so what you're saying is that I would need to edit the Adafruit MQTT library where the .publish function is defined, as it allows only passing of normal variables but not struct members?
Lagom:
Thanks; so what you're saying is that I would need to edit the Adafruit MQTT library where the .publish function is defined, as it allows only passing of normal variables but not struct members?
No, the library has overloaded functions. That means the function itself is there multiple times but they differ in the argument types. You need to tell the compiler which one you need, by making the argument inside the function call mach exactly one of the functions available. The fact that your byte comes from a struct should not matter. Only the byte is given to the function.
I do not have a test project and usually use a different MQTT library, so I could not test it. The Adafruit_MQTT.h file contains the following class
class Adafruit_MQTT_Publish {
public:
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const char *feed, uint8_t qos = 0);
bool publish(const char *s);
bool publish(double f, uint8_t precision=2); // Precision controls the minimum number of digits after decimal.
// This might be ignored and a higher precision value sent.
bool publish(int32_t i);
bool publish(uint32_t i);
bool publish(uint8_t *b, uint16_t bLen);
private:
Adafruit_MQTT *mqtt;
const char *topic;
uint8_t qos;
};
So it looks like there is no byte version and the compiler needs to cast the variable to a different type, but does not know which one you want to use. It knows that int32_t and uint32_t both could fit a byte and even the double. Try placing a cast operator inside the function call.
someinstance.publish( (int32_t) nodeTX.nothing );
If this does not work and you need some more help. A short test program and a note which libraries you are using would help. Otherwise I will need to figure out how the library works and what needs to be initialized instead of looking into this specific issue.
I'm using the Adafruit MQTT library. Going through various variable types, I realised that
void loop()
{
MQTT_connect();
// bool x = true; // = call of overloaded 'publish(bool&)' is ambiguous
// byte x = 255; // = call of overloaded 'publish(byte&)' is ambiguous
// int x = -32768; // = call of overloaded 'publish(int&)' is ambiguous
// long x = -2147483648; // okay
// float x = 21.43; // okay
// uint8_t x = 255; // = call of overloaded 'publish(uint8_t&)' is ambiguous
// int16_t x = -32768; // = call of overloaded 'publish(int16_t&)' is ambiguous
// uint32_t x = 4294967295; // okay
sometopic.publish(x);
delay(5000);
}
but also using one of the three accepted data types (instead of bool, byte and int) when publishing a struct member results in that error
I took your suggestion to explicitly cast struct members into an accepted data type in the .publish function, no matter which data type was used in the first place, and that does work.