oscP5 library, sending data with network


#1

Hello,

Is there a way to send a csv file about 200KB within oscP5 library?
Does someone know a similar programm about sending these files from an Android phone to a Pc through processing?

Thanks


#2

I’m no expert, but what’s stopping you from sending the entire file as a string through the message system?


#3

Can you describe your setup please and the data flow that you envision happening between your different devices?

If you are getting your data from a server, via an url, then you can use loadStrings(). If you are working with computers in a local network and one computer is always feeding the data, then you can set that computer as a server by setting a local server and then stick to loadStrings() (Untested). Now, if this is done between android devices, this approach might not work. Instead, I will stick to oscP5 or websockets.

Some other topics I found online:

https://forum.processing.org/two/discussion/9090/processing-and-android-how-to-transfer-pictures

https://forum.processing.org/two/discussion/8860/android-pc-udp-communication

If you use oscP5, notice there is a limit on the size of data on a transaction. Hence, you will need to break your file into pieces and send them one by one and stitch them together at the other end. The oscP5 also has an option to establish a TCP connection, which it would be more reliable than using the default UDP protocol. Notice I have not tested the oscP5 TCP version in android, so take my comment with a grain of salt. From what I read, suing a TCP is more convenient as the TCP should be able to handle the breaking up of the packages into the right size for you. Again, this is untested and hopefully somebody in the community can share their experiences here.

Found some other relevant posts:

Server & Client

Server->client reply

They are not a final solution unfortunately. Hopefully all these post will help with putting together a simple example.

Kf


#4

Thank so much for you response,

In my program/app i have a ketailist which represents the csv files that i want to load. So everytime i choose a name from the list which is a csv file and i load it and make it a graph.
Notice that the csv files are tables with two values, the values that i represent with the graph.
My issue is that i could send whenever and any csv file i want from my Android device to laptop with wifi…


#5

how will i declare a csv file as a string???
Like String (“123.csv”); ???


#6

The easiest is to load your data to your phone using an external app like shareit or pushbullet. You can also send the file to yourself via email and download the data to your phone. Then you could load the file from your local storage drive.

If you want to do this programatically, then there are few ways:

  • Use something like googledocs. You load the file to their online structure and then you retrieve the file. Notice this requires to get some credential validation and read their documentation. They should have a Java SDK to access and consume their resources.
  • The server option, as I mention above (untested but should work)
  • Using UDP or oscP5, but this requires a little bit of research and testing. I did a quick online search yesterday and there were not many posts addressing this topic
  • Websockets is another option

From your last message, I see you have a ketai list and you have a 2-column csv. Can you provide more details about the nature of the transaction? Like you want your app to access your PC files via your local network? You need to have one program running in the PC and one running in your Android, correct? The current program that you have for these devices, what does it do?

Kf


#7

As i have mentioned in the this program : Geolocation and Osc Message i wll sent the three values longitude, latitude, altitude with oscP5 library through wifi.
Ι want to sent the csv files that there are in the Android phone at the same time in the PC and if its possible and with the same or similar way. Yes of course, with this way i have a one program running in the PC and one running in your Android.
Finally my current program loads 2-column csv files, which are listed in a ketailist in my Android app and i want to send each csv file everytime i choose each file from the list.
Thanks


#8

Ok, so there is a better picture now. Based on the ideas proposed above, I’d recommend oscP5. It might not be the best solution when it comes to file data transfer, but it will keep your code base simpler (not adding complexities by choosing other data transfer concepts) and you could keep your code in the same terms as standard Processing format and using provide libraries.

What you need to do is to work in your server and client code. I believe you already have the structure layout to transfer (GPS coordinate) data between your PC and device. Now, your challenge is to create a separate layer that allows you to retrieve not only the file names available to share but also to trigger the transfer, on one side, and to assemble the files in the other end.

The first thing is to take your data and store it in a String variable. Then you send the data as bytes using oscP5. Give it a try and see if it works. Let us know if it works the first time or show us the issues you encounter and we can assist based on the code you provide.

Something that you need to clarify: Is the data transfer one way or bi-directional?

Kf


#9

First that is what i had in my mind from beginning but i have no idea how to start…How will i take my data and store them in a String variable??
And yes the data transfer one way, from Android device to PC.


#10

I would start off using the loadStrings() method to load all your data in from the .csv into an ArrayList of Strings.


#11

I would not recommend using one string variable for structured data like a csv. Instead you could use the fields in OSC messages. One approach is to careful walking through the available examples and test each part of your process separately, before assembling the two program that handle the whole transfer:

  1. load your csv file as a Table https://processing.org/reference/loadTable_.html
  2. loop over the rows https://processing.org/reference/Table_rows_.html
  3. build an osc message as per the oscP5 message example http://www.sojamo.de/libraries/oscP5/examples/oscP5message/oscP5message.pde
  4. the contents of the message should be the fields you retrieved from the Table Row. https://processing.org/reference/TableRow.html
  5. …if your row order matters, you may also want to give each row message ID if it doesn’t already have one, as network packet order arrival isn’t always guaranteed.

