Bestanden toegevoegd!
This commit is contained in:
Executable
+201
@@ -0,0 +1,201 @@
|
||||
package weerstation;
|
||||
|
||||
public class Calculator {
|
||||
public Calculator(){
|
||||
}
|
||||
|
||||
// Luchtdruk in hPa
|
||||
// Malek&Tom
|
||||
public double luchtdruk(short mval)
|
||||
{
|
||||
double luchtdruk = (mval / 1000f) * 33.86389;
|
||||
return luchtdruk;
|
||||
}
|
||||
|
||||
// Temperatuur in graden Celcius
|
||||
// Malek&Tom
|
||||
public double temperatuur(short mval)
|
||||
{
|
||||
double temperatuur = (((double)mval / 10) -32) / 1.8;
|
||||
return temperatuur;
|
||||
}
|
||||
|
||||
// Relatieve luchtvochtigheid in %
|
||||
// Malek&Tom
|
||||
public double luchtVochtigheid(short mval)
|
||||
{
|
||||
double luchtvochtigheid = mval;
|
||||
return luchtvochtigheid;
|
||||
}
|
||||
|
||||
// Windsnelheid in m/s
|
||||
// Janco&Tim
|
||||
public double windSnelheid(short mval)
|
||||
{
|
||||
double windSpeed = mval * 0.44704;
|
||||
return windSpeed;
|
||||
}
|
||||
|
||||
// Windrichting in noord, oost, zuid en west.
|
||||
// Kenneth&Daniël
|
||||
public String windRichting(short mval)
|
||||
{
|
||||
String direction = "Error";
|
||||
|
||||
if(mval < 12)
|
||||
{
|
||||
direction = "N";
|
||||
}
|
||||
else if(mval < 34)
|
||||
{
|
||||
direction = "NNO";
|
||||
}
|
||||
else if(mval < 57)
|
||||
{
|
||||
direction = "NO";
|
||||
}
|
||||
else if(mval < 79)
|
||||
{
|
||||
direction = "ONO";
|
||||
}
|
||||
else if(mval < 102)
|
||||
{
|
||||
direction = "O";
|
||||
}
|
||||
else if(mval < 124)
|
||||
{
|
||||
direction = "OZO";
|
||||
}
|
||||
else if(mval < 147)
|
||||
{
|
||||
direction = "ZO";
|
||||
}
|
||||
else if(mval < 169)
|
||||
{
|
||||
direction = "ZZO";
|
||||
}
|
||||
else if(mval < 192)
|
||||
{
|
||||
direction = "Z";
|
||||
}
|
||||
else if(mval < 214)
|
||||
{
|
||||
direction = "ZZW";
|
||||
}
|
||||
else if(mval < 237)
|
||||
{
|
||||
direction = "ZW";
|
||||
}
|
||||
else if(mval < 259)
|
||||
{
|
||||
direction = "WZW";
|
||||
}
|
||||
else if(mval < 282)
|
||||
{
|
||||
direction = "W";
|
||||
}
|
||||
else if(mval < 304)
|
||||
{
|
||||
direction = "WNW";
|
||||
}
|
||||
else if(mval < 327)
|
||||
{
|
||||
direction = "NW";
|
||||
}
|
||||
else if(mval < 349)
|
||||
{
|
||||
direction = "NNW";
|
||||
}
|
||||
else if(mval < 360)
|
||||
{
|
||||
direction = "N";
|
||||
}
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
// Regenmeter in mm
|
||||
// Kenneth&Daniël
|
||||
public double regenmeter(short mval)
|
||||
{
|
||||
double rainAmount = (double)mval*0.2;
|
||||
return rainAmount;
|
||||
}
|
||||
|
||||
// uvIndex in index
|
||||
// Kenneth&Daniël
|
||||
public double uvIndex(short mval)
|
||||
{
|
||||
double index = (double) mval/10;
|
||||
return index;
|
||||
}
|
||||
|
||||
// BatterySpanning in Volt
|
||||
// Janco&Tim
|
||||
public double batterySpanning(short mval){
|
||||
double voltage = (((double)mval * 300)/512)/100;
|
||||
return voltage;
|
||||
}
|
||||
|
||||
// sunRise en Sunset in tijdformaat hh:mm
|
||||
// Janco&Tim
|
||||
public String sunRise(short mval){
|
||||
return sun(mval);
|
||||
}
|
||||
public String sunSet(short mval){
|
||||
return sun(mval);
|
||||
}
|
||||
private String sun(short sunRaw){
|
||||
String tijd = "";
|
||||
for(int i = 0; i <= 3; i++){
|
||||
tijd = sunRaw % 10 + tijd;
|
||||
sunRaw /= 10;
|
||||
if(i == 1){
|
||||
tijd = ":" + tijd;
|
||||
}
|
||||
}
|
||||
return tijd;
|
||||
}
|
||||
|
||||
//windchill in graden Celcius
|
||||
//Janco en Keneth
|
||||
public double windChill(short gradenFahrenheit, short mijlPerUur)
|
||||
{
|
||||
short windChill = (short) (35.74 + (0.6215*gradenFahrenheit) - 35.75*Math.pow(mijlPerUur, 0.16) + 0.4275*gradenFahrenheit*Math.pow(mijlPerUur, 0.16));
|
||||
return temperatuur(windChill);
|
||||
}
|
||||
|
||||
//Heatindex in celcius
|
||||
//Tom met Malek
|
||||
public double heatIndex(double luchtv, double t)
|
||||
{
|
||||
double heatindex = -42.379 + (2.04901523 * t) + (10.14333127 * luchtv) - (0.22475541 * t * luchtv)
|
||||
- (6.83783 * Math.pow(10,-3) * Math.pow(t,2)) - (5.481717 * Math.pow(10,-2) * Math.pow(luchtv,2))
|
||||
+ (1.22874 * Math.pow(10,-3) * Math.pow(t,2) * luchtv) + (8.5282 * Math.pow(10,-4) * t * Math.pow(luchtv,2))
|
||||
- (1.99 * Math.pow(10,-6) * Math.pow(t,2) * Math.pow(luchtv,2));
|
||||
|
||||
return heatindex;
|
||||
}
|
||||
|
||||
//Dauwpunt in Celcius
|
||||
//Daniel en Tim
|
||||
public double dewPoint(double omgevingsTemp, short luchtVochtigheid)
|
||||
{
|
||||
double hm = luchtVochtigheid/100f;
|
||||
double dauwpunt = Math.pow( hm, (1/8f)) * (112 + 0.9*omgevingsTemp) + (0.1*omgevingsTemp) - 112;
|
||||
return dauwpunt;
|
||||
}
|
||||
|
||||
public double cloudHeight(double temp, short luchtVochtigheid ){
|
||||
|
||||
double wolkhoogte = 125 * (temp-dewPoint(temp, luchtVochtigheid));
|
||||
return wolkhoogte;
|
||||
}
|
||||
public void opdrachtEenA(){
|
||||
for(int i = 0; i<4; i++){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package weerstation;
|
||||
//
|
||||
// Port IO emulator class. All read/writes are send over TCP/IP to the host
|
||||
// using a dedicated protocol on port 81.
|
||||
// Use IO.init(host, port) to modify behaviour
|
||||
// by Wim Verhoef
|
||||
// Avans Hogeschool 's-Hertogenbosch
|
||||
//
|
||||
// @author Wim Verhoef
|
||||
// @version 1.1, December 6 2004
|
||||
//
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class IO {
|
||||
public static String host = "localhost";
|
||||
public static int port = 81;
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
* Before calling the emulated IO routines, use one of the init routines
|
||||
* to set the host name and port number of the server emulating the HW.
|
||||
**/
|
||||
public static boolean init() {
|
||||
return (init("localhost", 81));
|
||||
}
|
||||
|
||||
public static boolean init(String newHost) {
|
||||
return (init(newHost, 81));
|
||||
}
|
||||
|
||||
public static boolean init(int newPort) {
|
||||
return (init("localhost", newPort));
|
||||
}
|
||||
|
||||
public static boolean init(String newHost, int newPort) {
|
||||
host = newHost;
|
||||
port = newPort;
|
||||
return startConnectionToServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a short value (16-bits) from an I/O port.
|
||||
* @param address port address (16-bits)
|
||||
* @return short value (16-bits)
|
||||
**/
|
||||
public static short readShort(short address) {
|
||||
return remoteIO( (short) 0, address, (short) 0);
|
||||
}
|
||||
|
||||
public static short readShort(int address) {
|
||||
return remoteIO( (short) 0, (short) address, (short) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a short value (16-bits) to an I/O port.
|
||||
* @param address port address (16-bits)
|
||||
* @param value short value (16-bits)
|
||||
**/
|
||||
public static void writeShort(short address, short value) {
|
||||
remoteIO( (short) 1, address, value);
|
||||
}
|
||||
|
||||
public static void writeShort(int address, int value) {
|
||||
remoteIO( (short) 1, (short) address, (short) value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait a specified time. The routine uses Thread.sleep so below 20 ms
|
||||
* timing becomes very erraneous, but works fine for longer times
|
||||
*
|
||||
* @param lMilliSeconds number of milliseconds to wait
|
||||
*/
|
||||
|
||||
public static void delay(long lMilliSeconds) {
|
||||
if (lMilliSeconds > 0) {
|
||||
try {
|
||||
Thread.sleep(lMilliSeconds);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//============================= below are the support routines =====================
|
||||
|
||||
private static Socket client = null;
|
||||
private static DataOutputStream output = null;
|
||||
private static DataInputStream input = null;
|
||||
|
||||
private static void closeConnectionToServer() {
|
||||
try {
|
||||
if (output != null)
|
||||
output.close();
|
||||
if (input != null)
|
||||
input.close();
|
||||
if (client != null)
|
||||
client.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// no errors plz. e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean startConnectionToServer() {
|
||||
closeConnectionToServer(); // close any pending connection
|
||||
try {
|
||||
client = new Socket(InetAddress.getByName(host), port);
|
||||
client.setSoTimeout(2000); // we expect answers within 2 seconds
|
||||
client.setTcpNoDelay(true); //disable nagles algorithm for short packets
|
||||
output = new DataOutputStream(new BufferedOutputStream(client.
|
||||
getOutputStream()));
|
||||
input = new DataInputStream(new BufferedInputStream(client.getInputStream()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
client = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static short remoteIO(short IOCode, short address, short value) {
|
||||
if (client == null)
|
||||
return (short) - 1;
|
||||
|
||||
short readvalue = (short) 0;
|
||||
try {
|
||||
output.writeShort(IOCode);
|
||||
output.writeShort(address);
|
||||
output.writeShort(value);
|
||||
output.flush();
|
||||
readvalue = input.readShort();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// no errors plz. e.printStackTrace();
|
||||
}
|
||||
return readvalue;
|
||||
}
|
||||
}
|
||||
Executable
+156
@@ -0,0 +1,156 @@
|
||||
package weerstation;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class Measurement
|
||||
{
|
||||
|
||||
private String stationId;
|
||||
private java.sql.Timestamp dateStamp;
|
||||
private short barometer;
|
||||
private short insideTemp;
|
||||
private short insideHum;
|
||||
private short outsideTemp;
|
||||
private short windSpeed;
|
||||
private short avgWindSpeed;
|
||||
private short windDir;
|
||||
private short outsideHum;
|
||||
private short rainRate;
|
||||
private short UVLevel;
|
||||
private short solarRad;
|
||||
private short xmitBatt;
|
||||
private short battLevel;
|
||||
private short sunrise;
|
||||
private short sunset;
|
||||
Calculator calc;
|
||||
|
||||
public Measurement()
|
||||
{
|
||||
calc = new Calculator();
|
||||
}
|
||||
|
||||
// stationId
|
||||
public void setStationId (String str) { this.stationId = str;};
|
||||
public String getStationId () { return stationId; };
|
||||
|
||||
// dateStamp
|
||||
public void setDateStamp (java.sql.Timestamp ts) { this.dateStamp = ts;};
|
||||
public java.sql.Timestamp getDateStamp () { return dateStamp; };
|
||||
|
||||
// barometer
|
||||
public void setRawBarometer (short val) { this.barometer = val;};
|
||||
public short getRawBarometer () { return barometer; };
|
||||
public double getBarometer () { return round(calc.luchtdruk(barometer),0); };
|
||||
|
||||
// insideTemp
|
||||
public void setRawInsideTemp (short val) { this.insideTemp = val;};
|
||||
public short getRawInsideTemp () { return insideTemp; };
|
||||
public double getInsideTemp () { return round(calc.temperatuur(insideTemp),2); };
|
||||
|
||||
// insideHum
|
||||
public void setRawInsideHum (short val) { this.insideHum = val;};
|
||||
public short getRawInsideHum () { return insideHum; };
|
||||
public double getInsideHum () { return round(calc.luchtVochtigheid(insideHum),0); };
|
||||
|
||||
// outsideTemp
|
||||
public void setRawOutsideTemp (short val) { this.outsideTemp = val;};
|
||||
public short getRawOutsideTemp () { return outsideTemp; };
|
||||
public double getOutsideTemp () { return round(calc.temperatuur(outsideTemp),2); };
|
||||
|
||||
// windSpeed
|
||||
public void setRawWindSpeed (short val) { this.windSpeed = val;};
|
||||
public short getRawWindSpeed () { return windSpeed; };
|
||||
public double getWindSpeed () { return round(calc.windSnelheid(windSpeed),2); };
|
||||
|
||||
// avgWindSpeed
|
||||
public void setRawAvgWindSpeed (short val) { this.avgWindSpeed = val;};
|
||||
public short getRawAvgWindSpeed () { return avgWindSpeed; };
|
||||
public double getAvgWindSpeed () { return round(calc.windSnelheid(avgWindSpeed),2); };
|
||||
|
||||
// windDir
|
||||
public void setRawWindDir (short val) { this.windDir = val;};
|
||||
public short getRawWindDir () { return windDir; };
|
||||
public String getWindDir () { return calc.windRichting(windDir); };
|
||||
|
||||
// outsideHum
|
||||
public void setRawOutsideHum (short val) { this.outsideHum = val;};
|
||||
public short getRawOutsideHum () { return outsideHum; };
|
||||
public double getOutsideHum () { return round(calc.luchtVochtigheid(outsideHum),0); };
|
||||
|
||||
// rainRate
|
||||
public void setRawRainRate (short val) { this.rainRate = val;};
|
||||
public short getRawRainRate () { return rainRate; };
|
||||
public double getRainRate () { return calc.regenmeter(rainRate); };
|
||||
|
||||
// UVLevel
|
||||
public void setRawUVLevel (short val) { this.UVLevel = val;};
|
||||
public short getRawUVLevel () { return UVLevel; };
|
||||
public double getUVLevel () { return Math.ceil(calc.uvIndex(UVLevel)); };
|
||||
|
||||
// solarRad
|
||||
public void setRawSolarRad (short val) { this.solarRad = val;};
|
||||
public short getRawSolarRad () { return solarRad; };
|
||||
|
||||
|
||||
// xmitBatt
|
||||
public void setRawXmitBatt (short val) { this.xmitBatt = val;};
|
||||
public short getRawXmitBatt () { return xmitBatt; };
|
||||
|
||||
// battLevel
|
||||
public void setRawBattLevel (short val) { this.battLevel = val;};
|
||||
public short getRawBattLevel () { return battLevel; };
|
||||
public double getBattLevel () { return round(calc.batterySpanning(battLevel),2); };
|
||||
|
||||
// sunrise
|
||||
public void setRawSunrise (short val) { this.sunrise = val;};
|
||||
public short getRawSunrise () { return sunrise; };
|
||||
public String getSunrise () { return calc.sunRise(sunrise); };
|
||||
|
||||
// sunset
|
||||
public void setRawSunset (short val) { this.sunset = val;};
|
||||
public short getRawSunset () { return sunset; };
|
||||
public String getSunset () { return calc.sunSet(sunset); };
|
||||
|
||||
// windChill
|
||||
public double getWindChill () { return round(calc.windChill(outsideTemp, windSpeed),2); };
|
||||
|
||||
// heatIndex
|
||||
public double getHeatIndex () { return round(calc.heatIndex(outsideHum, outsideTemp),0); };
|
||||
|
||||
// dewPoint
|
||||
public double getDewPoint () { return round(calc.dewPoint( getOutsideTemp() , outsideHum),2); };
|
||||
|
||||
//wolkHoogte
|
||||
public double getCloudHeight () { return round(calc.cloudHeight(outsideTemp, outsideHum),1); };
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String s = "stationId = " + stationId
|
||||
+ ", dateStamp = " + dateStamp
|
||||
+ ", barometer = " + barometer
|
||||
+ ", insideTemp = " + insideTemp
|
||||
+ ", insideHum = " + insideHum
|
||||
+ ", outsideTemp = " + outsideTemp
|
||||
+ ", windSpeed = " + windSpeed
|
||||
+ ", avgWindSpeed = " + avgWindSpeed
|
||||
+ ", windDir = " + windDir
|
||||
+ ", outsideHum = " + outsideHum
|
||||
+ ", rainRate = " + rainRate
|
||||
+ ", UVLevel = " + UVLevel
|
||||
+ ", solarRad = " + solarRad
|
||||
+ ", xmitBatt = " + xmitBatt
|
||||
+ ", battLevel = " + battLevel
|
||||
+ ", sunrise = " + sunrise
|
||||
+ ", sunset = " + sunset;
|
||||
return s;
|
||||
}
|
||||
|
||||
//afronder
|
||||
public double round(double unrounded, int precision)
|
||||
{
|
||||
BigDecimal bd = new BigDecimal(unrounded);
|
||||
BigDecimal rounded = bd.setScale(precision, BigDecimal.ROUND_HALF_UP);
|
||||
return rounded.doubleValue();
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+561
@@ -0,0 +1,561 @@
|
||||
package weerstation;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class Weerstation
|
||||
{
|
||||
|
||||
private Connection myConn = null;
|
||||
|
||||
|
||||
|
||||
|
||||
public Weerstation()
|
||||
{
|
||||
this("84.24.41.72","5329","aws_data","aws","aws");
|
||||
}
|
||||
|
||||
//Start connection with Databse
|
||||
public Weerstation(String host, String port, String dbName, String userName, String password)
|
||||
{
|
||||
try
|
||||
{
|
||||
String url = "jdbc:mysql://" + host + ":" + port + "/"+ dbName + "?user="
|
||||
+ userName
|
||||
+ "&password="
|
||||
+ password;
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance ();
|
||||
myConn = DriverManager.getConnection(url);
|
||||
System.out.println("Database connection established");
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
System.out.println("Error : " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get most recent values of one column
|
||||
public Timestamp getMostRecentTimeStamp()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getDateStamp();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentBarometer()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawBarometer();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentInsideTemp()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawInsideTemp();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentInsideHum()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawInsideHum();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentOutsideTemp()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawOutsideTemp();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentWindSpeed()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawWindSpeed();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentAvgWindSpeed()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawAvgWindSpeed();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentWindDir()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawWindDir();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentOutsideHum()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawOutsideHum();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentRainRate()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawRainRate();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentUVLevel()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawUVLevel();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentSolarRadiation()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawSolarRad();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentXmitBatt()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawXmitBatt();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentBattLevel()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawBattLevel();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentSunrise()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawSunrise();
|
||||
|
||||
}
|
||||
|
||||
public short getMostRecentSunset()
|
||||
{
|
||||
Measurement m = getMostRecentMeasurement();
|
||||
return m.getRawSunset();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get all values of one column
|
||||
public short[] getAllOutsideTemp()
|
||||
{
|
||||
ArrayList<Measurement> mArr = getAllMeasurements();
|
||||
short[] values = new short[mArr.size()];
|
||||
int count = 0;
|
||||
for(Measurement m: mArr )
|
||||
{
|
||||
values[count++] = m.getRawOutsideTemp();
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public short[] getAllBarometer()
|
||||
{
|
||||
ArrayList<Measurement> mArr = getAllMeasurements();
|
||||
short[] values = new short[mArr.size()];
|
||||
int count = 0;
|
||||
for(Measurement m: mArr )
|
||||
{
|
||||
values[count++] = m.getRawBarometer();
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get most recent value of all columns
|
||||
public Measurement getMostRecentMeasurement()
|
||||
{
|
||||
|
||||
Measurement m = new Measurement();
|
||||
|
||||
try
|
||||
{
|
||||
// query:
|
||||
Statement s = myConn.createStatement();
|
||||
s.executeQuery("SELECT stationId, timestamp, " +
|
||||
"barometer, " +
|
||||
"insideTemp, " +
|
||||
"insideHum, " +
|
||||
"outsideTemp, " +
|
||||
"windSpeed, " +
|
||||
"avgWindSpeed, " +
|
||||
"windDir, " +
|
||||
"outsideHum, " +
|
||||
"rainRate, " +
|
||||
"UVLevel, " +
|
||||
"solarRad, " +
|
||||
"xmitBatt, " +
|
||||
"battLevel, " +
|
||||
"sunrise, " +
|
||||
"sunset " +
|
||||
"FROM measurement order by measurementId desc limit 1");
|
||||
|
||||
ResultSet rs = s.getResultSet();
|
||||
int count = 0;
|
||||
while( rs.next() )
|
||||
{
|
||||
m.setStationId( rs.getString("stationId") );
|
||||
m.setDateStamp( rs.getTimestamp(2));
|
||||
m.setRawBarometer( Short.valueOf(rs.getString("barometer")) );
|
||||
m.setRawInsideTemp( Short.valueOf(rs.getString("insideTemp")) );
|
||||
m.setRawInsideHum( Short.valueOf(rs.getString("insideHum")) );
|
||||
m.setRawOutsideTemp( Short.valueOf(rs.getString("outsideTemp")) );
|
||||
m.setRawWindSpeed( Short.valueOf(rs.getString("windSpeed")) );
|
||||
m.setRawAvgWindSpeed( Short.valueOf(rs.getString("avgWindSpeed")) );
|
||||
m.setRawWindDir( Short.valueOf(rs.getString("windDir")) );
|
||||
m.setRawOutsideHum( Short.valueOf(rs.getString("outsideHum")) );
|
||||
m.setRawRainRate( Short.valueOf(rs.getString("rainRate")) );
|
||||
m.setRawUVLevel( Short.valueOf(rs.getString("UVLevel")) );
|
||||
m.setRawSolarRad( Short.valueOf(rs.getString("solarRad")) );
|
||||
m.setRawXmitBatt( Short.valueOf(rs.getString("xmitBatt")) );
|
||||
m.setRawBattLevel( Short.valueOf(rs.getString("battLevel")) );
|
||||
m.setRawSunrise( Short.valueOf(rs.getString("sunrise")) );
|
||||
m.setRawSunset( Short.valueOf(rs.getString("sunset")) );
|
||||
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
s.close();
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch( Exception ex)
|
||||
{
|
||||
System.out.println("getMeasurement: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get all values of all columns
|
||||
public ArrayList<Measurement> getAllMeasurements()
|
||||
{
|
||||
|
||||
ArrayList<Measurement> mArr = new ArrayList<Measurement>();
|
||||
|
||||
try
|
||||
{
|
||||
// query:
|
||||
Statement s = myConn.createStatement();
|
||||
s.executeQuery("SELECT stationId, timestamp, " +
|
||||
"barometer, " +
|
||||
"insideTemp, " +
|
||||
"insideHum, " +
|
||||
"outsideTemp, " +
|
||||
"windSpeed, " +
|
||||
"avgWindSpeed, " +
|
||||
"windDir, " +
|
||||
"outsideHum, " +
|
||||
"rainRate, " +
|
||||
"UVLevel, " +
|
||||
"solarRad, " +
|
||||
"xmitBatt, " +
|
||||
"battLevel, " +
|
||||
"sunrise, " +
|
||||
"sunset " +
|
||||
"FROM measurement");
|
||||
|
||||
ResultSet rs = s.getResultSet();
|
||||
int count = 0;
|
||||
while( rs.next() )
|
||||
{
|
||||
Measurement m = new Measurement();
|
||||
|
||||
m.setStationId( rs.getString("stationId") );
|
||||
m.setDateStamp( rs.getTimestamp(2));
|
||||
m.setRawBarometer( Short.valueOf(rs.getString("barometer")) );
|
||||
m.setRawInsideTemp( Short.valueOf(rs.getString("insideTemp")) );
|
||||
m.setRawInsideHum( Short.valueOf(rs.getString("insideHum")) );
|
||||
m.setRawOutsideTemp( Short.valueOf(rs.getString("outsideTemp")) );
|
||||
m.setRawWindSpeed( Short.valueOf(rs.getString("windSpeed")) );
|
||||
m.setRawAvgWindSpeed( Short.valueOf(rs.getString("avgWindSpeed")) );
|
||||
m.setRawWindDir( Short.valueOf(rs.getString("windDir")) );
|
||||
m.setRawOutsideHum( Short.valueOf(rs.getString("outsideHum")) );
|
||||
m.setRawRainRate( Short.valueOf(rs.getString("rainRate")) );
|
||||
m.setRawUVLevel( Short.valueOf(rs.getString("UVLevel")) );
|
||||
m.setRawSolarRad( Short.valueOf(rs.getString("solarRad")) );
|
||||
m.setRawXmitBatt( Short.valueOf(rs.getString("xmitBatt")) );
|
||||
m.setRawBattLevel( Short.valueOf(rs.getString("battLevel")) );
|
||||
m.setRawSunrise( Short.valueOf(rs.getString("sunrise")) );
|
||||
m.setRawSunset( Short.valueOf(rs.getString("sunset")) );
|
||||
|
||||
mArr.add(m);
|
||||
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
s.close();
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch( Exception ex)
|
||||
{
|
||||
System.out.println("getMeasurement: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return mArr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get specified values of all columns
|
||||
public ArrayList<Measurement> getAllMeasurementsBetween(GregorianCalendar d1, GregorianCalendar d2)
|
||||
{
|
||||
|
||||
String sd1 = d1.get(Calendar.YEAR) + "-" + (d1.get(Calendar.MONTH)+1) + "-" + d1.get(Calendar.DATE) + " 0:0:0";
|
||||
String sd2 = d2.get(Calendar.YEAR) + "-" + (d2.get(Calendar.MONTH)+1) + "-" + d2.get(Calendar.DATE) + " 23:59:59";
|
||||
|
||||
ArrayList<Measurement> mArr = new ArrayList<Measurement>();
|
||||
|
||||
try
|
||||
{
|
||||
// query:
|
||||
Statement s = myConn.createStatement();
|
||||
s.executeQuery("SELECT stationId, timestamp, " +
|
||||
"barometer, " +
|
||||
"insideTemp, " +
|
||||
"insideHum, " +
|
||||
"outsideTemp, " +
|
||||
"windSpeed, " +
|
||||
"avgWindSpeed, " +
|
||||
"windDir, " +
|
||||
"outsideHum, " +
|
||||
"rainRate, " +
|
||||
"UVLevel, " +
|
||||
"solarRad, " +
|
||||
"xmitBatt, " +
|
||||
"battLevel, " +
|
||||
"sunrise, " +
|
||||
"sunset " +
|
||||
"FROM measurement where timestamp between " +
|
||||
"'" + sd1 + "' and '" + sd2 + "'");
|
||||
|
||||
ResultSet rs = s.getResultSet();
|
||||
int count = 0;
|
||||
while( rs.next() )
|
||||
{
|
||||
Measurement m = new Measurement();
|
||||
|
||||
m.setStationId( rs.getString("stationId") );
|
||||
m.setDateStamp( rs.getTimestamp(2));
|
||||
m.setRawBarometer( Short.valueOf(rs.getString("barometer")) );
|
||||
m.setRawInsideTemp( Short.valueOf(rs.getString("insideTemp")) );
|
||||
m.setRawInsideHum( Short.valueOf(rs.getString("insideHum")) );
|
||||
m.setRawOutsideTemp( Short.valueOf(rs.getString("outsideTemp")) );
|
||||
m.setRawWindSpeed( Short.valueOf(rs.getString("windSpeed")) );
|
||||
m.setRawAvgWindSpeed( Short.valueOf(rs.getString("avgWindSpeed")) );
|
||||
m.setRawWindDir( Short.valueOf(rs.getString("windDir")) );
|
||||
m.setRawOutsideHum( Short.valueOf(rs.getString("outsideHum")) );
|
||||
m.setRawRainRate( Short.valueOf(rs.getString("rainRate")) );
|
||||
m.setRawUVLevel( Short.valueOf(rs.getString("UVLevel")) );
|
||||
m.setRawSolarRad( Short.valueOf(rs.getString("solarRad")) );
|
||||
m.setRawXmitBatt( Short.valueOf(rs.getString("xmitBatt")) );
|
||||
m.setRawBattLevel( Short.valueOf(rs.getString("battLevel")) );
|
||||
m.setRawSunrise( Short.valueOf(rs.getString("sunrise")) );
|
||||
m.setRawSunset( Short.valueOf(rs.getString("sunset")) );
|
||||
|
||||
mArr.add(m);
|
||||
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
s.close();
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch( Exception ex)
|
||||
{
|
||||
System.out.println("getMeasurement: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return mArr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get last 86400 values of all columns
|
||||
public ArrayList<Measurement> getAllMeasurementsLast24h()
|
||||
{
|
||||
return getAllMeasurementsLastHours(24);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get specified values of all columns
|
||||
public ArrayList<Measurement> getAllMeasurementsLastHours(int hour)
|
||||
{
|
||||
|
||||
ArrayList<Measurement> mArr = new ArrayList<Measurement>();
|
||||
|
||||
try
|
||||
{
|
||||
// query:
|
||||
Statement s = myConn.createStatement();
|
||||
s.executeQuery("SELECT stationId, timestamp, " +
|
||||
"barometer, " +
|
||||
"insideTemp, " +
|
||||
"insideHum, " +
|
||||
"outsideTemp, " +
|
||||
"windSpeed, " +
|
||||
"avgWindSpeed, " +
|
||||
"windDir, " +
|
||||
"outsideHum, " +
|
||||
"rainRate, " +
|
||||
"UVLevel, " +
|
||||
"solarRad, " +
|
||||
"xmitBatt, " +
|
||||
"battLevel, " +
|
||||
"sunrise, " +
|
||||
"sunset " +
|
||||
"FROM measurement where timestamp between NOW() - INTERVAL " +
|
||||
hour + " HOUR and NOW()");
|
||||
|
||||
|
||||
ResultSet rs = s.getResultSet();
|
||||
int count = 0;
|
||||
while( rs.next() )
|
||||
{
|
||||
Measurement m = new Measurement();
|
||||
|
||||
m.setStationId( rs.getString("stationId") );
|
||||
m.setDateStamp( rs.getTimestamp(2));
|
||||
m.setRawBarometer( Short.valueOf(rs.getString("barometer")) );
|
||||
m.setRawInsideTemp( Short.valueOf(rs.getString("insideTemp")) );
|
||||
m.setRawInsideHum( Short.valueOf(rs.getString("insideHum")) );
|
||||
m.setRawOutsideTemp( Short.valueOf(rs.getString("outsideTemp")) );
|
||||
m.setRawWindSpeed( Short.valueOf(rs.getString("windSpeed")) );
|
||||
m.setRawAvgWindSpeed( Short.valueOf(rs.getString("avgWindSpeed")) );
|
||||
m.setRawWindDir( Short.valueOf(rs.getString("windDir")) );
|
||||
m.setRawOutsideHum( Short.valueOf(rs.getString("outsideHum")) );
|
||||
m.setRawRainRate( Short.valueOf(rs.getString("rainRate")) );
|
||||
m.setRawUVLevel( Short.valueOf(rs.getString("UVLevel")) );
|
||||
m.setRawSolarRad( Short.valueOf(rs.getString("solarRad")) );
|
||||
m.setRawXmitBatt( Short.valueOf(rs.getString("xmitBatt")) );
|
||||
m.setRawBattLevel( Short.valueOf(rs.getString("battLevel")) );
|
||||
m.setRawSunrise( Short.valueOf(rs.getString("sunrise")) );
|
||||
m.setRawSunset( Short.valueOf(rs.getString("sunset")) );
|
||||
|
||||
mArr.add(m);
|
||||
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
s.close();
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch( Exception ex)
|
||||
{
|
||||
System.out.println("getMeasurement: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return mArr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Exectute a custom query
|
||||
private ResultSet executeCustomQuery(String query)
|
||||
{
|
||||
ResultSet returnSet = null;
|
||||
|
||||
try{
|
||||
Statement s = myConn.createStatement();
|
||||
s.executeQuery(query);
|
||||
ResultSet rs = s.getResultSet();
|
||||
|
||||
returnSet = rs;
|
||||
|
||||
rs.close();
|
||||
s.close();
|
||||
}
|
||||
catch( SQLException ex)
|
||||
{
|
||||
System.out.println("SQLException: " + ex.getMessage());
|
||||
System.out.println("SQLState: " + ex.getSQLState());
|
||||
System.out.println("VendorError: " + ex.getErrorCode());
|
||||
}
|
||||
catch( Exception ex)
|
||||
{
|
||||
System.out.println("getMeasurement: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return returnSet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Close connection with Database
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
// Close database connection
|
||||
if( myConn != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
myConn.close();
|
||||
System.out.println("Database connection terminated");
|
||||
}
|
||||
catch( Exception e ) {}
|
||||
}
|
||||
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user