Arduinos In The Grow Room: My Project

that's the love and hate relationship i have with windows; the inevitable reload-it-to-make-it-faster cycle.

VS Code is a good alternative for Arduino development too, if you haven't tried it out. VStudio is pretty awesome already, so I wouldn't blame you for sticking with that.
 
I'll have a look, you haven't steered me wrong yet :) I am pretty comfortable in Visual Studio though, so we'll see.

Yeah, my computer is much better now, I hardly have time for a toke when I change folders, he he
 
I've got a new problem...

I ended up re-installing Windows, and now everything I compile for the ESP just throws it into an endless loop crashing and rebooting :( I have a full backup, I could restore my environment, but I'm not in a rush, everything is running well, so I don't need to recompile anything for the live system. I'll figure it out, then I can get back to the Switch Module and my new contactor relay for the lights :)


After scouring my code for anything that would cause the constant wdt reboots, I finally decided to compare the current version of the MySql Connector library against the backup I did before re-installing. When I re-installed Windows, I also downloaded and re-installed everything else, since I didn't want to restore stuff, that risked slowing things down again. Anyhow, I noticed a difference in file size in some of the .cpp files.

AHA!!!

I backed up (renamed the folder) the new library I just installed, and then restored the version I was running before the re-install, and (knock on wood) so far, not a single reboot, but I've still got lots commented out. I'm sure this is the cause, once I confirm it, I can let the author know.

Onward!
 
Looks like a change was made 8 days ago. This is the only change listed. It looks like lines 39 and 40 were added. I have no idea how or why it has caused the problem, but I think I can rest easy knowing that this is definitely the cause.


1567288733087.png
 
That's it folks, the admins have removed my signature and told me to stop posting links to my blog even though in my opinion, it does not conflict with this site. Unfortunately, this means no more posts here, as I'm not going to completely duplicate every post.

Thanks for all your interest in my DIY threads, hope you were inspired...
 
One final post, as it concludes my investigation into the problems I had with the MySQL Connector.

September 5, 2019

Happy, happy, happy... It's working again!

I'm so happy right now!

I finally found, and fixed, the problem with reading the sensor configurations when doing a sensor scan. If you've been following along, I had to close the database after each query or I was getting strange results. Generally it would load the first of two parts for the first sensor, and then all the rest would fail. By closing the database after each query, it all worked like magic.

In my investigations, which have been going on for a week now, I once noticed that when I did the query for part 2 of the config (there are too many fields to do it in one query due to memory) it would come back with a row, but none of my fields, and when I printed out the field names, they were left over from the part 1 query. I chalked this up to some sort of memory issue, something I must have done wrong, but it could be anywhere...

So, I started over again, I took the code from my rewrite of the switch module, because it was working, and had all the basic infrastructure., I only had to add the sensor module specific code, which for the most part, I just cut and paste. Each time I would add a tiny bit of code, compile it, upload it, and test it. Everything was fine until I added the code to read part 1 of the sensor config, which it did, the first time, then failed after that....

That's when I discovered the problem...
Untitled.png

This sample query is not the one which caused the problem, this is just an example of a pretty standard sql query, and I've highlighted two lines I had intentionally removed from my query code when loading the sensor configuration. The do ... while loop loops through the resulting records from the query, however, like this query, I was only expecting a single record back so saw no reason to spend the extra time looping when there were no more records.

Once I added these two lines back into my queries (there were three altogether where I had removed them) I can remove the database close after each query, and everything is working again!

In retrospect, the fact I was seeing leftover field names from the previous query could have been a clue. I haven't looked at the library code enough to check, but it appears that a query returns at least one null row at the end of valid rows, the do while look ensures you have all the records.

By skipping the loop, and only grabbing the first record, somehow the next query first had to read the null row (with the field names from the first query) and this is what caused the problem? That's my working theory...

I'm going to leave it at that, I now know what I did wrong, every example for the library shows the do...while loop. I've gone back to my original rewrite code and fixed it, and I can move on, thankfully...

Because I don't have to close the database between queries, it runs much faster now too :)
 
Wow, it's been almost 2 1/2 months since I've updated things here... An awful lot has happened in that time. While I could never list all the changes here, and I'm not allowed to post links to my blog,I didn't want people to get the idea that I've given up, or stopped working on this project. I'm still plugging away full time, and having just as much fun as always.
 
Some pics to help with perspective... you can see the mess of the modules and sensor wires, eventually that will all get cleaned up, it IS still a prototype.
I got a real kick when I seen your wiring mess. You and I would get along great! I do the same, then clean it up once proven. This said, I intend on doing something similar based on the Arduino platform. I'd like to incorporate a solid state relay array to control lighting and have a PH and nutrient dosing station as well.
I really dig your work bro!
 
I got a real kick when I seen your wiring mess. You and I would get along great! I do the same, then clean it up once proven. This said, I intend on doing something similar based on the Arduino platform. I'd like to incorporate a solid state relay array to control lighting and have a PH and nutrient dosing station as well.
I really dig your work bro!

Thanks... I'm still working on this whole system, and nearly have the design for the Sensor Modules nailed down. I'm always thinking of new things to add, or better ways to do things. Hopefully I'll order some properly printed "shields" for them and mount them in nice enclosures soon, although I don't really consider that an important goal, just a nicety :)
 
