Hydroplant Subsystems – Week 6


Introduction to This Week’s Update on Smart Systems

Welcome back! We have used quite some time this week to test the system together, debug, fix issues and test again. Looking forward in the following weeks to show more of our testing with videos!

When life gives you lemons, make lemonade. When Git gives you conflicts, git blame.

Still unknown

Shahin Ostadahmadi

Week 6

Connections between Master Controller and our nodes

Together with Oscar we added more functionality for handling the connection status between Master controller and our Nodes. Oscar has written about this further down. I implemented the following functionalities in GUI and in Library:

  • Make sure that the node always is aware of the connection with Master Controller
    • Update connection status
    • Try to connect to Master controller regularly when the connection is lost
  • Make sure to notify the system if a node is going offline
  • Make sure to tell the system when the nodes become online

By these functionalities along with the same logic Oscar has implemented in Master controller, our nodes, GUI, and master controller always are aware of each other. We tested by turning on and off our Arduinos, Master Controller, and GUI in different orders and the system will automatically handle the connectivity and all the functionalities worked fine. This also helps us to test our entire system much faster than before.

Refactoring CommunicaitonHandler and command queue issues

I refactored the communicationHandler class after testing it several times last week. After refactoring we tested the functionalities for handling commands and we found some issues. The refactoring helped me to test different parts of the code separately and finally find the problematic part. The problem was that the copy constructor of ArduinoJson made a shallow copy of the document when I assumed it took a deep copy. The commands that I copied went out of scope and when I tried to fetch the command to handle it, the pointer to the memory place was gone. This made wired behavior. The solution was take a deep copy of the heap-allocated command, delete the pointer, and send the copied command document to the commandHandler function to handle the command.

I spent a lot of time testing and debugging it along with Oscar on Thursday.

In the diagram, you can see how the commands are handled. the diagram for Main loop is simplified to illustrate the essence, in the actual code the steps are abstracted in the communication class.

Entity measurements/activity values to database

What is an entity?

Entity: as you can see in the picture from our documentation, all our sensors, actuators, and logicControllers are entities. In this way, we can abstract away the most common processes in entity which all the subclasses can use.

Implemented the process of sending measurement/action values for all the entities to the right MQTT topic and Master Controller will take care of it from there. The messages we send are the standard JSON format we use for all our communication exchanges. This process is automatically managed by the communication class and sends the measurements whenever an entity doing a measurement or activity.

Logging functions

I implemented some new functions for logging into our library to simplify the logging process for several use cases. In the picture below you can see the documentation for the new functions. Logging will be sent to the GUI with respective levels: info, warning, and error. The code structure does not limit us to adding other destinations such as storing logging to a file, sending it to the database, or printing it out in serial monitor. The functions were tested with Oscar, we found some issues while testing it and the issues are fixed.

Example of the documentation with explanation:

GUI config page

I also tested out different layouts for the configuration page. This page will be used to change different system configuration for all the different variabels in the system. Such as: different nutrition levels, temperatur, light hours and etc. The page is static for now. We will also do create this page dynamically. We are waiting to test the entire system before we implement all the logic.

Test setup

Together with Ivan, we set up test boards with the necessary electronics. After we received the delivery of new electronics we purchased for testing different parts of the system, the test boards helped us become more efficient. They eliminated the unnecessary time spent connecting electronics each time we wanted to test. Ivan made sure that all the electronics were correctly connected together.

Pictures will come.

Commits

Only members of the organization can see these commits.

https://github.com/hydroplantno/library/commit/bcc7086fc35cd67b8ae8316ffb3c4ec155e3fe60 – Connect your Github account

https://github.com/hydroplantno/library/commit/156ebab2ab0dabbcac9923059b44ed889b1efef3 – Connect your Github account

https://github.com/hydroplantno/water-node/commit/b45b5b95da28e736450a0414c9b99d7780c5bf2a – Connect your Github account

https://github.com/hydroplantno/climate-node/commit/fe6d4abfa7c8c151bcfa157f3305d21643ee54e5 – Connect your Github account

https://github.com/hydroplantno/gui-node/commit/062b137ae9c831ea31cf1515ab9206a4051cbb7a – Connect your Github account

Oscar Melby

Restructuring repos

The code we had for interacting with MQTT was not the best on the “client” side (if we think of master-controller as server). Since there was a lot of repetitive code and logic which every node needed to have anyways, we wanted to hide this away in our library. When starting out we also decided that we wanted to have one GitHub repository containing all the nodes as folders (for some reason). After working a bit with this, and discussing it with Shahin we decided it would be 1. easier to avoid merge conflicts 2. keep track of commits, and 3. just cleaner; to have a repository for each single node.

So I created the repos and helped Aditi and Theo setup their new repos with submodules, sub-submodules and copied some of their code from the old repository.

Before:

After:

Handling disconnects and connects

