• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Node Red Feedback Loop

Q&A Forum › Category: ESP32 › Node Red Feedback Loop
0 Vote Up Vote Down
bill1 asked 5 years ago

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.

Question Tags: Node-Red
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

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

0 Vote Up Vote Down
bill1 answered 5 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Try something like this:

mqttClient.publish("fritz/mid/espb/ledSW1", 2, true, String(brightnessLed1).c_str());

Let me know if this works.
Regards,
Sara

0 Vote Up Vote Down
bill1 answered 5 years ago

It does indeed, thank you so much.

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Great!
I’ll mark this issue as resolved.
If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.