# Using AMPL with Node red

**URL:** <https://discourse.nodered.org/t/using-ampl-with-node-red/9602>\
**Category:** General\
**Created:** [30 March 2019 08:48 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602 "2019-03-30T08:48:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)\
**Post date:** [30 March 2019 08:48 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/1 "2019-03-30T08:48:36Z")

</div>

Hello, it might be an unusual question but here it is:  
I'm working on a smart irrigation system with NodeMCU and Node red using MQTT protocol, and I'm using dht22 and soil moisture sensors to collect data evey 30 s.  
Now I want to add a combinatorial optimization ( to have the exact amount of water needed by the plant) using AMPL A Mathematical Programming Language, I want to use the sensors' data like temperature, soil moisture.. and use them in the calculation of AMPL every 30 seconds, and then use the decision of how much water should I use (how long should I turn on the water pump).  
If anyone have an idea if that is possible or how to do it, please enlighten because I'm lost.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 March 2019 09:36 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/2 "2019-03-30T09:36:26Z")

</div>

Are you able to write an AMPL script that does the calculations you want? If so then you could call that every 30 seconds using an exec node, to get the required time.

---

<div class="post-metadata">

**Author:** ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)\
**Post date:** [30 March 2019 09:42 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/3 "2019-03-30T09:42:00Z")

</div>

Is it possible to run a file with it ? I mean when I use the IDE I type: ampl: include exemple1.run, could the exec node do a similiar thing (This is the first time I hear about it sorry)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 March 2019 09:56 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/4 "2019-03-30T09:56:07Z")

</div>

I don't know anything about the IDE, but presumably somehow you can write a script that you can call to do that from the command line. Find out how to run it from the command line and then you put that in an exec node.  
Are the calculations so complex that you cannot convert them easily to javascript? Then you just put that in a Function node and trigger it every 30 seconds.

---

<div class="post-metadata">

**Author:** ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)\
**Post date:** [30 March 2019 10:05 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/6 "2019-03-30T10:05:58Z")

</div>

I didn't think about that actually, but It is a solution of a non linear equation problem using dynamic programming. so I think it is complicated 😕

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 March 2019 10:09 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/7 "2019-03-30T10:09:43Z")

</div>

OK, well you just need to find out how to call it from the command line rather than within the IDE. I will be astonished if that is not possible.

---

<div class="post-metadata">

**Author:** ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)\
**Post date:** [30 March 2019 10:10 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/8 "2019-03-30T10:10:36Z")

</div>

Okay I'll try to, Thank you very much! 😃

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 March 2019 10:13 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/9 "2019-03-30T10:13:27Z")

</div>

By the way, others here have solved the irrigation problem by using PID control of the water injection to control soil moisture content.

Also I think the DHT22 is considered a poor sensor, by some at least. See

> [@DHTT22 zero values](https://discourse.nodered.org/t/dhtt22-zero-values/7465):
>
> Have been using node-red-contrib-dht-sensor with DHT22 sensor showing zero values in temperature and humidity : (object \_msgid: "2bea0790.4d4168" topic: "rpi-dht22" payload: "0.00" humidity: "0.00" isValid: false errors: 4 sensorid: "dht22" }. Anyone has any idea what went wrong? I'm using the Physical Pin Rev.2 with pin 15. All other grounded + power(3.3) are placed correctly. Much Appreciated

---

<div class="post-metadata">

**Author:** ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)\
**Post date:** [30 March 2019 10:16 UTC](https://discourse.nodered.org/t/using-ampl-with-node-red/9602/10 "2019-03-30T10:16:05Z")

</div>

It seems like what I want to do, I'll check it out, Thanks!
