• 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

Quering MySQL to feed a feild

Q&A Forum › Quering MySQL to feed a feild
0 Vote Up Vote Down
Sylvain Hamel asked 9 years ago
4 Answers
0 Vote Up Vote Down
Sylvain Hamel answered 9 years ago

I placed 2 DHT sensors in my house, one in the bath room, the otherone in the living room. Whenever the one in the bath room gets more then 10% higher in humidity then the one in the living room,  I want to start the fan.
DHT sensors are connected to ESP8266-12 that feed an MQTT topic on my Pi. Node-Red puts the value into a MySQL data base. I now have a table with sensor’s humidity values updated and an other table where I could put a value according to the condition of 10% higher.
How can I make a request that would put a “on” or “off” value in the second table according to the condition ?
THX

0 Vote Up Vote Down
Rui Santos Staff answered 9 years ago

Does that DHT readings values are time stamped?
You can create a function with Node-RED that is triggered every X number of seconds that opens your database and compares the values, if the value is higher it triggers the MQTT topic that sends the on or off command.

0 Vote Up Vote Down
Sylvain Hamel answered 9 years ago

When they get into the MQTT file, they are time stemped and into the data base they are also.
What would look like that function ?
There is the flow to put the valu into the database
[{“id”:”ca77ca65.961bf8″,”type”:”mqtt in”,”z”:”1faf2c1f.1ed2d4″,”name”:””,”topic”:”Maison/SS/Humidite”,”qos”:”1″,”broker”:”a42b5e0c.745e8″,”x”:110,”y”:60,”wires”:[[“8899b529.010888”]]},{“id”:”8899b529.010888″,”type”:”function”,”z”:”1faf2c1f.1ed2d4″,”name”:”Maison/SS/Humidite”,”func”:”msg.topic = \”REPLACE INTO Capteurs VALUES (‘1’, ‘Maison/SS/Humidite’,’\” + msg.payload + \”‘,now());\”;\nreturn msg;”,”outputs”:1,”noerr”:0,”x”:400,”y”:60,”wires”:[[“856ef26c.95f8f”]]},{“id”:”6055c210.ce4f7c”,”type”:”mqtt in”,”z”:”1faf2c1f.1ed2d4″,”name”:””,”topic”:”Maison/RC/Salle_Bain/Hum”,”qos”:”1″,”broker”:”a42b5e0c.745e8″,”x”:140,”y”:240,”wires”:[[“7d997ae2.95cfe4”]]},{“id”:”7d997ae2.95cfe4″,”type”:”function”,”z”:”1faf2c1f.1ed2d4″,”name”:”Maison/RC/Salle_Bain/Hum”,”func”:”msg.topic = \”REPLACE INTO Capteurs VALUES (‘4’, ‘Maison/RC/Salle_Bain/Hum’,’\” + msg.payload + \”‘,now());\”;\nreturn msg;”,”outputs”:1,”noerr”:0,”x”:420,”y”:240,”wires”:[[“856ef26c.95f8f”]]},{“id”:”856ef26c.95f8f”,”type”:”mysql”,”z”:”1faf2c1f.1ed2d4″,”mydb”:”948bddb2.bfe6b”,”name”:”DomotiquePi”,”x”:710,”y”:140,”wires”:[[“7579428.e533abc”]]},{“id”:”a42b5e0c.745e8″,”type”:”mqtt-broker”,”z”:”1faf2c1f.1ed2d4″,”broker”:”DomotiquePi”,”port”:”1883″,”clientid”:””,”usetls”:false,”compatmode”:true,”keepalive”:”60″,”cleansession”:true,”willTopic”:””,”willQos”:”0″,”willPayload”:””,”birthTopic”:””,”birthQos”:”0″,”birthPayload”:””},{“id”:”948bddb2.bfe6b”,”type”:”MySQLdatabase”,”z”:”1faf2c1f.1ed2d4″,”host”:”127.0.0.1″,”port”:”3306″,”db”:”MQTT”,”tz”:”cdt”}]
THX

0 Vote Up Vote Down
Rui Santos Staff answered 9 years ago

You basically need to set a timer that is triggered every X amount of seconds that calls a node that establishes a connection with your database and retrieves both values.
Then you simply compare the two values, based on that result you either send the on or off command…

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.