offset \ˈȯf-ˌset\ noun

a force or influence that makes an opposing force ineffective or less effective

Drawing Setup

Temperature is dropping in the northern hemisphere again. With the looming energy crisis, some people worry about heating. It's not that dire, though. Ireland is not reliant on the rest of the EU's infrastructure and the temperature oscillations are mild, too. There are no reductions, but the costs are rising. The situation is such that people keep warning the politicians against allowing so many datacenters in Ireland because the infrastructure can't support it. There's a concern this might lead to potential black-outs.

Cuply project was written about so it's time for me to take a short break from it. Even though it's hard for me not to come back. I believe it not to be finished so I will keep revisiting it to make sure it works properly. The bad weather keeps me at bay. Winter is approaching and we aren't on the balcony anymore so no hardware bits are done at the moment, only what's on the desk in front of me. I'm thinking about having a PCB for it, but need to figure out how to approach it. With the winter, again, we're slowly going into hibernation as well, so most of the things we do will happen indoors.

It is high time for me to kick myself into drawing and painting again. I guess it was a hectic beginning of the year and I cannot catch a break. We traveled (and still travel) a lot which I'll mention in the recap. I can tell that with all the travel, it was difficult to carry out things I had planned out, like Cuply. We did minor fixes in the apartment and rearranged priorities. So many things to do, so little time.

To kick off the painting, I decided to write this article. I got to have enough time this year to do things in spite of the distractions. The following paragraphs will describe my drawing setup.

I do things at the standing desk that goes up twice a day for an hour and a half. I automated that with ESP32 board. I can say that more focus comes from sitting, but I can't afford sitting all the time. I am not getting any younger and seldom do exercise (aside from the wall climbing which seems to be getting more frequent). This is at least countering the sedentary way of living. On the desk there's one 24" DELL U2413 monitor on the monitor arm so I can move it around should I have to. There's the standard keybord-mouse combination and a set of speakers on the desk, but they are not that important for drawing. The monitor arm is important since I have more space to work with.

The traditional drawing happens with a set of pencils (usually on the dark side with B2 being the most common), blending stumps, regular and kneaded erasers, some technical pens for inking and a small sketchbook. Sometimes I go for a specialty charcoal pens, but they're not used often in my repertoire. I can always display references on the big screen and, when done, scan things in with the scanner system behind me (HP 4130 doing a vendor lock-in) which is enough for home use.

I also hope to start with traditional painting of minis and I'll have more to say on that topic once I actually get to it. I'd need to use a spray paint primer, which is impossible to do indoors, but for the brushwork, I'll pretty much spend most of the time at the same desk. The only difference being one silicone mat so the paint doesn't spill on the desk surface.

When doing things digitally, which is my preferred method, I use a small Wacom Cintiq graphics tablet. It has all the usual pen gestures, from tilt (which is invaluable to have) to pressure. I also have a bluetooth keyboard for hitting all the keyboard shortcuts from wherever it's comfortable. I use a combination of Corel Painter and Krita applications of which I had a guest article on a slicing Python plug-in on Krita's blog. There are also Lazy Nezumi Pro and PureRef to help me out with the workflow.

There's one more thing and that's the ImgRef browser extension that I had Vesna do. It helps immensely with finding reference images for the finished work. A multi-page search. I'll have to poke her to publish the code.

Cuply - Hydroponics Greenhouse Cabinet Powered by Django Channels and Arduino - Conclusion

I'm in the process of making a greenhouse out of a glass cabinet that sits on our balcony. Inside it, there's to be a plethora of sensors and actuators hooked up to Arduino Due microcontroller, which is in turn connected to an old Raspberry Pi. The software stack is Django with Channels in the back-end, and React with some D3 in the front-end. It was a project long time in development, and this series of articles will explore it from the inception to the latest product.

  1. Overview
  2. Hardware
  3. Back-end
  4. Front-end
  5. Conclusion ← You are here

The devil is in the details. Right now the system works, but as with all long-running projects, this one will need some time to see if it's viable. As of time of this writing, there are contacts loose and the relays are breaking down sometimes. I need to tighten up the contacts and stop using the breadboard which was a proof of concept anyway. Moving on from prototyping into a real product will mean that I need to sit down and start soldering on the connections. With all the #revengetravel happening, I was putting it off for quite some time.

