This is the documentation of the Ship Survailance Application.
The application is a Java application running on a Asue Eee Pc at the ship.
Java App for Ship Daemon
Installing
The application comes as a single .jar-file. It does, however need a few things to run on a new pc:
General: If you have installed the Processing or Arduino environment on a computer, and it succesfully can comminicate with the serial port, then this, the ship survailance application will work too.
Arduino installing
Just install the "Standard Firmata" firmware on the Arduino board. You can do that from the Arduino IDE.
Starting up
The main window
Google Talk
- Write username and password of the user (illutronshipdaemon@gmail.com)
- "Connect to Google Talk"
- Friends - Add and remove friends of the daemon
Arduino
- "Get Ports" to get the serial ports on the system and select. Try to guess the correct number
- NB: There is a error, if you plug in or rip out the usb cable of the Arduino while the application is running
- "Connect to Arduino" - Obviously connects to the Arduino Board
- "View Arduino" - See the status of ports and set pinmodes
View Arduino Dialog
Event script
This is the script, that monitor sensors (Arduino values) and send message to recipients in case of events.
- "Run" to start checking every 1000 millisecond (default, can be changed)
- "Stop" to stop
- "Open file.." and "Save as.." to handle existing scripts
- "Edit.." opens the script editor
Script editor
Always use: "Test this" to do a test parsing of the script in the editor, to make sure it runs.
Response script
This script is fired, when someone writes a message to the Daemon.
The script is used to filter incoming messages, do action or get data, and send a response.
- "Start listening" - to start listening and responding to incoming chat messages
- "Stop" to stop
- "Open file.." "Save as.." and "Edit.." - As for the event scripts
Scripting - How toThe scripting language is JavaScript. With some reserved functions and variables to handle Arduino Data and messages.
Common commands (for both event scripts and response scripts)
Value |
Explaination |
Code example |
(int) analog[n]
n : [0..5] (int) |
Get the value of analog pin n.
returns [0..1023] (int) |
if (analog[1] > 600) {
...
} |
(int) digital[n]
n : [2..13] (int) |
Get the value of digital pin n
returns 0 or 1.
- pin 0 and 1 reserved for rx,tx of serial
- Pinmode has to be set correctly
|
if (digital[12] == 0) {
...
} |
digitalwrite[n] = x
n : [2..13] (int)
x : [0..1] (int) |
Sets the value of digital pin n to either 0 or 1.
- pin 0 and 1 reserved for rx, tx
- Pinmode has to be set correctly
|
digitalwrite[13] = 1;
|
analogwrite[n] = x
n : [3,5,6,9,10,11] (int)
x : [0..255] (int) |
Sets the PWM value of the pins that support PWM. |
analogwrite[10] = 200; |
scriptmemory_int[n] = x
n : [0..30] (int)
x : (int) |
Sets a value, that is to be remembered at the next run of the script.
- Used to keep track of state or do counters
|
// FlipFlop
if (scriptmemory_int[1] == 0) {
digitalwrite[13] = 0;
scriptmemory_int[1] = 1;
} else {
digitalwrite[13] = 1;
scriptmemory_int[1] = 0;
}
|
status[0] (String) | Sets the online status message of the daemon | if (incoming == "be happy"){ digitalwrite[13] = 1; status[0] = "Don't worry"; response[0] = "I won't worry now"; } |
Event script commands
Method |
Explaination |
Code example |
message[n] = "bla bla"
n : [0..30] (int) |
Sets the message text that is to be sent at an event.
30 different messages can be constructed in one script. |
|
messagerecipients[n] = (String)
n : [0..30] (int) |
Sets the receivers of message[n]
- "ALL" - message[n] is sent to all friends
- "nnn@gmail.com,xxx@gmail.com" - message[n] is sent to the specific users nnn@gmail.com and xxx@gmail.com
- comma between emails
|
if (analog[2] > 400){
message[5] = "analog 2 is above 400";
messagerecipients[5] = "ALL";
}
if (analog[2] < 400){
message[5] = "analog 2 is below 400";
messagerecipients[5] = "chrlilje@gmail.com";
} |
Response script commands
Again - normal Javascript. Some commands are the same as for event script
Value |
Explaination |
Code example |
incoming (String)
|
Get a string containing the message that a user has sent to the Daemon. |
|
response[0] (String)
|
Sets the string of the response to send to the user, that wrote incoming message |
if (incoming == "start pump"){ digitalwrite[13] = 1; response[0] = "Pump started";
}
if (incoming == "stop pump"){ digitalwrite[13] = 0; response[0] = "Pump stopped"; }
|
Known issues- If the program wont run, it can be a hanging serial port that blocks it. Restart windows or kill the process blocking the serial port.
- Clicking "Connect" multiple times on Google Talk and Arduino has uncertain effects
- Getting serial ports using "Get ports" can sometimes take very long time. Just wait.
- The application does not always shut down correctly leading to a need to kill processes or restart the computer.
|
|