So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Gdipstick
#73054 New questions....


1. I would also like to publish the RGB values, i've tried a few different commands to do this, but because this is the void loop, i'm receiving various errors i would be happy with publishing the whole void loop

void printRgbValues()

as one payload to the MQTTBox or more specifically just the RGB values line like in the serial monitor version

Serial.println("Mapped(r,g,b)=(" + String(rgbLed.redMappedValue) + "," + String(rgbLed.greenMappedValue) + "," + String(rgbLed.blueMappedValue) + ")");

what example commands could i use for either or both of these results?

2. I'd like to group all the variables outputs (the button counter, the 'on / off' message and the RGB values) to MQTTBox as one payload, is that possible?
User avatar
By Gdipstick
#73128 here are some more details, just one example of code i've tried, unsuccessfully :mrgreen:

// next 2 lines converts the push button counter to text then publishes same message to MQTTBox, works great thx schufti & gdsports!
itoa(buttonPushCounter,msg,10);
client.publish("OsoyooDataF",msg);
// Trying to do the same thing here, publish the RGB LED color values string to the MQTTBox
client.publish("OsoyooDataF", (String("r,g,b = " + String(rgbLed.redPin) + "," + String(rgbLed.greenPin) + "," + String(rgbLed.bluePin))));
// herein lies the error, trying to send the same message to the MQTTBox that is going to the serial monitor, next line
// Serial.println("r,g,b = " + String(rgbLed.redPin) + "," + String(rgbLed.greenPin) + "," + String(rgbLed.bluePin) );


Arduino: 1.8.2 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"

C:\Users\GADAWE\Documents\Arduino\node_ct_rgb_box\node_ct_rgb_box.ino: In function 'void loop()':

node_ct_rgb_box:138: error: no matching function for call to 'PubSubClient::publish(const char [12], String)'

client.publish("OsoyooDataF", (String("r,g,b = " + String(rgbLed.redPin) + "," + String(rgbLed.greenPin) + "," + String(rgbLed.bluePin))));

^

C:\Users\GADAWE\Documents\Arduino\node_ct_rgb_box\node_ct_rgb_box.ino:138:144: note: candidates are:

In file included from C:\Users\GADAWE\Documents\Arduino\node_ct_rgb_box\node_ct_rgb_box.ino:2:0:

C:\Program Files\arduino-1.8.2\libraries\pubsubclient\src/PubSubClient.h:130:12: note: boolean PubSubClient::publish(const char*, const char*)

boolean publish(const char* topic, const char* payload);

^

C:\Program Files\arduino-1.8.2\libraries\pubsubclient\src/PubSubClient.h:130:12: note: no known conversion for argument 2 from 'String' to 'const char*'

C:\Program Files\arduino-1.8.2\libraries\pubsubclient\src/PubSubClient.h:131:12: note: boolean PubSubClient::publish(const char*, const char*, boolean)

boolean publish(const char* topic, const char* payload, boolean retained);

^

C:\Program Files\arduino-1.8.2\libraries\pubsubclient\src/PubSubClient.h:131:12: note: candidate expects 3 arguments, 2 provided

C:\Program Files\arduino-1.8.2\libraries\pubsubclient\src/PubSubClient.h:132:12: note: boolean PubSubClient::publish(const char*, const uint8_t*, unsigned int)

boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);

^

C:\Program Files\arduino-1.8.2\libraries\pubsubclient\src/PubSubClient.h:132:12: note: candidate expects 3 arguments, 2 provided

C:\Program Files\arduino-1.8.2\libraries\pubsubclient\src/PubSubClient.h:133:12: note: boolean PubSubClient::publish(const char*, const uint8_t*, unsigned int, boolean)

boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);

^

C:\Program Files\arduino-1.8.2\libraries\pubsubclient\src/PubSubClient.h:133:12: note: candidate expects 4 arguments, 2 provided

exit status 1
no matching function for call to 'PubSubClient::publish(const char [12], String)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
User avatar
By schufti
#73150 if you would try to understand the error message, you would have found that
publish supports several variants in parameters

boolean PubSubClient::publish(const char*, const char*)
boolean PubSubClient::publish(const char*, const char*, boolean)
boolean PubSubClient::publish(const char*, const uint8_t*, unsigned int)
boolean PubSubClient::publish(const char*, const uint8_t*, unsigned int, boolean)

you are trying to use it like this
boolean PubSubClient::publish(const char*, String)
what is not supported.

So it is up to you to find adequate comments to convert your variable(s) to required format.
For one example you allready have been given the solution, just find the similarities.