So i've got a few CrazyFlies that i'm hoping to use to stream parameter values to a web server. The hope is to really make the quadcopters "IoT"ized, but to start I just want to send acceleration data.
I need to be able to repeatedly and quickly access a parameter and then send that data with a POST request. What i've tried so far...
Creating a log block that I write to file with the default Crazyflie PC software. I then used a java program to read the last line of the file and send that value. That worked great except that the file is not updated very rapidly. If I understand how it's working correctly, a group of values is written into the file every few seconds. This makes my last-line program only update with a new value every few seconds, which is not fast enough for me.
Which brings me to the question...
If I wanted to be able to access a parameter value constantly (or increase the speed that the csv file is written) how would I do that? I am also open to the idea of modifying crazyflie pc software so that this process happens automatically (although i'm not looking to do a lotttt of work).
The program I made is below...
Code: Select all
package file_read;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import file_read.SentToThingWorx;
public class FileReader {
public static String readLastLine(String filename) throws IOException {
FileInputStream in = new FileInputStream(filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLastLine = "";
String tmp;
while ((tmp = br.readLine()) != null)
{
strLastLine = tmp;
}
String[] strArray = strLastLine.split(",");
System.out.println(strArray[1]);
in.close();
return strArray[1];
}
public static void main(String [] args) throws IOException{
String filename = "D:/Users/mcheli/AppData/Roaming/cfclient/logdata/20151002T14-32-59/TWX_TEST-20151002T14-34-16.csv";
while(true){
SentToThingWorx.send(readLastLine(filename));
}
}
}
Code: Select all
package file_read;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class SentToThingWorx {
public static void send (String Data) {
URL url;
String urlToRead;
HttpURLConnection conn;
BufferedReader rd;
String line;
String result = "";
urlToRead = "http://acadev1.cloud.thingworx.com/Thingworx/Things/jocox_training_thing/Services/Write?appKey=[omitted]&method=post&x-thingworx-session=true<&Data=" + Data; //Mark look here, change to my thingworx server
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result += line;
}
rd.close();
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println(result);
return;
}
}