Close

Java Dev Day Update!

A project log for HydroPWNics

An open source hydroponic garden control, monitoring, and grow system with cloud database and dashboard.

avrAVR 06/29/2015 at 03:510 Comments

So today I spent some time working on the higher level software for the system. I'd say good chunk got done too but there is still plenty to go. I started with the Java software because for the most part the system's layout and how all the subsystems interact with eachother is basically decided (see previous diagram). Most of the code written today pertains to the data object and how the data of each plant and garden as a whole will be represented and managed inside the Java program. Code from today is found at the following repo: https://github.com/adamjvr/HydroPWNicsAPI

The data structure for the the garden is a sort of nested data structure. The Garden as a whole is represented by a Garden object, the Garden object is made up of PlantRow objects. PlantRow represents a row of plants in the system, PlantRowm has a fixed size set during instantiation. The PlantRow object holds up to the set max amount of Plant objects in an ArrayList. The objects represent the different physical components of the grow units, the plants and the fence post row units they grow in. The Plant object represents a plant, Plant objects are contained by PlantRow objects. A Plant object contains an arraylist of all data samples (timestamped) take during the plants lifetime in addition to characteristics such as name and type. So thats the general overview of how the data of the garden will be handled internal.

Some Code Snippets of the Data Objects can be found below, keep in mind these are rough and very bleeding edge lol

Plant Object

package com.DataTypes.hydroPWNicsAPI.github.io;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
public class Plant {
	/**
	 * plantDataSamples : an ArrayList of type PlantData containing all the data
	 * samples on a given plant complete with timestamp
	 */
	ArrayList<PlantData> plantDataSamples = new ArrayList<PlantData>();

	/**
	 * plantDataSamplesIterator an Iterator of Type PlantData for cycling
	 * through the arraylist of containing all plant data samples
	 */
	Iterator<PlantData> plantDataSamplesIterator = plantDataSamples.iterator();
	
	/**
	 * datPlanted : a timestamp oject denoting the time the plant was added to
	 * the system
	 */
	Timestamp datePlanted = new Timestamp(0);
	
	/**
	 * PlantTyep : a string of the plant type, e.g Tomato, or Pepper etc
	 */
	String PlantType = "N/A";

	/**
	 * plnt_stage : an enum denoting the plants growth stage, Seedling, sprout,
	 * vegetive, flowering and fruiting.
	 */
	PlantStage plnt_stage = null;

	/**
	 * Instantiation constructor, acceps a date of planting, string for type
	 */
	public Plant(Timestamp date, String type, PlantStage pstage) {
		datePlanted = date;
		PlantType = type;
		plnt_stage = pstage;
	}
	
	
	/**
	 * Returns plant data on a given day/time
	 * 
	 * @param desired_date
	 *            accepts a timstamp object representing the desired date
	 * @return returns a PlantData object containing all the plant data on the
	 *         specified date.
	 */
	public PlantData getPlantDataOnDate(Timestamp desired_date) {
		PlantData dd_data = new PlantData();
		Timestamp iterator_time = new Timestamp(0);
		while (plantDataSamplesIterator.hasNext()) {
			dd_data = plantDataSamplesIterator.next();
			iterator_time = dd_data.getSmplDate();

			if (iterator_time.equals(desired_date)) {
				return dd_data;
			}// end if

		}// end while
		return null;
	}// end funct

	/**
	 * 
	 * @return
	 */
	public int getDays() {
		return 0;
	}

	/**
	 * 
	 * @return
	 */
	public int getWeeks() {
		return 0;
	}
}

PlantData Object

package com.DataTypes.hydroPWNicsAPI.github.io;

import java.sql.Timestamp;

public class PlantData {

	/**
	 * plant_humidity Humidity within the vicinity of the plant
	 */
	double plant_humidity = 0.0;
	/**
	 * plant_temp the temperature within the vicinity of the plant
	 */
	double plant_temp = 0.0;
	/**
	 * smpl_waterData : the waterData at the time of that the sample of plant
	 * data is taking place
	 */
	WaterData smpl_waterData = new WaterData();

	/**
	 * lght_tmp : an enum pertaining to the type of light conditions the plant
	 * is under at the time of the plant data sample taking place
	 */
	LightTemp lght_tmp = null;
	/**
	 * type : an enum pertainting to the type of garden the plant is in,
	 * hydroponic, soil, or soiless
	 */
	GardenType type = null;
	/**
	 * smplDate : a Timestamp object containting the date and time the sample of
	 * plant data occurred.
	 */
	Timestamp smplDate = new Timestamp(0);