I'd like to incorporate a solid state relay array to control lighting

I ended up going with a "contactor" which I found at my local grow shop. I had nbo idea what I was looking for so bought it there, since that's what it was used for... The arduino can use a 5v relay to trigger this big high current relay, and turn the light on and off, and I use LDRs (light detecting resistors) to make sure the lights are on or off as they are supposed to be.
 
So I've built this system to include features I'm not currently using, and may not use. This includes the automatic watering, which, living in an apartment building, just seems like asking for trouble. I've actually run it, for days at a time, watering empty buckets, sitting in large totes to catch any overflow etc, and while it seems bullet proof, I just can't bring myself to use it here, besides, with all the automation, that's about the only time I actually visit my plants :)

The Sensor Modules do monitor the soil moisture in the pots, and the system notifies me when to water individual plants. To do this, I've created software on the PC that lets me send Windows Notifications (those popups) and since I'm at my computer probably 75% of the time I'm awake, works great. Any of the modules can send these types of notifications. I recently created an Alarm Module as well, which will display the most serious notifications on a small LCD screen and buzz a piezo buzzer as well as flashing the LED RED/BLUE like a police light. This module currently sits on my desk, but I can easily hear it when I'm watching TV, or pretty well anywhere in the apartment.

I finally incorporated the high current relay and created a Light Controller Module for switching my HID lights on and off. I have a module called the Switch Module which I was going to use to control lights as well, but decided to make it a separate module since it's timing is important and don't want some other task interfering. The Switch Module can turn on/off fans, heaters, small lights, humidifiers, dehumidifiers, etc. The switching can be based on the time, or readings from any of the sensors on the system, such as temperature, humidity, light detection unit, etc. The Switch Module also controls my "Misting" bottle which uses a servo mounted on the top to squeeze the trigger and send a spray of mist over my clones. That's another feature I'm not currently using since I'd getting fantastic results using my "Aqua Cloner" DWC system.

There are a ton of other features for the grow room, but also lots of just cool nifty arduino tricks and custom development tools. I guess this is three years now, and I have nothing else to do, so I've spent a LOT of time working on it.

I suppose I need to update my feature list, just naming off all the modules doesn't do the system any justice, each module is jam packed with additional features and redundancy to ensure a bullet proof system. For example, the Light Controller Module is primarily responsible for turning a light on and off, it also includes hot start protection, and will delay turning the light on for a predetermined amount of time if the light was on, and just turned off. Most ballasts will protect against this, but I wanted it as a safety feature. It also uses a Light Detection Resistor to check to ensure the light is on or off as it is supposed to be, and send an alarm if it is not correct. Another Module is responsible for, among other things, checking to make sure all the other modules are running. If one crashes, I get notified. All notifications and alarms are customizable. The entire system is completely customizable.

Now if only I could create a module that kills thrips! :)
 
One of the newest modules I came up with is to replace the mechanical timer for my 600W HPS light in the flower tent. I was working away the other night when I noticed on my "Grow Room Overview" web page that the light was not on like it should have been. I have a sensor that detects the light level.

My new Light Module has been sitting on my workbench, running, flawlessly, for about a month, so I swapped it in for the defective mechanical timer switch. The module consists of a Arduino Mega 2560/ESP8266, a 5vdc relay, which switches a high current, 110vac Contactor (high current relay). There are power supplies, Realtime Clock, etc as well as a buzzer, and a light sensor.

This is good because I have a lot more control over the timing, and if power goes out, it doesn't throw off the schedule. The module also gives me full control over knowing when the light should be on, and detecting if it is not. I now get pop up warnings on my computer, as well as an audible and visible alarm on the Alarm Module if something isn't right.
 