When testing the system and debugging things we often want the nodes connected to master-controller. Say if master-controller crashes, we would need to physically restart the Arduino Unos for them to be able to reconnect. This is bad since it’s a hassle to work with, and we can’t have the nodes not reconnect in production. So Shahin and I worked on setting up the logic around this. What if master-controller suddenly disconnects, and what if a node disconnects? Turns out our MQTT broker already has some logic implemented for dealing with this. They are called “will” and are a custom set message that gets sent if the node disconnects from the broker. So we had nodes and master-controller send their own “will” if they disconnect, so the other parts can pick up on that. We also made them send out a “ready” message when they connect. Going forward we also want to implement some kind of pinging system, even though it might not be needed, we want to be completely sure that the devices talking know whether the messages will reach out or not.

Also debugged the communication and job handling together with Shahin.

Actions runner

In a previous blog-entry I said that I was done with the GitHub self-hosted actions runner, but I tried a bit more, and seems like it finally works this time. Seems like the error was when creating a folder on the webserver as root, you would not own the folder as default and therefore would need to use sudo to do every single small thing, which the actions runner prohibits. After setting myself as the owner of the folder everything turned out fine. The actions runner is still running after multiple days without crashing and seems like I can finally start to forget about the runner and it just works™

Also switched the runner to be organization-wide instead of just for master-controller, so when we are going to build and deploy documentation in other repositories we just need to set the workflow correctly and it should work.

Still in Idle after multiple days (which is good, means its not offline) :melting_face:

Commits

Only members of the organization can see these commits.

https://github.com/hydroplantno/plant-information-node/commit/3cd6716352191b8bad7cae714a606d63f0f635d6 – Connect your Github account

https://github.com/hydroplantno/master-controller/commit/6ff49a7d9761de65c8e1dbc3d8fce4b9b34db755 – Connect your Github account

Aditi Deshpande

On Monday, our group made big changes to how the git repositories and branches were operated. The Plant Information Node is its own repository now, and the library was updated with communication all in place, which was very good news. I spent some time familiarising myself with the setup. Next, on Wednesday Theo and I started planning our new system where we work with only 3 switches instead of 12. The front part of the stepper motor has one of the switches, the mover itself has one and the end part of the motor has one switch. This way it is easier for the mechanical guys to design exactly where and how the switches are placed so they are activated properly.

So in order for efficient work to be done by the mover in Plant Info Node, it needs to calibrate. This was the big thing I worked on. The mover goes backward to the starting point, and it starts moving forward again when it activates the front switch. Then whenever the switch placed on it is active, we presume it is under a plant holder, so we log that into our system and we also log how many steps the stepper took to reach the specific plant holder.

When the mover reaches the end switch it stops and comes out of the calibrate function. And Theo and I worked together to create the function Calibrate. We came across a lot of problems, such as pointer variables, which weren’t working as they should have, and some git problems while trying to pull(ah git !!) but we managed to finish. To test the function we connected Arduino buttons instead of switches and used interrupt functions. The interrupt functions were also not working properly, it was not being activated at all. But we debugged and found out that I had forgotten the pinMode code, and we had connected the buttons in the wrong order. Shahin’s GUI also could log the PIN, which was great news. After that, I wanted to test this on the actual stepper. I tried connecting with all the right pins, but the stepper was not moving no matter what. I then realized that the hang string that was connected to the mover and stepper was way too tight, the stepper motor was really warm, so it was trying to move, but it couldn’t. I didn’t dare touch the system and try to change it, I will leave that to the mech guys.

  1. Here made some clean changes to Plant Information Node class

https://github.com/hydroplantno/plant-information-node/commit/a4b7a9d979dc1c4599b35c60c42670be13e0ce88 – Connect your Github account

  1. Added the calibrate function which works with Arduino buttonshttps://github.com/hydroplantno/plant-information-node/commit/9b70bfbf6ddae1acd588cac9b06e592c1e064b64 – Connect your Github account
  2. Changes made to library, stepper class, added the Go function: https://github.com/hydroplantno/library/commit/a1e87f636b78431a68b3289e9cf552a8e059bd2e – Connect your Github account

Theo Magnor

Aditi and i started working on the calibrate function, which will count the number of rows and how many steps it took to move to each row. This data will stored in the system and used to control the plant mover. There is still more work to do on the function, and the switch cases where the logic will run. These are the cases for the plant mover: idle, moving, check_switch_state, attach, detach, calibrate. We also need to set up communication between the plant mover and the master controller.

Here is a simple diagram describing the calibrate function:

Ivan Bergmann Maronsson

This week I figured out how to make all the names of the components and values appear on my board. But instead ran into another problem. This problem being that the version of Orcad I have got installed, somehow got installed incorrectly. Where certain files/operations are not included. One of the files not included in my install, where the proper files for mounting holes. Currently I am working on fixing/making my own mounting holes using the padstack editor. And after that will the netlist be created and then Pspice simulations.

I also prepered test board with Shahin on friday for our nodes. I connected necessary electronics on the boards for each node and we are going to test them next week!

Things to do next:

  1. Fixing mounting holes.
  2. Create a netlist

See you in the presentation!


Leave a Reply