Académique Documents
Professionnel Documents
Culture Documents
Source code:
The following is the source code that runs on the client side of the webpage.
dojo.declare("Main", wm.Page, {
start: function() {
this.timer_Temp.update();
},
"preferredDevice": "desktop",
//Temperature
serviceVar_checkTempatureSuccess: function(inSender, inDeprecated) {
this.var_temp.setValue("dataValue", inSender.getData().dataValue);
this.iFrame_temp.setSource("resources/htmlcontent/thermometer.html");
this.label_temp.setCaption(inSender.getData().dataValue);
},
timer_TempTimerFire: function(inSender) {
this.serviceVar_checkTempature.update();
},
//Filling tank
button_fill_onClick: function(inSender) {
this.serviceVar_fillOn.update();
this.button_fill_off.show();
this.button_fill_on.hide();
this.picture_sink.show();
},
serviceVar_fillOnSuccess: function(inSender, inDeprecated) {
alert("Filling");
},
serviceVar_fillOnError: function(inSender, inError) {
this.picture_sink.hide();
alert("Tank not filling. Try again.");
this.button_fill_off.hide();
this.button_fill_on.show();
},
button_fill_offClick: function(inSender) {
this.serviceVar_fillOff.update();
this.button_fill_on.show();
this.button_fill_off.hide();
this.picture_sink.hide();
},
serviceVar_fillOffSuccess: function(inSender, inDeprecated) {
alert("Filling stopped");
},
serviceVar_fillOffError: function(inSender, inError) {
this.picture_sink.show();
alert("Filling didn't stop. Try again.");
this.button_fill_on.hide();
this.button_fill_off.show();
},
//Draining tank
button_drain_onClick: function(inSender) {
this.serviceVar_drainOn.update();
this.button_drain_off.show();
this.button_drain_on.hide();
},
serviceVar_drainOnSuccess: function(inSender, inDeprecated) {
alert("Tank draining.");
},
serviceVar_drainOnError: function(inSender, inError) {
//this.picture_drain.hide();
alert("Drain didn't start. Try again.");
this.button_drain_off.hide();
this.button_drain_on.show();
},
button_drain_offClick: function(inSender) {
this.serviceVar_drainOff.update();
this.button_drain_on.show();
this.button_drain_off.hide();
},
serviceVar_drainOffSuccess: function(inSender, inDeprecated) {
alert("Draining stopped.");
},
serviceVar_drainOffError: function(inSender, inError) {
//this.picture_drain.hide();
alert("Drain didn't stop. Try again.");
this.button_drain_on.hide();
this.button_drain_off.show();
},
//Light
button_light_onClick: function(inSender) {
this.serviceVar_lightOn.update();
this.button_light_off.show();
this.button_light_on.hide();
this.picture_light.show();
},
serviceVar_lightOnSuccess: function(inSender, inDeprecated) {
alert("Light on.");
},
serviceVar_lightOnError: function(inSender, inError) {
this.picture_light.hide();
alert("Light didn't turn on. Try again.");
this.button_light_off.hide();
this.button_light_on.show();
},
button_light_offClick: function(inSender) {
this.serviceVar_lightOff.update();
this.button_light_on.show();
this.button_light_off.hide();
this.picture_light.hide();
},
serviceVar_lightOffSuccess: function(inSender, inDeprecated) {
alert("Light off.");
},
serviceVar_lightOffError: function(inSender, inError) {
this.picture_light.show();
alert("Light didn't turn off. Try again.");
this.button_light_on.hide();
this.button_light_off.show();
},
//Feed
button_feed_onClick: function(inSender) {
this.serviceVar_feedOn.update();
this.picture_feeder.show();
},
serviceVar_feedOnSuccess: function(inSender, inDeprecated) {
alert("Fish Fed!");
this.picture_feeder.hide();
},
serviceVar_feedOnError: function(inSender, inError) {
this.picture_feeder.hide();
alert("Feeder didn't work. Try again.");
},
//Chemical 1
button_chemical_1Click: function(inSender) {
this.serviceVar_chemical1.update();
this.picture_chemical.show();
},
serviceVar_chemical1Success: function(inSender, inDeprecated) {
alert("Optional chemical added!");
this.picture_chemical.hide();
},
serviceVar_chemical1Error: function(inSender, inError) {
this.picture_chemical.hide();
alert("Optional chemical not added. Try again.");
},
//Chemical 2
button_chemical_2Click: function(inSender) {
this.serviceVar_chemical2.update();
this.picture_chemical.show();
},
serviceVar_chemical2Success: function(inSender, inDeprecated) {
alert("Bacteria supplement added!");
this.picture_chemical.hide();
},
serviceVar_chemical2Error: function(inSender, inError) {
this.picture_chemical.hide();
alert("Bacteria supplement not added. Try again.");
},
//Chemical 3
button_chemical_3Click: function(inSender) {
this.serviceVar_chemical3.update();
this.picture_chemical.show();
},
serviceVar_chemical3Success: function(inSender, inDeprecated) {
alert("Water conditioner added!");
this.picture_chemical.hide();
},
serviceVar_chemical3Error: function(inSender, inError) {
this.picture_chemical.hide();
alert("Water conditioner not added. Try again.");
},
_end: 0
});
Java service:
The following is the java service code that runs on the server side of the
webpage.
import com.wavemaker.runtime.javaservice.JavaServiceSuperClass;
import com.wavemaker.runtime.service.annotations.ExposeToClient;
import jssc.SerialPort;
@ExposeToClient
public class grotto extends JavaServiceSuperClass {
public grotto() {
super(INFO);
}
while (true) {
if (serialPort.getInputBufferBytesCount() == 4) {
byte buffer[] = serialPort.readBytes();
int intbit = 0;
intbit = (buffer[3] << 24) | ((buffer[2] & 0xff) << 16) | ((buffer[1] & 0xff) << 8) |
(buffer[0] & 0xff);
Thread.sleep(100);
}
serialPort.closePort();
} catch(Exception e) {
log(ERROR, "The checkTemperature java service operation has failed", e);
}
return result;
}
serialPort.writeBytes("D".getBytes());
serialPort.closePort();
serialPort.writeBytes("d".getBytes());
serialPort.closePort();
serialPort.writeBytes("F".getBytes());
serialPort.closePort();
serialPort.writeBytes("f".getBytes());
serialPort.closePort();
serialPort.writeBytes("L".getBytes());
serialPort.closePort();
result = "Light On";
} catch(Exception e) {
log(ERROR, "The fillTank java service operation has failed", e);
}
return result;
}
serialPort.writeBytes("l".getBytes());
serialPort.closePort();
serialPort.writeBytes("E".getBytes());
serialPort.closePort();
serialPort.writeBytes("e".getBytes());
serialPort.closePort();
serialPort.writeBytes("A".getBytes());
serialPort.closePort();
serialPort.writeBytes("B".getBytes());
serialPort.closePort();
serialPort.writeBytes("C".getBytes());
serialPort.closePort();
#include <Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>
Servo myServo;
#define ONE_WIRE_BUS 5
OneWire oneWire(5);
DallasTemperature sensors(&oneWire);
float Celcius;
float Fahrenheit;
int command = 0;
int drainPin = 4;
int fillPin = 3;
int lightPin = 2;
int eatPin = 6;
int chem1Pin = 8;
int chem2Pin = 9;
int chem3Pin = 10;
void setup() {
sensors.begin();
pinMode(fillPin, OUTPUT);
digitalWrite(fillPin, HIGH);
pinMode(drainPin, OUTPUT);
digitalWrite(drainPin, HIGH);
pinMode(lightPin, OUTPUT);
digitalWrite(lightPin, HIGH);
myServo.attach(6);
myServo.write(0);
//pinMode(E1, OUTPUT);
//pinMode(I1, OUTPUT);
//pinMode(I2, OUTPUT);
pinMode(chem1Pin, OUTPUT);
digitalWrite(chem1Pin, HIGH);
pinMode(chem2Pin, OUTPUT);
digitalWrite(chem2Pin, HIGH);
pinMode(chem3Pin, OUTPUT);
digitalWrite(chem3Pin, HIGH);
Serial.begin(9600);
}
void loop() {
command = Serial.read();
if(command == 70){
digitalWrite(fillPin, LOW);
}else if(command == 102){
digitalWrite(fillPin, HIGH);
}else if(command == 68){
digitalWrite(drainPin, LOW);
}else if(command == 100){
digitalWrite(drainPin, HIGH);
}else if(command == 76){
digitalWrite(lightPin, LOW);
}else if(command == 108){
digitalWrite(lightPin, HIGH);
}else if(command == 69){
myServo.write(179);
//analogWrite(E1, 50);
//digitalWrite(I1, LOW);
//digitalWrite(I2, HIGH);
delay(1000);
myServo.write(130);
delay(1000);
myServo.write(110);
delay(1000);
myServo.write(90);
delay(1000);
myServo.write(0);
//analogWrite(E1, 0);
//digitalWrite(I1, LOW);
//digitalWrite(I2, HIGH);
}else if (command == 65){
digitalWrite(chem1Pin, LOW);
delay(100);
digitalWrite (chem1Pin, HIGH);
}else if (command == 66){
digitalWrite(chem2Pin, LOW);
delay(100);
digitalWrite (chem2Pin, HIGH);
}else if (command == 67){
digitalWrite(chem3Pin, LOW);
delay(100);
digitalWrite (chem3Pin, HIGH);
}else if (command == 84){
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
delay(1000);
serialFloatPrint(Fahrenheit);
}
command = 0;
delay(500);
}
void serialFloatPrint(float f) {
//Serialise data.
byte * b = (byte *) &f;
Serial.write(b[0]);
Serial.write(b[1]);
Serial.write(b[2]);
Serial.write(b[3]);
}