A couple minor bugs, a few new ideas, and this module has been back on my workbench and I've just been switching the light on and off by hand for a few days now. I finally put the old mechanical timer back in, since it seems to be working fine now. This is temporary, because I plan on putting the Light Module back soon.

Anyhow, the more things I added, the more complicated it got. Mostly it had to do with the board I'm using, a Wemos Mega 2560 with on board ESP8266. The two talk to each other over a set of dedicated hardware Serial ports. The "modules" consist of two pieces of software, one running on the ESP8266, and another running on the Mega 2560. The ESP code accesses the WiFi network, the MySql Database, the Blynk Server, etc, while the Mega2560 has access to the pins (sensors, relays, switches, etc) and peripherals, such as the RTC, the Micro-SD Card module, etc.

The more gadgets, the more the two modules have to talk to each other. At some point, they start interrupting each other, and this communication breaks down. I send data back and forth in XML format, with CRC checking, very basic stuff, but also very effective, until it gets overloaded. I suppose I could fix that, but a much better solution presented itself. If my modules are so complex that it overwhelms the serial communications, then a simpler solution is needed...

It turned out that rewriting the code was easier than trying to figure out why the old code stopped working, it really was poorly planned code, written on the fly, subject to constant changes... The new code is much more elegant, a LOT fewer lines of code, and uses a lot less memory.
 
Still plugging away at it, haven't been updating since there doesn't seem to be any interest... Will do occasional updates just for the heck of it...
You got some interest here! We're about to take on a prototype room automation using the Arduino architecture. You've already paved the way on a lot of this. Expect some brain-pickin for me!
Dig this thread...
 
A couple minor bugs, a few new ideas, and this module has been back on my workbench and I've just been switching the light on and off by hand for a few days now. I finally put the old mechanical timer back in, since it seems to be working fine now. This is temporary, because I plan on putting the Light Module back soon.

Anyhow, the more things I added, the more complicated it got. Mostly it had to do with the board I'm using, a Wemos Mega 2560 with on board ESP8266. The two talk to each other over a set of dedicated hardware Serial ports. The "modules" consist of two pieces of software, one running on the ESP8266, and another running on the Mega 2560. The ESP code accesses the WiFi network, the MySql Database, the Blynk Server, etc, while the Mega2560 has access to the pins (sensors, relays, switches, etc) and peripherals, such as the RTC, the Micro-SD Card module, etc.

The more gadgets, the more the two modules have to talk to each other. At some point, they start interrupting each other, and this communication breaks down. I send data back and forth in XML format, with CRC checking, very basic stuff, but also very effective, until it gets overloaded. I suppose I could fix that, but a much better solution presented itself. If my modules are so complex that it overwhelms the serial communications, then a simpler solution is needed...

It turned out that rewriting the code was easier than trying to figure out why the old code stopped working, it really was poorly planned code, written on the fly, subject to constant changes... The new code is much more elegant, a LOT fewer lines of code, and uses a lot less memory.
I'm just starting to grasp a sketch, and had to deal with a serious "bounce" issue where the Arduino was pick iij ng up say 20 button pushes off one quick push. Kept jacking with the program and we kept trying to rewrite the code.
Once we were able to "see" what was happening on the computer screen, well, let's just say that when we learned about bounce.
Just one of the many hiccups along the way.
Anyway, hats off to you my friend!
 
You got some interest here! We're about to take on a prototype room automation using the Arduino architecture. You've already paved the way on a lot of this. Expect some brain-pickin for me!
Dig this thread...

Thanks for your interest... While I'm not posting a lot here, I am still very actively working on this project. I guess it's my retirement project :) What I have is really a prototype, since I'm not even quite sure how to install it from scratch, it's just been built in place over the past couple years. As a prototype though, I think I've covered most of the bases, it does everything I need and want, and does it extremely well (so far!)

I'd be glad to respond to any questions about my design or implementation, as well as discuss any new ideas.
 
I'm just starting to grasp a sketch, and had to deal with a serious "bounce" issue where the Arduino was pick iij ng up say 20 button pushes off one quick push. Kept jacking with the program and we kept trying to rewrite the code.
Once we were able to "see" what was happening on the computer screen, well, let's just say that when we learned about bounce.
Just one of the many hiccups along the way.
Anyway, hats off to you my friend!

Remember, google is your friend :) I find myself googling the same things over and over, and also just searching my own code to see how I did things. My memory is pretty bad, I can write a chunk of code, and 20 minutes later, forget what I did :)
 
Back
Top Bottom