Languages

Menu
Sites
Language
Export sensor data as csv file in Samsung gear 2

Hi,
I am developing Tizen Wearable Web app with Samsung gear 2

I want to collect Accelerarator and Gyro data by deviceMotion Event
and export data as a csv file to the gear 2 stoarge.
(Even if gear2 is not connected with mobile device)
When I put the start button, it will begin to export data as a csv file
until I put the end button.

My main problem is :
(1) I try to implement by javascript from some resource on the Internet
But the most of the searching result is not what I want. It seems that most
of the example export table (on the HTML which is input by user) as csv file.
Like this : http://www.raymondcamden.com/demos/2014/apr/3/testdownload.html

(2)I had tried some example like (1) metion. But when I input some data in
the table and export it as a csv file. I cannot find the file which I have just
exported! (I check it in the gear storage) I can't find the output csv file on the
gear device but I can run normally on my browser(Chrome)

How can I fix my problem ?

Thanks for all in advance!

Responses

12 Replies
ChiehHsin Chen
OK
ChiehHsin Chen

I'm so sorry to repost the same articles Can the host help me to delete it ? Thanks.

Why csv?

Why not JSON?

Your widget has a "private local storage", your file probably stored there

When you create the "File", where do you create it? Why don't you save it under location you choose?

How can we help you without sample of the code?

Rob Guinness

I am interested to do basically the same thing, so please post here if you find a solution. Thanks!

ChiehHsin Chen

Hi, the related solution please refer to my related post : https://developer.tizen.org/forums/general-support/gear-2-tizen-file-system-api-fail-write Just change test.txt into text.csv and you can do what you want to do. Hope this could help.

Sniper

Hi Chen,

I am also trying to do the same thing. I need to collect the Accelerometer Data and Gyroscope Data by 'devicemotion' event. I am able to save the data into Index DB database. I was trying to read the data from database and save it into txt file. The Problem is the event listener is keeping inserting data into database and while I am reading the data It seems I am getting part of the data, not full data in the database. Do I need to read in different thread? Is it possible to implement multithreading in JavaScript? Any suggestion for me? Thanks in Advance.

colin Rao

Please refer to the help doc. Tizen Mobile Web App Programming > Programming Guide > W3C/HTML5 Guides > Performance and Optimization GuidesWeb Workers (Partial) 

see the Multi-threading section.

Sniper

Hi Colin,

Thanks for your reply. I need some more help. I need to read part of the data (I am saving timestamp in Indexed DB, I need to read all the data within the given timestamp range) from database and save it in a file. I am wondering how can I perform the query in Index DB. I am pretty new in Tizen development. I have another basic question, I want to post questions in this developer site, but I am unable to find any option or button for that. I appreciate any help.

Thanks in advance! 

daniel kim

Hi,

I wish this link will help you to perform the query using index.

http://www.w3.org/TR/IndexedDB/

 

and you can find "New topic" button to post new question in this site

Sniper

Hi,

Thanks for quick reply. I was trying to save data from a IndexDB object store to a file in the following manner. But I am getting "IOError: Stream is closed." while reading from cursor and trying to write the string to the file in line 40 (

fs.write(string); //getting error at this line

)

any idea why I am getting this error? Thanks In Advance 

$("#exportall").click(function() {
    			
				var documentsDir;
				function onresolveerror(error) 
				{
					console.log("The error " + error.message
							+ " occurred when listing the files in the selected folder");
				}
				function onresolvesuccess(files) 
				{

					var d = new Date().getTime();
					//console.log(d + ".txt");

					var testFile = documentsDir.createFile(d + ".txt");

					if (testFile !== null) 
					{
						testFile.openStream("rw", function(fs) {
							try {
								
								/*var i=0;  //this testing works fine and writes to the file
								for(i=0;i<10000;i++)
								{
									fs.write(1420579156522+" "+ -1.31605+" "+\n");																	
								}*/
								
								var string="";
								
								var objectStore = db.transaction([ "mydb" ], "readonly").objectStore("mydb");

								var index = objectStore.index("id");

								index.openCursor().onsuccess = function(event) {
									var cursor = event.target.result;
									if (cursor) {
										string=cursor.key+" "+cursor.value.x+"\n";
										console.log(string);										
										fs.write(string); //getting error at this line
										cursor.continue();
									}
									else {
										console.log("No more entries.");
									}
								};
																
								console.log(fs.position);
								fs.close();
								
							} 
							catch (err) 
							{
								console.log("exception [" + err.name + "] msg[" + err.message
										+ "]");
							}
						}, function(e) {
							console.log("Error " + e.message);
						}, "UTF-8");

					}
				}
				
				tizen.filesystem.resolve('documents', function(dir) {
					documentsDir = dir;
					dir.listFiles(onresolvesuccess, onresolveerror);
				}, function(e) {
					console.log("Error" + e.message);
				}, "rw");
			});

 

 

Marco Buettner

Try "w" instead "rw".... New file (without content) can not read

Sniper

Actually I solved the problem by closing the file when the cursor becom empty!

Thnaks for reply :-)