Space Vegetables ICON

 

Hi everyone ! Hope all are well and safe.

 

This is the weekly update for the Space Vegetables Project.

 

The Vegetables are growing well. The beans - i hope - don't grow any more in height, because they already are reaching into the top hydroponics layer.

I can already distinguish some plants from beans and lettuce. Others I'll need for them to grow a bit more .

 

SpaveVegetables Week 2H

 

According to what I can see, they are growing in good health. The beans roots are looking great.

Hydroponics beans roots

TDS sensor

 

Finally, the TDS sensor has arrived and I can finally start measuring the nutrients quantity in the water.

TDS sensor

 

My initial idea was to connect it to one of the analog inputs off the AutomationHAT mini, but I couldn't make the code work in Python. So, and to not add to much into an already fill system, I connected it to a Arduino Micro Pro and connect the Arduino to one of the USB ports of the RPi 4B - the one with the Enviro HAT. This way, I can power the Arduino, provide power to the sensor and read the TDS sensor values using serial communication.

This will be explained when I post about the Enviro HAT (the Client of Space Vegetables) .

TDS sensor USB Raspberry PI for Serial communication

 

PH sensor

Unlike the TDS sensor, the PH sensor cannot stay in water, so, I can't connect it to the Raspberry PIs. Still, It's already working with a TFT screen attached to it. I will print a case for it and post about it. A portable PH sensor.

 

PH sensor

 

Problems

 

I'm having (but I think it is solved) some problems with the Lights turning off. The Client does send the order for the lights to turn on, but never gets to send the order for the lights to turn off.

At first I tough that Python was having problems with the sleep function being to much - 36000 seconds - 10 hours - could be to much for it, but:

  • An error never gets thrown
  • The order for the lights to turn off is not sent before the time.

 

Next, I tough that the thread could just end without the time.sleep to finish.. But again, no error is thrown and the program just keeps working for all the other functions as expected.

So, to confirm (or not ) my suspicions, the threads in Python have some function to know how many threads are in execution.

I've implemented and scheduled a function to send to Telegram, every 30 minutes how many threads are executing and the names of them.

 

def checkActiveThreads():
    ac = threading.activeCount()
    log.info ("There are %s threads active", str(ac))
    sendMessageTelegram("There are " + str(ac) + " threads active")
    message = str(threading.enumerate())
    log.info(message)
    sendMessageTelegram (message)

 

Initially, this was the message of the function:

At 09:40, it should be 3 threads active:

  • Main function
  • Water Pump
  • Lights

 

But, 20 minutes later, this was the result:

What was expected ? The Water pump had stopped, like supposed, but the lights thread should be going and it just vanish...

I search in the code and saw nothing unusual. The lights thread was just like all the others (water pump and air pump) and those were working fine. Not for 10 hours, but 15 and 20 minutes... What could it be ?

I did try reducing the time to 1 hour, 30 minutes and still the same...

 

When testing, I had a function for the lights (the threads call the functions) that it would just sent the order to the AutomationHAT to just turn the lights. The control of the time was done on the server (AutomationHAT) - this was just for testing at the time.

I decided to make a test with it - next day, the thread would call that function, but, in the Automation HAT, instead of 10 hours, just 1 hour.

08:00 - thread to turn the lights on.

After a while, Telegram would send a notification of the threads.. The lights thread is in execution... WHAT ? It's working... But now, I don't need it, because it's the AutomationHAT that is controlling the time. 1 hour later, lights turn off...

Another go, but 5 hours now - half a day's light . It worked.. And the best was, the lights  thread was still active... Again, the code was just like the others, but this one didn't had the time.sleep.. Just calls the server function to turn the lights..

 

I decided to turn the time control of the lights to the EnviroPI (the client) and, instead of commenting this function, made a copy, and added the time.sleep code and then to turn the lights off.

It worked. Right now, it's the second day of testing and, the thread is still active (afterwards, i learned how to name the threads, so they now have names):

Telegram notifications

 

Don't know what it was, but, ghosts in the code.

 

 

 

Well, I leave here a new timelapse of the plants growing. This is since week 0.

Happy coding