Making Cuply pretty will mean that the mechanism will get enclosed in a proper box where I can only have the necessary connections sticking out. For power, communication and sensors. I will utilize 3D printer mentioned before for some of the stuff.

At the moment, Cuply code lives in the repository online, but I need to clean it up and write up some documentation. With all that has been happening this summer, it was hard to keep up. Things are flowing if nothing. Not overflowing :)


/media/images/cuply-water-flow.png

Cuply - Hydroponics Greenhouse Cabinet Powered by Django Channels and Arduino - Front-end

I'm in the process of making a greenhouse out of a glass cabinet that sits on our balcony. Inside it, there's to be a plethora of sensors and actuators hooked up to Arduino Due microcontroller, which is in turn connected to an old Raspberry Pi. The software stack is Django with Channels in the back-end, and React with some D3 in the front-end. It was a project long time in development, and this series of articles will explore it from the inception to the latest product.

  1. Overview
  2. Hardware
  3. Back-end
  4. Front-end ← You are here
  5. Conclusion

This summer I set out to work on Cuply so I containerized the thing and set up the Raspberry Pi to house the project. I destroyed one SD card in the process but it's still working with the old one. Just a bit too cramped for my liking. When setting up the hardware I did some soldering (for which I bought the soldering iron) for the relay contraption. I tested out the pumps, checked for leaks and sealed them with silicone glue. For the back-end part I wrote majority of tests and implemented the coverage for it. I still need to push the repo to the cloud. Stay put for that one.

It was time for me to move to the front-end, which this article is about. The progress has been slow, but the Cuply project is moving forward despite outside distractions. The front-end architecture is driven by React. The dashboard is using the Bootstrap CSS framework and there are some D3 graphs that display the state of sensors. D3 bits are heavily modified examples taken from Observable.

I don't have a user registration system in place at the moment so when setting the project up, a user needs to be created in the back-end with createsuperuser Django management command. It's not an issue to have a superuser here because the project is isolated in the local network and the user is the only one existing in the project. Parameters can also be changed with the enabled Django admin.

A microcontroller is also needed to be set up in the Django admin, but at this point I'm thinking about hardcoding it in the settings and getting rid of the database interaction since there's only one microcontroller present. To ease my trouble, I exported the fixtures of the user, profile, microcontroller and devices so I can recreate them at will with loaddata management command.

Containerizing it spins up two containers. One for queue for the websockets and the other one for the app itself. The latter exposes the Arduino from the host so the order of things when spinning it up matters. Plug in the Arduino in the electrical outlet, then plug it in the Raspberry. This is important because the Arduino requires its own power supply, otherwise it makes Raspberry unstable.

Front-end bit is completely isolated and communicates with the back-end via REST API, websockets and authorizes itself through JWT. It is built with create-react-app.

When turning on the interface in the browser for the first time, a modal with logging in is presented to the user and one user/password combination later, the rest of the interface is unlocked. The navigation consists of the standard buttons for the main page and for signing out, then the items that are:

  • Sensors
  • Actuators
  • Plants
  • Trends
  • Settings

The first three display and edit the state of the items in the cupboard. Trends deals with displaying the graph of the historical data of the sensors and Settings changes the user's API key for FloraCodex. Editing the specific item opens a modal with a form to be changed and submitted back on the server via REST API. The real time data is fed to the dashboard through the websocket.

Here are some screenshots:


/media/images/cuply-sensors.png
/media/images/cuply-actuators.png
/media/images/cuply-plants.png
/media/images/cuply-trends.png
/media/images/cuply-settings.png

Cuply - Hydroponics Greenhouse Cabinet Powered by Django Channels and Arduino - Back-end

I'm in the process of making a greenhouse out of a glass cabinet that sits on our balcony. Inside it, there's to be a plethora of sensors and actuators hooked up to Arduino Due microcontroller, which is in turn connected to an old Raspberry Pi. The software stack is Django with Channels in the back-end, and React with some D3 in the front-end. It was a project long time in development, and this series of articles will explore it from the inception to the latest product.

  1. Overview
  2. Hardware
  3. Back-end ← You are here
  4. Front-end
  5. Conclusion

Back-end architecture is driven by Python and Django. I am skilled with that stack so I wanted to make something with things I know how to work with. Because of the smaller footprint that the Raspberry Pi has, I had to reduce the number of active processes that would potentially consume the memory. What I ended up with is:

  • Redis server that serves as the support for the websockets
  • Django ASGI process that would deal with both, sockets and web traffic, but another thread is spawned to take care of the sensors and actuators, as explained further down
  • Docker daemon composing the application

