02 Aug 2013, 04:30
Generic-user-small

Jayaraman Kiruthi Vasan (2 posts)

Daniel, I bought this book yesterday and am happy that I bought it. I am a fan of processing although I am not an expert. Android - I was trying to learn java and probably my C background is putting me off. Now coming to the point, I started trying examples and suddenly got greedy and tried working on chapter 6. I wrote the program in both PC and the above Android device. Removed compiling errors due to my mistakes and both programs are running. Now I find that whatever PC sends phone is able to receive and display it. Vice versa is not working. The console is printing a lot of messages as below.

Error onAccelerometerEvent() [simple]:null java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at ketai.sensors.KetaiSensor.onSensorChanged(KetaiSensor.java:608) at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:250) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4921) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) at dalvik.system.NativeStart.main(Native Method) Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118) at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:175) at libcore.io.IoBridge.sendto(IoBridge.java:473) at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:182) at java.net.DatagramSocket.send(DatagramSocket.java:284) at netP5.AbstractUdpClient.send(Unknown Source) at oscP5.OscNetManager.send(Unknown Source) at oscP5.OscNetManager.send(Unknown Source) at oscP5.OscP5.send(Unknown Source) at processing.test.wifitopc.WifiToPC.onAccelerometerEvent(WifiToPC.java:84) … 12 more Can you throw some light please?

I also read about getting the applet sign in - does it have something to do with it? If so, how is it practically done?

Thanks in advance

JK

02 Aug 2013, 05:02
Generic-user-small

Jayaraman Kiruthi Vasan (2 posts)

Daniel,

I made a change in the code and it is working now. I took the code inside the event handler routine and put it into a mousePressed routine. Now, whenever I tap onto the touchscreen, I am able to receive accelerometer data into PC. I am still puzzled, why it is not possible to send continuously.

20 Nov 2013, 22:05
Generic-user-small

Rafael Puyana (1 post)

I am facing the same issue. Do you mind sharing the way you managed to send data from Android to the PC processing app?

15 Jan 2014, 06:42
Generic-user-small

Arasch Lagies (1 post)

I am having the same issue. i just copied the code from chapter 6 into Processing (one for Android one for PC with Java). The mouse clicking event is sent from PC to Android. But the PC does not receive the Accelerometer values. I get following error: Error onAccelerometerEvent() [simple]:null java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at ketai.sensors.KetaiSensor.onSensorChanged(KetaiSensor.java:631) at android.hardware.SystemSensorManager$SensorEventQueue.dispatchSensorEvent(SystemSensorManager.java:467) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:132) at android.os.Looper.loop(Looper.java:124) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) at dalvik.system.NativeStart.main(Native Method) Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1144) at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:175) at libcore.io.IoBridge.sendto(IoBridge.java:466) at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:182) at java.net.DatagramSocket.send(DatagramSocket.java:284) at netP5.AbstractUdpClient.send(Unknown Source) at oscP5.OscNetManager.send(Unknown Source) at oscP5.OscNetManager.send(Unknown Source) at oscP5.OscP5.send(Unknown Source) at processing.test.wifidataexchangeandroid.WiFiDataExchangeAndroid.onAccelerometerEvent(WiFiDataExchangeAndroid.java:98) … 13 more

Is there some permit missing which I need to set for Android? Appreciate any tips you have regarding this issue.

Thanks AL

23 Jan 2014, 20:27
Ds_2009_mpark_pragsmall

Daniel Sauter (47 posts)

Hi everyone, are you using Processing 2.1? Android mode is not working in 2.1.X, please use 2.0.3 instead. http://forum.processing.org/two/discussion/comment/6701#Comment_6701 Signing apps is discussed in Chapter 13, Sharing and Publishing Applications. Best, Daniel

03 Apr 2014, 00:11
Generic-user-small

Gary Roth (5 posts)

I just got this working. Here’s what I did

  1. Exported to Eclipse, because when you run/debug from Eclipse it signs the app. I couldn’t figure out how to do this from within Processing.
  2. Placed the oscP5 call inside an AsyncTask – android no longer lets you execute WiFi tasks from the main UI task. Read why at (http://www.androiddesignpatterns.com/2012/06/app-force-close-honeycomb-ics.html). I adapted the example from (http://developer.android.com/reference/android/os/AsyncTask.html) to get the following

package processing.test.wifidataexchangeandroid;

import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 
import netP5.*; 
import oscP5.*; 
import ketai.net.*; 
import ketai.sensors.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 
import java.net.URL;

import android.os.AsyncTask;

public class WiFiDataExchangeAndroid extends PApplet {

// WiFiDataExchangeAndroid
//
// Rapid Android Development 134-35






OscP5 oscP5;
KetaiSensor sensor;

NetAddress remoteLocation;
OscMessage myMessage;
float myAccelerometerX,
  myAccelerometerY,
  myAccelerometerZ;
int x,
  y,
  p;
String myIPAddress;
String remoteAddress = "192.168.1.50";

public void setup()
{
  sensor = new KetaiSensor(this);

  orientation(PORTRAIT);
  textAlign(CENTER, CENTER);
  textSize(36);
  initNetworkConnection();
  sensor.start();
  thread("sendOscP5");
}

public void draw()
{
  background(78, 93, 75);
  
  text("Remote Mouse Info:"
    + "\nmouseX: " + x
    + "\nmouseY: " + y
    + "\nmousePressed: " + p
    + "\n\nLocal Accelerometer Data: "
    + "\nx: " + nfp(myAccelerometerX, 1, 3)
    + "\ny: " + nfp(myAccelerometerY, 1, 3)
    + "\nZ: " + nfp(myAccelerometerZ, 1, 3)
    + "\n\nLocal IP Address: " + myIPAddress
    + "\n\nRemote IP Address: " + remoteAddress,
    width / 2,
    height / 2);
}

public void oscEvent(OscMessage theOscMessage)
{
  if(theOscMessage.checkTypetag("iii"))
  {
    x = theOscMessage.get(0).intValue();
    y = theOscMessage.get(1).intValue();
    p = theOscMessage.get(2).intValue();
  }
}

public void onAccelerometerEvent(float x, float y, float z)
{
  myAccelerometerX = x;
  myAccelerometerY = y;
  myAccelerometerZ = z;
  
  myMessage = new OscMessage("accelerometerData");
  
  myMessage.add(x);
  myMessage.add(y);
  myMessage.add(z);
  
//  oscP5.send(myMessage, remoteLocation);
//  sendOscP5();
  new DownloadFilesTask().execute();
}

public void sendOscP5()
{
  oscP5.send(myMessage, remoteLocation);
  
  return;
} 

public void initNetworkConnection()
{
  oscP5 = new OscP5(this, 12000);
  remoteLocation = new NetAddress(remoteAddress, 12000);
  myIPAddress = KetaiNet.getIP();
}

class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
    protected Long doInBackground(URL... urls) {
        oscP5.send(myMessage, remoteLocation);

        return 1L;
    }

    protected void onProgressUpdate(Integer... progress) {
    }

    protected void onPostExecute(Long result) {
    }
}
}

  You must be logged in to comment