Currently i am developing Prototype of Air quality monitoring device using Arduino. The device integrated with three gas sensors that will send the the data over the HC-05 bluetooth module to my android app. I am able to receive the values in real time and display it using textview but have no idea on have to save the data in android device itself using SQL database. I have tried all tutorials that i found elsewhere but it only save data on a button click, but even when trying the buttonclick method the app crashes (instead i want to save the data continuously on the background,every time the app starts). I am very new to android development, please help me.
Currently i need to save (time/date, gps coordinate, sensor1 data, sensor2 data, sensor3 data, overall air quality).
I am sorry, already removed the SQL storing part, here the code for get real time data from Arduino.
//data received from Arduino as #data+data+data+~
bluetoothIn = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == handlerState) { //if message is what we want
String readMessage = (String) msg.obj; // msg.arg1 = bytes from connect thread
recDataString.append(readMessage); //keep appending to string until ~
int endOfLineIndex = recDataString.indexOf("~"); // determine the end-of-line
if (endOfLineIndex > 0) { // make sure there data before ~
String dataInPrint = recDataString.substring(0, endOfLineIndex);
if (recDataString.charAt(0) == '#') //if it starts with # we know it is what we are looking for
{
dataInPrint = dataInPrint.substring(1, dataInPrint.length() - 1); //remove the Hash tag symbol
StringTokenizer st = new StringTokenizer(dataInPrint,"+");
String sensor0 = st.nextToken();
String sensor1 = st.nextToken();
String sensor2 = st.nextToken();
showMq135.setText(sensor0); //update the textviews with sensor values
showMq9.setText(sensor1);
showDust.setText(sensor2);
p1 = (ProgressBar) findViewById(R.id.progressBarMq135);
int p135 = Integer.parseInt(sensor0);
p1.setMax(100);
p1.setProgress(p135);
p2 = (ProgressBar) findViewById(R.id.progressBarMq9);
int p9 = Integer.parseInt(sensor1);
p2.setMax(100);
p2.setProgress(p9);
p3 = (ProgressBar) findViewById(R.id.progressBarDust);
int pDust = Integer.parseInt(sensor2);
p3.setMax(100);
p3.setProgress(pDust);
if (p135 >= 51 || p9 >= 51 || pDust >= 51) {
showAirQuality.setTextColor(Color.RED);
showAirQuality.setText("Hazardous/Very unhealthy");
sound.start();
}
else {
showAirQuality.setTextColor(Color.BLUE);
showAirQuality.setText("Normal/Intermediate");
}
}
recDataString.delete(0, recDataString.length());//clear all string data
}
}
}
};