The database is SQLite since it's only one user per cabinet. No need to have Postgres there. Originally I was thinking to go raw with Circus managing the processes (I wouldn't go with Supervisor because Circus is simpler and handles sockets as well), but this proved to be better encapsulated with Docker so I wrapped things in it instead.

When an ASGI process is created (because it has to handle websockets), an app gets initialized and there's a piece of code in apps.py that spawns another thread. I had to do it this way since that other thread houses an infinite loop that would block the execution of the normal server code. In that new thread, a loop manager is created and executed, which in turn has several functions called in an infinite loop. They are:

  1. updating the devices needed to be parsed if the device list is changed in any way
  2. updating the readings from the sensors
  3. running actuators depending on the readings from the sensors
  4. communicating the current state to the websocket
  5. saving the snapshot of the state for trend graphs

I had to have the Arduino blueprint sketch written in a C variant, but since I don't know C that well, what it does is sends the state to the USB and reacts to the input coming from the USB. This is done for the analog and digital sensors and actuators, for I2C and for communicating with the servo if attached. The idea is that devices in the cabinet are:

  • analog temperature sensor
  • analog light sensor
  • analog ambient humidity sensor
  • I2C water level sensor (a capacitive one to prevent the corrosion)
  • servo motor for pushing and pulling the door of the cabinet through the rack and pinion mechanism
  • three digital actuator relays for controlling the submerged pump, the air pump and the LED strip

The meat of the code is in Python that wraps the pySerial library around Arduino microcontroller itself. The wrapper methods are in turn called from two places. Django models and the finite state machine library called automat from Glyph. Communicating the state is sending the JSON message to the channel layer for the front-end to parse.

The other bits of the back-end application is a common auth system used by Django together with REST framework to serialize the messages for interfacing with FloraCodex via my Shamrock library. Originally Shamrock was interfacing with Trefle, but Trefle is now discontinued and FloraCodex is picking up the pieces. It works OK for my use-case. At least in the initial test. This might warrant another article, but I'll probably mention it in the future eventually.

Cuply - Hydroponics Greenhouse Cabinet Powered by Django Channels and Arduino - Hardware

I'm in the process of making a greenhouse out of a glass cabinet that sits on our balcony. Inside it, there's to be a plethora of sensors and actuators hooked up to Arduino Due microcontroller, which is in turn connected to an old Raspberry Pi. The software stack is Django with Channels in the back-end, and React with some D3 in the front-end. It was a project long time in development, and this series of articles will explore it from the inception to the latest product.

  1. Overview
  2. Hardware ← You are here
  3. Back-end
  4. Front-end
  5. Conclusion

The hardware side came to be an IKEA glass cabinet. We opted to buy one and be done with it. I assembled it indoors and we took it out to the balcony. It fit the space we had in mind for the project and we felt it was good enough. The glass walls made it a greenhouse and, because it resembled a cupboard, the name was born: Cuply.

We replaced the original shelving with a suspension contraption to hold the plants. Some parts were bought in the nearby hardware store, some in IKEA, some online, some in the nearby general store, but let's list them all:

