0

I'm trying to connect my Glass with Arduino and a Wifi Shield.

At MenuActivity.java I call (and others methods... but this is the call) :

protected void onCreate(Bundle savedInstanceState) 
    {
        new ConnexioArduino().execute();
        super.onCreate(savedInstanceState);
    }

And my ConnexioArduino.java :

private boolean socketReady;
    private BufferedWriter outA;
    private BufferedReader inA;
    private Socket mySocket;
....
.... 
@Override
    protected Void doInBackground(Void... params) {

        socketReady = true;         
        String Host = "192.168.43.177";
        int Port = 10001; 
        outA = null;
        inA = null;
        mySocket = null;

        try {
            mySocket = new Socket(Host, Port);
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        try {
            mySocket.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

So it only does a connexion between Glass-Arduino Wifi Shield through Socket. But when I execute my app it stops and it gives me the following error : (see image on this link, sorry for the URL I don't have the enough reputation)

http://google-glass-api.googlecode.com/issues/attachment?aid=4630000000&name=Captura+de+pantalla+2014-04-09+a+la%28s%29+13.08.12.png&token=CyuXI9n0-00D4I0inCvN122h42g%3A1398618521508&inline=1 Imagen

SJuan76
  • 24,532
  • 6
  • 47
  • 87
Mark
  • 113
  • 7
  • url works fine for me... – Mark Apr 27 '14 at 17:28
  • Does not work in IE, works in Chrome – SJuan76 Apr 27 '14 at 17:48
  • url does not work for me either, 400 error, check in an incognito tab Mark to see if it will work users other than you ... can you just paste the error from logcat? – Mark Scheel Apr 27 '14 at 17:48
  • Edited the image in, but anyway you should really post the stacktrace as text, as it is both more legible and searchable. – SJuan76 Apr 27 '14 at 17:53
  • You got a NullPointerException in line 51, which is line 51? And most important: who gave you some Google Glasses if you cannot find a NPE in an stacktrace? – SJuan76 Apr 27 '14 at 17:55
  • Best bet: you got a "hidden" exception when instantiating the socket and you get the exception trying to do `mySocket.close()` – SJuan76 Apr 27 '14 at 17:57

1 Answers1

0

Share your manifest, it should have:

<uses-permission android:name="android.permission.INTERNET"/>

If not you will get a socket failed:eacces (permission denied) error if you step-debug.

Another possible problem is that your server is not accepting the socket request for any number of reasons.

I was able to use your exact code, set up a basic node server on a laptop, and open and close the socket without a crash.

Socket code on Glass should be just like Android according to this:

https://code.google.com/p/google-glass-api/issues/detail?id=272

If you continue to have issues log out the value of e in the exceptions you are catching and paste the result into your question.

Mark Scheel
  • 2,963
  • 1
  • 20
  • 23
  • Thank you Mark. Yes I have the android.permission.INTERNET in my manifest. I read that post and I got the same conclusion as you, it must be the same. In fact, I created a simple android app for android device (nexus 7), and it worked... It must be something about Glass. What I'm not sure if I should create my Socket in an AsynkTask or I could create it onCreate method... – Mark Apr 27 '14 at 19:44