Page 4 of 4

Re: plant watering

Posted: Sun Dec 15, 2019 6:01 pm
by johnv
so its working!

didnt need the relay after all, the 2n7000 did the trick!

btw cant upload the mp4 video :(

Re: plant watering

Posted: Fri Dec 27, 2019 1:59 pm
by johnv
hi, for reading the values and future stuff and controlling, maybe using an app, what is the better way to do it,

learn about mqtt, or a websocket or try building a server???

i'm kinda lost on this subject,

i think there is to much info on this subject,

i end up installing node red on the raspberry, but i would like to learn micropython, so block coding is cool to see things work but not the way i want to go,

also home assistant is a bit overkill, using yaml and implimantations of all kinds,

i like to keep it to python, so i can learn more,

so i would be gratefull, to any help offcourse ;)

i really like to know where to start with this,

kind regards, john!

Re: plant watering

Posted: Tue Jan 07, 2020 9:23 pm
by safetyfactorman
I'm not sure what your requirements are, but you may find the opensprinkler project of interest.

https://opensprinkler.com/product/opensprinkler-pi/

The software has a c/c++ verson and a python version. I am trying to learn the python version, so I can hack it.

https://rayshobby.net/mediawiki/index.p ... Background

The developers sell a card that plugs into the gpio bus on the raspberry pi. It is also possible to have remote stations. The software could be expanded to become a kinda garden scada, using remote embedded micropython devices.

Re: plant watering

Posted: Thu Feb 13, 2020 7:22 pm
by johnv

Code: Select all

import machine
from machine import Pin
from machine import ADC
import time
from time import sleep

moisture = ADC(0)        #declare soil sensor
pump = Pin(4, Pin.OUT)    #declare pin 4 as output, naming it pump
dry_value = 600                #declare dry_value as 600

while True:                                       #create infinit loop till somthing breaks the true statement
    moisture_value = moisture.read()    #when there are readings from the soil sensor put them in 'moisture_value'
    print(moisture_value)                      #show readings from soil sensor
    sleep(3)                                          #wait for ... seconds
    
    if (moisture_value < dry_value):      #when readings from soil sensor is smaller than 600 then ...
        pump.on()                                  #pin 4 high
        print(pump.value())                      #shows pin state 1 (high)
        sleep(10)                                      #wait ... seconds
        pump.off()                                     #pin 4 (0)low
        sleep(10)                                        #wait 10 seconds
    

hi i'm still struggeling, to grasp how i'm supposed to put the data in to mqtt

do i use the " print(moisture_value)" into the publish topic?

Re: plant watering

Posted: Fri Feb 14, 2020 5:48 pm
by pythoncoder
See the official examples such as this one. You will need to convert moisture_value to a bytes instance to publish it, so after connecting to your broker your publication code will look something like

Code: Select all

c.publish(b'moisture', str(moisture).encode())

Re: plant watering

Posted: Sat Feb 15, 2020 6:44 pm
by johnv
i apreciate your help, sir! have a great weekend!