I’m having a ridiculously trivial problem that’s driving me crazy. I have a lighting control system using esp32 and node red for multiple control points to permit graceful failure. The lights can be switched and dimmed from any web device connected to the local network as well as near the lights with touch sensors (TTP223B–the built-in sensors are too flaky), and a dpst switch that can bypass all the electronics and just apply 12vdc. I want to feed back the state of each light using MQQT when the touch sensors are being used (yeah, it’s a minor refinement, but this about learning too) so I publish the setting when the lights are switched or dimmed. For example, short tap the touch control to turn off the LED. and the local ESP32 sends an MQQT code like (“Fritz/mid/esp32/ledSW1”, 2,true, “0”) to the MQQT server which sends the code to the local ESP32 and turns the light off. Okay, that works fine, but of course, the state of the node-red switch doesn’t change to reflect the new state.
So I added a node-red MQQT IN node to receive the published command and flip the switch. That caused a runaway feedback loop that took some fiddling to fix, but unchecking “pass through msg if the payload matches new state” stopped the runaway feedback loop, and choosing “switch icon shows state of the input” made the switch work both directly and via MQQT commands.
By comparison, my problem controlling the dimmer seems trivial, but as much as I’ve searched I can’t make it work. In the MQQT statement, the payload value has to be text. Converting the text to a number for brightness control is really straightforward since I just copied Rui’s method: Brightness=payload.toInt(). I tried several approaches using itoa() but the compiler keeps gagging. I used itoa (Brightness , textPlease, 10) and get “invalid conversion from char to char”. Clearly I don’t know how to use this function and the samples I’ve found are unclear. Any help will be warmly received, and I’ll just keep trying in the meantime.
Hi Bill.
Just to be clear, you want to convert your brightness value into a string to send it via MQTT using the ESP32? So, you want to convert int to a string using Arduino IDE?
What’s the MQTT function you’re using to publish? Can you show me that part of your code?
Regards,
Sara
Yes, exactly. I’ve tried several ways to convert the integer value to a string and send it, but here’s one that doesn’t work.
if (pressLength_milliSeconds >= optionTwo_milliSeconds){
Serial.print(“long press”);
if (brightnessLed1<254){
brightnessLed1 = brightnessLed1+stepLed;
ledcWrite(ledChannel1, brightnessLed1);
mqttClient.publish("fritz/mid/espb/ledSW1", 2, true, String(brightnessLed1));
Serial.println(brightnessLed1);
Compiler error: No matching function call to AsyncMqttClient publish(const char[22}, int, bool,String)
Substituting a fake string value for brightnessLed, like "150" works fine.
Try something like this:
mqttClient.publish("fritz/mid/espb/ledSW1", 2, true, String(brightnessLed1).c_str());
Let me know if this works.
Regards,
Sara