4

I am looking to connect my phone to my Google Glass and transfer data (photos, text, etc.) between the two.

I was thinking of using Bluetooth LTE but as I understand it, Glass does not support it because it is only running version 4.0.3 (or similar) of Android.

I know you can connect the phone and glass via the myGlass app, so clearly, what I am looking to do is possible. However, I was wondering if someone could point me in the right direction to get started? Specifically, what technologies should I look at if not CoreBluetooth on the iOS side? Has anyone else done this?

Also, if it would be better served to use Bonjour, or even to create the hotspot on my iPhone and connect that way, any tutorials you could point me to would be great.

Thanks in advance.

W. Wright
  • 101
  • 5
  • It should be possible. It's possible via an android app and glass http://stackoverflow.com/a/20414642/661079. – Kenny C Mar 31 '14 at 19:14

2 Answers2

3

I'm writing a Google Glass Development book for Apress and just finished the chapter Network and Bluetooth, with some working samples to let Glass communicate with iPhone for data transfer. You're right that Glass as of now (API level 15) doesn't support Bluetooth Low Energy (BLE). I have implemented three ways to make the data transfer between Glass and iOS happen:

  1. Let Glass talk to an Android device, such as Nexus 7 with Android 4.3 or above with BLE support, via Classic Bluetooth or socket, and Nexus 7 acts as a BLE central to talk to iOS as a BLE peripheral. Notice you shouldn't use BLE to send large data such as photo.

  2. Let Glass talk to iOS directly via socket - you can use C socket code running as a server and Glass Java socket client, or vice versa. This would require your Glass and iOS device on the same Wifi, but can transfer large data.

  3. Use a server-based solution - upload data from Glass to a server and let iOS get it via Apple Push Notification. I used this method to share photos on Glass with friends on WhatsApp and WeChat, both apps run on iOS.

Sample iOS code acting as socket server:

- (void) runSocketServer {
    int listenfd = 0;
    __block int connfd = 0;
    struct sockaddr_in serv_addr;

    __block char sendBuff[1025];

    listenfd = socket(AF_INET, SOCK_STREAM, 0);
    memset(&serv_addr, '0', sizeof(serv_addr));
    memset(sendBuff, '0', sizeof(sendBuff));

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(6682);

    bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));    
    listen(listenfd, 10);

    dispatch_async(dispatch_get_global_queue(0, 0), ^{        
        connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
        int count = 1;
        while (count++ < 120) {
            char rate[100];
            sprintf(rate, "%i\n", bpm);            
            write(connfd, rate, strlen(rate));            
            sleep(1);
        }

        close(connfd);
    });
}

Sample Glass code acting as a socket client:

public void run()
{
    String serverName = "192.168.1.11"; 
    int port = 6682;
    try
    {
        socket = new Socket(serverName, port);
        BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        do {
            result = input.readLine();
            runOnUiThread(new Runnable() {
                public void run() {
                    mTvInfo.setText(result);
                }
            });                 
        } while (result != null);

        });                  
    }
    catch(Exception e) {
        try { socket.close(); }
        catch (Exception e2) {};
        e.printStackTrace();
    }
}
Jeff Tang
  • 1,804
  • 15
  • 16
  • Do you happen to have some example code of the method number 2 (sockets)? It looks like that will most likely be the way I have to go with this. Thanks for your help. – W. Wright Apr 02 '14 at 01:57
0

Have you tried setting up Google backup? You can instantly get your pictures from glass and view them on your phone (but not vice versa).

Otherwise, there is currently no way on the market for this, but here are a couple of ideas:

  1. You could submit it as an app idea to one of these:

http://glass-apps.org/google/glass-app-ideas https://plus.google.com/communities/107405100380970813362/stream/b18a5f3c-e170-40a8-991f-823f018e75af

  1. Or you could build it yourself. The GDK is pretty powerful. You can't submit gdk apps to Google yet, but it would be great for personal use. This guy started working on it and his github is here: https://github.com/NathanielWaggoner/GoogleGlassBlutooth
  • I should have mentioned that using the cloud is not really an option - it needs to be an iphone-to-glass communication. Thanks for the github link, I will check that out. – W. Wright Apr 02 '14 at 01:59