Now receive your row messages on the other end http://www.sojamo.de/libraries/oscP5/examples/oscP5sendReceive/oscP5sendReceive.pde

…and parse them for use or saving in whatever way you like – e.g. either by hand or using plug:

However, if you can cram the complete text of your csv file into a single OSC message field, then modify the above steps accordingly (that is, use loadStrings(), and loop over the array, rather than using Table) and go for it!


#12

I have done the 1,2,3 steps but i do not understand bellow steps…
Could you please apply them into the next similar example code???

type or paste coimport grafica.*;

GPlot plot;

void setup() {
  // Define the window size
  size(750, 410);

  // Load the cvs dataset. 
  // The file has the following format: 
  // country,income,health,population
  // Central African Republic,599,53.8,4900274
  // ...
  Table table = loadTable("data.csv", "header");

  // Save the data in one GPointsArray and calculate the point sizes
  GPointsArray points = new GPointsArray();
  float[] pointSizes = new float[table.getRowCount()];
  
  for (int row = 0; row < table.getRowCount(); row++) {
    String country = table.getString(row, "country");
    float income = table.getFloat(row, "income");
    float health = table.getFloat(row, "health");
    int population = table.getInt(row, "population");
    points.add(income, health, country);
    
    // The point area should be proportional to the country population
    // population = pi * sq(diameter/2) 
    pointSizes[row] = 2 * sqrt(population/(200000 * PI));
  }

  // Create the plot
  plot = new GPlot(this);
  plot.setDim(650, 300);
  plot.setTitleText("Life expectancy connection to average income");
  plot.getXAxis().setAxisLabelText("Personal income ($/year)");
  plot.getYAxis().setAxisLabelText("Life expectancy (years)");
  plot.setLogScale("x");
  plot.setPoints(points);
  plot.setPointSizes(pointSizes);
  plot.activatePointLabels();
  plot.activatePanning();
  plot.activateZooming(1.1, CENTER, CENTER);
}

void draw() {
  // Clean the screen
  background(255);

  // Draw the plot  
  plot.beginDraw();
  plot.drawBox();
  plot.drawXAxis();
  plot.drawYAxis();
  plot.drawTitle();
  plot.drawGridLines(GPlot.BOTH);
  plot.drawPoints();
  plot.drawLabels();
  plot.endDraw();
}de here

#13