	/**
	 * Main constructor used for full instantiation of PlantData Object
	 * 
	 * @param iplant_humidity
	 *            Humidity around the plant at time of sample
	 * @param iplant_temp
	 *            Temperature around the plant at time of sample
	 * @param ismpl_waterData
	 *            Water datagram at the time of sample
	 * @param itype
	 *            Plant type, hydroponic, soil, or soiless pertains to garden
	 *            growth type
	 */
	public PlantData(double iplant_humidity, double iplant_temp,
			WaterData ismpl_waterData, GardenType itype, LightTemp ilght_tmp,
			Timestamp idate) {
		plant_humidity = iplant_humidity;
		plant_temp = iplant_temp;
		smpl_waterData = ismpl_waterData;
		type = itype;
		lght_tmp = ilght_tmp;
		smplDate = idate;
	}

	/**
	 * default constructor defaults to hydroponic garden designation all other
	 * datatypes default to their constructor default in this case
	 */
	public PlantData() {
		type = GardenType.HYDRO;
	}

	
	/**
	 * getPlant_humidity : returns the plants humidity
	 * 
	 * @return returns type double, member variable pertaining to humidity of
	 *         plant at time of sample
	 */
	public double getPlant_humidity() {
		return plant_humidity;
	}

	/**
	 * 
	 * @return
	 */
	public double getPlant_temp() {
		return plant_temp;
	}

	/**
	 * 
	 * @return
	 */
	public WaterData getSmpl_waterData() {
		return smpl_waterData;
	}

	/**
	 * 
	 * @return
	 */
	public GardenType getType() {
		return type;
	}

	/**
	 * 
	 * @param type
	 */
	public void setType(GardenType type) {
		this.type = type;
	}

	/**
	 * 
	 * @return
	 */
	public Timestamp getSmplDate() {
		return smplDate;
	}

}

PlantRow Object

package com.DataTypes.hydroPWNicsAPI.github.io;

import java.util.ArrayList;
import java.util.Iterator;

public class PlantRow {
	int num_plants = 0;
	int max_plant_num = 4;
	ArrayList<Plant> PlantsInRow = new ArrayList<Plant>();
	Iterator<Plant> IPlantsInRowIterator = PlantsInRow.iterator();

	/**
	 * Main Constructor
	 * 
	 * @param iPlantsInRow
	 */
	public PlantRow(ArrayList<Plant> iPlantsInRow) {
		PlantsInRow = iPlantsInRow;
		num_plants = iPlantsInRow.size();
	}

	/**
	 * 
	 * @return
	 */
	public int getNumberOfPlants() {
		return num_plants;
	}

	/**
	 * 
	 * @return
	 */
	public Plant getPlant(int list_index) {
		return PlantsInRow.get(list_index);
	}

	/**
	 * 
	 * @param newPlant
	 */
	public void addPlantToRow(Plant newPlant) {
		if (PlantsInRow.size() < max_plant_num) {
			PlantsInRow.add(newPlant);
		}
	}

}

Garden Object

package com.DataTypes.hydroPWNicsAPI.github.io;

import java.util.ArrayList;
import java.util.Iterator;

public class Garden {
	ArrayList<PlantRow> GardenRows = new ArrayList<PlantRow>();
	Iterator<PlantRow> IGardenRowsIterator = GardenRows.iterator();
	int GardenRowCount = 0;
	int MaxGardenRowSize = 0;
	int PlantRowSize = 0;
	int GardenSize = 0;
	
	public void addRowToGarden(PlantRow rowToAdd){
		if(GardenRows.size()<MaxGardenRowSize){
			GardenRows.add(rowToAdd);
		}
	}
	
	public void AddPlantToGarden(PlantRow whchRow, int plantRowNum){
		
	}
	
	
	public void removePlantFromGarden(PlantRow whchRow, int plantRowNum){
		
	}
	
	
	
}

On another note in regards to the Java side of things, I did also begin the Java objects representing the hardware. This component of the system is a bit more complex than I anticipated so I didn't get much done in one sitting. I need to read up more on the custom Bowler device documentation from Neuron Robotics before I move ahead anymore with this code.

For transmitting the data to the cloud, I have decided to use JSON packets and the google Gson Java JSON library. With the Gson library I can easily serialize the datatype objects into JSON strings and push them to the cloud. The reason to use JSON is that its simple, readable, and well used. JSON use is definitely the newest development in the project so I don't have much else to say on the subject, so stay tuned for new updates!!!!

Discussions