I've been basing both programs off of the SerialCallResponse example in Arduino 1.0 (
http://arduino.cc/en/Tutorial/SerialCallResponse ) to get them to talk. Perhaps it was never meant for something like this though.
In a nutshell, I want to first send 15 Arduino sensor values to Processing; then write 6 Processing values to the Arduino; lastly, I was looking to return those last 6 values to Processing to confirm that they were recorded.
Any advice or corrections would be greatly appreciated. I've been struggling with this for a bit now. At any rate here are the println responses generated through my debugging efforts:
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
firstContact == false
inByte == 'A'
secondContact == false
thirdContact == false
didn't receive sensor data
goes on like this for a while
didn't receive sensor data
secondContact == false
thirdContact == false
138 //confirmation of the first value in the array received
serialCount == 15; 'Z' has been given to arduino; it should begin getData() now
secondContact == false
thirdContact == false
firstContact == false
inByte == 'A'
secondContact == false
thirdContact == false
didn't receive sensor data
goes on like this for a while
thirdContact == false
didn't receive sensor data
secondContact == false
inByte == 'B' + 'B'
thirdContact == false
didn't receive sensor data
secondContact == true
weather and preferences and 'Y' have been sent to arduino
thirdContact == false
didn't receive sensor data
secondContact == false
goes on like this for a while
thirdContact == false
didn't receive sensor data
secondContact == false
inByte == 'B' + 'B'
thirdContact == false
didn't receive sensor data
secondContact == true
weather and preferences and 'Y' have been sent to arduino
thirdContact == false
didn't receive sensor data
secondContact == false
goes on like this for a while
didn't receive sensor data
secondContact == false
thirdContact == false
didn't receive sensor data
secondContact == false
thirdContact == false
131
serialCount == 15; 'Z' has been given to arduino; it should begin getData() now
secondContact == false
thirdContact == false
firstContact == false
goes on like this for a while
thirdContact == false
firstContact == false
secondContact == false
inByte == 'B' + 'B'
thirdContact == false
firstContact == false
secondContact == true
weather and preferences and 'Y' have been sent to arduino
thirdContact == false
firstContact == false
secondContact == false
goes on like this for a while
secondContact == false
thirdContact == false
firstContact == false
secondContact == false
inByte == 'B' + 'B'
thirdContact == false
firstContact == false
secondContact == true
weather and preferences and 'Y' have been sent to arduino //it's odd that it's skipping
thirdContact == false
firstContact == false
secondContact == false
thirdContact == false
firstContact == false
secondContact == false
inByte == 'B' + 'B'
thirdContact == false
firstContact == false
secondContact == true
weather and preferences and 'Y' have been sent to arduino
thirdContact == false
firstContact == false
secondContact == false
inByte == 'B' + 'B'
thirdContact == false
firstContact == false
secondContact == true
weather and preferences and 'Y' have been sent to arduino
thirdContact == false
firstContact == false
secondContact == false
goes on like this for a while
thirdContact == false
firstContact == false
secondContact == false
inByte == 'B' + 'B'
thirdContact == false
firstContact == false
secondContact == true
weather and preferences and 'Y' have been sent to arduino
In the PostgreSQL example for the SQLibrary (
http://bezier.de/processing/libs/sql/ ), it says that the example only works if the DB is on the local network. I can't seem to find anything in the documentation that suggests a way to differentiate the code to facilitate a remote-connection away from the local network.
Does anyone know if this can be done, or how?
PostgreSQL Example:
// updated fjenett 20081129
import de.bezier.data.sql.*;
PostgreSQL pgsql;
void setup()
{
size( 100, 100 );
// this example assumes that you are running the
// postgresql server locally (on "localhost").
//
// replace with your own postgresql-account.
//
String user = "fjenett";
String pass = "fjenett";
// name of the database to use
//
String database = "test";
// connect to database on "localhost"
//
pgsql = new PostgreSQL( this, "localhost", database, user, pass );
// connected?
if ( pgsql.connect() )
{
// query the number of entries in table "weather"
pgsql.query( "SELECT COUNT(*) FROM weather" );
// results found?
if ( pgsql.next() )
{
// nice, then let's report them back
println( "number of rows in table weather: " + pgsql.getInt(1) );
}
// now let's query for last 10 entries in "weather"
I'm using Processing to read sensor values from an Arduino via com port. Everything seems to work fine for a couple of hours or so, but eventually one of the last values in the array
String[] readList = splitTokens(getRawArduino);comes back null and causes a java.lang.ArrayIndexOutOfBoundsException at 11, 12, 13 or 14. Usually it happens at 11 though. The following variables are the source of the null values, and are all coming from the SHT15 temp/humidity sensor:
temp_c_indoor = float(readList[11]);
temp_f_indoor = float(readList[12]);
dewpoint_f_indoor = float(readList[13]);
relative_humidity_indoor = float(readList[14]);
Once in a while the sensor will return 0.0000 causing the null in processing. I'm trying to implement a try() and catch() function to deal with this, but I'm not understanding how it's set up and I'm hoping somebody can point out what I'm doing wrong.
void draw(){
if (lastQueryTime + 600000 > millis() && lastQueryTime < 100){
getXML();
doQueryExecuteDB();
lastQueryTime = millis();
}
if (arduinoCom + 120000 < millis()){
try{
nullException = readList.readArduino();
}
catch (ArrayIndexOutOfBoundsException) {
nullException = null;
}
if (nullException == null){
noLoop();
}
else{
readArduino();
}
writeArduino();
doWriteArduinoDB();
arduinoCom = millis();
}
if (lastQueryTime + 600000 < millis()) {
getXML();
doQueryExecuteDB();
lastQueryTime = millis();
}
}
void readArduino(){
//get the sensor and actuator data from the serial port
Is there a way to project updated values into a SQL command string? I'm accessing web-based XML data every ten minutes and want to write it to my PostgreSQL DB.
This would be the example command to write to DB:
pgsql.execute(INSERT INTO table (column1, column2, etc) VALUES (value1, value2, ect));
For these variables:
String station_location_xml;
String observation_time_xml;
String temp_f_xml;
String temp_c_xml;
String relative_humidity_xml;
String wind_degrees_xml;
String wind_dir_xml;
String wind_mph_xml;
String wind_gust_mph_xml;
String dewpoint_f_xml;
String dewpoint_c_xml;
I want to write into the DB, which could look like:
I would like to write data to my PostgreSQL DB using SQLibrary.
First off, is it capable of doing that? I've had success querying the DB using this library, but there doesn't seem to be much documentation on writing to a DB using it. I've tried using pgsql.execute but get this error:
SQL.query(): java.sql.SQLException.
org.postgresql.util.PSQLException: ERROR: syntax error at end of input
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1608)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1343)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:194)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:336)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:328)
at de.bezier.data.sql.SQL.execute(Unknown Source)
at dbQuery_XMLFeed.manipulateDB(dbQuery_XMLFeed.java:234)
at dbQuery_XMLFeed.draw(dbQuery_XMLFeed.java:56)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
The fact that it says "SQL.query():" leads me to think that this library only queries.
If it is possible, could someone provide an example?
Additionally, I want the program to make certain decisions based on the data and send/receive data to an Arduino through the serial com port.
I'm not terribly concerned about the decision making methods that will take place in the app. It's the communication between program-URL and program-DB, as well as the conversion of XML that I'm unsure about. I would really appreciate any advice, or being pointed to the right resources.