Glass Cabinet
Ikea, a small version of MILSBO line, to hold everything. It's transparent on all the sides except the bottom, which is to achieve the greenhouse effect and keep things cozy.
Suspension rod
Ikea, FINTORP line rod, attached with screws from the local hardware store. We drilled into the inside of the cabinet, on the top side, to attach it. It's meant to hold the suspended plant pillars from the accompanying hooks. I also had to shorten it with a hacksaw.
Two chains per pillar
From the local hardware store, four chains in total. They measure ~50cm in length. The links have to fit the hooks on the suspension rod and the turnbuckles.
Three turnbuckles per pillar
From the local hardware store, six in total. Each turnbuckle goes through a bottle so it holds it in place.
Six plastic bottles
They're rather small, 1L actually, but one has to start somewhere and we drank a lot of juice to get them. Bottom half is sprayed white to reflect the sunlight and shield the sensitive roots. Black electric wire isolating tape is added in the middle just for the looks, to hide the transition from white to transparent. The front of each bottle is cut out to allow the plant to stick out. Bottle sides are drilled on the left and right for the turnbuckle to go through. A plant pillar consists of three bottles, turned upside-down and connected by plugging the bottle cap of the previous bottle into the bottom of the next one, which requires drilling a 2.5cm hole in each bottom to push the cap through. Each bottle cap and the bottom of the first bottle have a 5mm holes drilled into them, to connect to the water system loop and circulate water through the pillars. Each bottle houses a hydroponic pot (it's like a regular pot, but like a net) with clay pellets. There are two pillars, three bottles per pillar - six bottles in total.
Upper tank made from a soil drain pipe
10cm diameter, 75cm in length. Both ends are covered with a rubber cap bought online. There is a hole at the top, 2.5cm in diameter, for the water inlet, and two small holes at the bottom of the tank with aquarium drip valves to control the flow. A small piece of aquarium tubing leads from each bottom hole into the top hole of its respective plant pillar. The drip valves are sealed with silicone (which is safe for aquatic life) so they don't leak at the sides. The upper tank is suspended above the pillars and held in place by two pipe clamps and some screws from the local hardware store.
Lower tank also made from a soil drain pipe
10cm diameter, 75cm in length. Both ends are covered with a rubber cap bought online. There is a hole at the top, 2.5cm in diameter, for the water outlet. A small water pump is submerged in the lower tank with a power cable going out the cable hole on the side. The outlet of the lower tank is connected to the inlet hole in the upper tank via the provided water pump tube (via nozzle), approximately 13mm in diameter and of ~150cm length. The pump outputs 1500L of liquid per hour so it's fast and strong enough. Another hole on the top, also 2.5cm in diameter, is drilled on the other side to replenish the water and to provide the access to the air stone from the air pump to keep the algae from forming in the tank. The cap of the bottom bottle of each pillar has a small hole drilled into it, 5mm in diameter, from which an aquarium tube feeds back into the lower thank, allowing it to be filled up again. There's also another ~2mm * ~20mm slit on the top side for the I2C capacitive water level sensor to go into the bottom tank. Could be that more sensors can be added, but this is my experimental limit for now. It is also held in place by two pipe clamps and some screws from the local hardware store.
Light, temperature, ambiental humidity sensors
All analogue placed inside the cabinet.
Relays
For controlling both of the pumps and the light. Three in total.
Arduino Due
All the sensors are attached to it and it has its own power source since all of it cannot be powered through the USB. Arduino Due is used because it supports a wider plethora of sensors than GPIO of Raspberry PI.
Raspberry Pi
A first generation model B+ is put to use here. It has a WiFi antenna in one USB slot (because it didn't come with an integrated WiFi interface) and Arduino Due is plugged in the other USB slot to report the state of the sensors (and act on the actuators).
LED strip in the cabinet
Held in place above the pillars to provide additional lighting and connected via relay to the Arduino Due.
Power source
Everything is neatly connected in one plastic box and fed power coming into the cabinet from the nearby outlet.

The idea came from the Window Farms kickstarter so kudos to those folks. Even though the project is discontinued, it gave me inspiration for the hydroponic loop. The plants are nested in each bottle and are of a herb type, compatible both with the ambiental conditions as well as with each other. There are various attempts online at controlling similar systems via computers. Mine is no different. The systems are known as Grow Boxes and there are most likely communities around them.

The lower tank has an inlet for the solution that is made from water and a fertilizer concentrate bought in store. It needs to be changed weekly or when it evaporates. Once things are set up, the system runs the loop by pumping the solution from the lower tank controlled by the relay and turned on by the sensor, then letting the gravity take care of the rest by dripping the solution from the upper tank all the way through the pillars to the lower tank. The whole cycle is repeated ad nauseam. The lights turn on in the low light conditions.

Here are some photos from hammering on the hardware:


/media/images/cabinet.jpg
/media/images/suspension-rod.jpg
/media/images/turnbuckle-1.jpg
/media/images/turnbuckle-2.jpg
/media/images/pillar-1.jpg
/media/images/pillar-2.jpg
/media/images/light.jpg
/media/images/lower-tank-1.jpg
/media/images/lower-tank-2.jpg
/media/images/lower-tank-3.jpg
/media/images/lower-tank-4.jpg
/media/images/lower-tank-5.jpg
/media/images/lower-tank-6.jpg
/media/images/arduino-box.jpg
/media/images/air-pump.jpg
/media/images/raspberry-pi.jpg
/media/images/cuply-first-look.jpg