If your question is just about retrieving rows from a Table, you can’t do table.getFloat() – you have to first retrieve a TableRow (TableRow row = table.getrow()), then retrieve a field from that row (int cell = row.getInt().

I recommend reading through the reference examples, combining them, and modifying them.

Also, if you want to share a Table sketch for feedback, please provide a few rows of the text data file so that it can be run by someone else.

Could you share what you have done for step 3? I don’t see OSC at all in the code you shared.


#15
import grafica.*;
import ketai.net.*;
import oscP5.*;
import netP5.*;


OscP5 oscP5;
NetAddress remoteLocation;


GPlot plot;

//Table table;

void setup(){
  fullScreen();
  
  oscP5 = new OscP5(this, 12000);
  remoteLocation = new NetAddress("192.168.1.2", 12000);
  
  
 Table table=loadTable("data.csv","header");
  table.setColumnType("Intensity", Table.FLOAT);
    table.setColumnType("Time", Table.FLOAT);
     GPointsArray points = new GPointsArray();
  float[] pointSizes = new float[table.getRowCount()];
  
  for (int row = 0; row < table.getRowCount(); row++) {
    float Time = table.getFloat(row,"Time");
   float Intensity = table.getFloat(row, "Intensity");
   
   points.add(Time, Intensity);// add the points x,y from the table (the two values)   
    pointSizes[row] = 0.1;  //determine the size of rows
  }
  
  
   plot = new GPlot(this);
  plot.setDim(800, 500);// set the position of the plot on the screen
  plot.setPoints(points);  //add the points in the plot
  plot.setPointSizes(pointSizes);  // set the size of points that determined above
  plot.activatePointLabels();
  plot.activatePanning();  // activate the panning effect
  plot.activateZooming(1.1, CENTER, CENTER);
 }
 
 void draw() {
  background(255);
  // Draw the plot  
  plot.beginDraw();
  plot.drawBox();
  plot.drawXAxis();
  plot.drawYAxis();
  plot.drawTitle();
  plot.drawGridLines(GPlot.BOTH);
  plot.drawPoints();
  plot.drawLabels();
  plot.drawLines();
  plot.endDraw();


OscMessage myMessage = new OscMessage("data.csv");
      myMessage.add("data.csv");
    oscP5.send(myMessage, remoteLocation);
}


void oscEvent(OscMessage theOscMessage) {


  /* print the address pattern and the typetag of the received OscMessage */
  print("### received an osc message.");
  print("data.csv");
   println(" typetag: "+theOscMessage.typetag());
}  
  
 

 

#16

A the data format is the below csv file :

Time,Intensity
10,0.2
20,0.4
30,0.4
40,0.3
50,0.6
60,0.6
70,0.9
80,0.7
90,0.5
100,0.5
110,0.3
120,0.1
130,0.3
140,0.5
150,0.6
160,0.4
170,0.3
180,0.1
190,0.1
200,0.2
210,0.2
220,0.3
230,0.1
240,0.2
250,0.5
260,0.6
270,0.6
280,0.7
290,1.2
300,1.3
310,1.1
320,0.9
330,0.6
340,0.6
350,0.5
360,0.3
370,0.3
380,0.1
390,0.1
400,0.2
410,0.4
420,0.4
430,0.6
440,0.6
450,0.7
460,0.7
470,0.7
480,0.9
490,1
500,0.8
510,0.5
520,0.5
530,0.2
540,0.2
550,0.2
560,0.1
570,0.1
580,0.1
590,0.2
600,0.2
610,0.2
620,0.6
630,0.6
640,0.5
650,0.5
660,0.5
670,0.8
680,0.8
690,0.9
700,0.9
710,0.9
720,0.9
730,1.2
740,1.6
750,1.3
760,1.1
770,0.8
780,0.8
790,0.8
800,0.5
810,0.3
820,0.3
830,0.1
840,0.1
850,0.2
860,0.2
870,0.2
880,0.5
890,0.5
900,0.7
910,0.8
920,0.8
930,0.9
940,0.9
950,0.9
960,1.2
970,1.4
980,1.1
990,1
1000,0.8
1010,0.8
1020,0.7
1030,0.5
1040,0.5
1050,0.2
1060,0.2
1070,0.1
1080,0.1
1090,0.3
1100,0.5
1110,0.6
1120,0.9
1130,1.2
1140,1.8
1150,1.6
1160,1.5
1170,1.2
1180,1.1
1190,0.9
1200,0.9
1210,0.7
1220,0.5
1230,0.3
1240,0.1
1250,0.3
1260,0.5
1270,0.6
1280,0.4
1290,0.3
1300,0.1
1310,0.1
1320,0.2
1330,0.2
1340,0.3
1350,0.1
1360,0.2
1370,0.5
1380,0.6
1390,0.6
1400,0.7
1410,1.2
1420,1.3
1430,1.1
1440,0.9
1450,0.6
1460,0.6
1470,0.4
1480,0.6
1490,0.6
1500,0.5
1510,0.5
1520,0.3
1530,0.2
1540,0.2
1550,0.3
1560,0.5
1570,0.5
1580,0.2
1590,0.2
1600,0.2
1610,0.1
1620,0.1
1630,0.1
1640,0.2
1650,0.2
1660,0.2
1670,0.6
1680,0.6
1690,0.7
1700,1.2
1710,1.3
1720,1.1
1730,0.9
1740,0.6
1750,0.6
1760,0.5
1770,0.3
1780,0.3
1790,0.1
1800,0.1
1810,0.2
1820,0.1
1830,0.1
1840,0.2
1850,0.2
1860,0.2
1870,0.5
1880,0.5
1890,0.7
1900,0.8
1910,0.9
1920,1.2
1930,1.4
1940,1.1
1950,1
1960,0.7
1970,0.7
1980,0.3
1990,0.3
2000,0.2

#17

Okay, thanks for the sketch and data. I now see that you are using the table.getTYPE(row, "Field") for access, and that you are drawing a graph.

I recommend not running in fullScreen so that you can actually see the OSC console logs in PDE.

size(400,400);

It looks like you are trying to send the whole file as a single message, rather than one per row.

Is it now working, and is this your solution?

If not – What does your host do? What do your client and host logs say?


#18

The above code is working in my mobile…I have complied it in Android mode to my smartphone…
I do not know if i can declare as “data.csv” into the oscMessage or i have to find another way to send all the data file as oscMessage. I tried with this method but the whole file was not sent…My client is my phone which sents the messages to the server (my PC). My PC recieves the “data.csv” as a name not the values from the file. How can i send the content of “data.csv”, the content of the cvs file, all rows…???


#19

`myMessage.add(“data.csv”) is sending a string, “data.csv”. If you want a string with the contents of a file data.csv, then you should load the contents of the file:

https://processing.org/reference/loadStrings_.html

and then join the String[] array you get back (one per line) into a single string, using joiin:

https://processing.org/reference/join_.html


#20

Notice that i want to add have a ketailist which represents the csv files that i want to load. So everytime i choose a name from the list which is a csv file and i load it and make it a graph. So everytime i load different csv file… @jeremydouglass if i do these that you are talking about i see the data of the csv file in the console…I want to make a loop which i can call everytime to load a different file and then sent it…


#21

Well, I am familiar with the Processing API but have no specific experience on Android. If you are having trouble loading a file into a string variable myFileString and then putting that variable into myMessage.add(myFileString) – then I think someone Android-familiar may be able to give you better advice.