Send/Recieve files

edited May 16 in Android Mode

Hello, i would like to know if there is a way in processing i3 to send and recieve data files. as csv files between android phone and pc through Wi-Fi..Actually i tried to communicate them with oscP5 library and i can send/recieve messages..But what about csv files???

Comments

  • edited May 16

    i want to send the OktoberfestVSGermanElections.csv file, when i push the button(Message).This is my code bellow:

        import ketai.net.*;
        import ketai.net.bluetooth.*;
        import ketai.net.nfc.*;
        import ketai.net.nfc.record.*;
        import ketai.net.wifidirect.*;
        import ketai.sensors.*;
        import ketai.ui.*;
    
        import oscP5.*;
        import netP5.*;
        import grafica.*;
    
    
        OscP5 oscP5;
        NetAddress remoteLocation;
    
        double longitude, latitude, altitude;
        KetaiLocation location;
    
        Button on_button;  // the button
        int clk = 1;  
    
    
        String[] monthNames = new String[] {"January", "February", "March", "April", "May", "June", "July", 
                                             "August", "September", "October", "November", "December"};
        int[] daysPerMonth = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[] daysPerMonthLeapYear = new int[] {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
        GPlot plot;
    
        void setup() {
          fullScreen();
          //size(800, 410);
          orientation(LANDSCAPE);
          textAlign(CENTER, CENTER);
        textSize(22);
    
         location = new KetaiLocation(this);
    
        oscP5 = new OscP5(this,19000);
           on_button = new Button("Message", 850, 360, 150, 100);
        remoteLocation = new NetAddress("192.168.1.2",19000);
    
          // Load the Oktoberfest vs. Bundestagswahl (German elections day) Google 
          // search history file (obtained from the Google trends page). 
          // The csv file has the following format: 
          // year,month,day,oktoberfest,bundestagswahl
          // 2004,0,1,5,1
          // ...
          Table table = loadTable("OktoberfestVSGermanElections.csv", "header");
          table.setColumnType("year", Table.INT);
          table.setColumnType("month", Table.INT);
          table.setColumnType("day", Table.INT);
          table.setColumnType("oktoberfest", Table.INT);
          table.setColumnType("bundestagswahl", Table.INT);
    
          // Save the data in two GPointsArrays
          GPointsArray pointsOktoberfest = new GPointsArray();
          GPointsArray pointsElections = new GPointsArray();
    
          for (int row = 0; row < table.getRowCount(); row++) {
            int year = table.getInt(row, "year");
            int month = table.getInt(row, "month");
            int day = table.getInt(row, "day");
            float date = getExactDate(year, month, day);
            int oktoberfestCount = table.getInt(row, "oktoberfest");
            int electionsCount = table.getInt(row, "bundestagswahl");
    
            pointsOktoberfest.add(date, oktoberfestCount, monthNames[month]);
            pointsElections.add(date, electionsCount, monthNames[month]);
          }
    
          // Create the plot
          plot = new GPlot(this);
          plot.setDim(700, 300);
          plot.setTitleText("Oktoberfest vs. Bundestagwahl Google search history");
          plot.getXAxis().setAxisLabelText("Year");
          plot.getYAxis().setAxisLabelText("Google normalized searches");
          plot.getXAxis().setNTicks(10);
          plot.setPoints(pointsOktoberfest);
          plot.setLineColor(color(100, 100, 100));
          plot.addLayer("German elections day", pointsElections);
          plot.getLayer("German elections day").setLineColor(color(255, 100, 255));
          plot.activatePointLabels();
        }
    
        void draw() {
          background(255);
          on_button.Draw();
          if (location.getProvider() == "none")
            text("Location data is unavailable. \n" +
              "Please check your location settings.", -100,100, width, height);
          else
            text("Latitude: " + latitude + "\n" + 
              "Longitude: " + longitude + "\n" + 
              "Altitude: " + altitude + "\n" + 
              "Provider: " + location.getProvider(),  -100, 100, width, height);  
    
          // Draw the plot  
          plot.beginDraw();
          plot.drawBox();
          plot.drawXAxis();
          plot.drawYAxis();
          plot.drawTitle();
          plot.drawGridLines(GPlot.VERTICAL);
          plot.drawFilledContours(GPlot.HORIZONTAL, 0);
          plot.drawLegend(new String[] {"Oktoberfest", "Bundestagswahl"}, new float[] {0.07, 0.22}, 
                          new float[] {0.92, 0.92});
          plot.drawLabels();
          plot.endDraw();
        }  
    
    
        // Not really the exact date, but it's ok for this example
        float getExactDate(int year, int month, int day) {
          boolean leapYear = false;
    
          if (year % 400 == 0) {
            leapYear = true;
          }
          else if (year % 100 == 0) {
            leapYear = false;
          }
          else if (year % 4 == 0) {
            leapYear = true;
          }
    
          if (leapYear) {
            return year + (month + (day - 1f)/daysPerMonthLeapYear[month])/12f;
          }
          else {
            return year + (month + (day - 1f)/daysPerMonth[month])/12f;
          }
        }
    
        void mousePressed() {
          if (on_button.MouseIsOver()) {
          /* in the following different ways of creating osc messages are shown by example */
          OscMessage myMessage = new OscMessage("The Data are bellow:" +"\n" +
                       "Latitude: " + latitude + "\n" + 
              "Longitude: " + longitude + "\n" + 
              "Altitude: " + altitude);
    
          //myMessage.add(123); /* add an int to the osc message */
    
          /* send the message */
          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("Hello: "+theOscMessage.addrPattern());
         // println(" typetag: "+theOscMessage.typetag());
    
        }
        void onLocationEvent(double _latitude, double _longitude, double _altitude)
        {
          longitude = _longitude;
          latitude = _latitude;
          altitude = _altitude;
          println("lat/lon/alt: " + latitude + "/" + longitude + "/" + altitude);
        }
    
        class Button {
          String label; // button label
          float x;      // top left corner x position
          float y;      // top left corner y position
          float w;      // width of button
          float h;      // height of button
    
          // constructor
          Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
            label = labelB;
            x = xpos;
            y = ypos;
            w = widthB;
            h = heightB;
          }
    
          void Draw() {
            fill(150);
            stroke(141);
            rect(x, y, w, h, 10);
            textAlign(CENTER, CENTER);
            fill(0);
            text(label, x + (w / 2), y + (h / 2));
          }
    
          boolean MouseIsOver() {
            if (mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) {
              return true;
            }
            return false;
          }
        }
    
Sign In or Register to comment.