Visualizzazione post con etichetta Eddystone. Mostra tutti i post
Visualizzazione post con etichetta Eddystone. Mostra tutti i post

lunedì 8 gennaio 2018

Estimote Eddystone telemetry bridge in Android

Un esempio per ricevere i dati di telemetria dei pacchetti Eddystone (il protocollo di Google per i beacons) e trasmetterli poi ad un server remoto (ho scoperto solo oggi che il nome Eddystone deriva dal faro di Eddystone)



compile 'com.estimote:sdk:1.0.12'

---------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="innocenti.luca.com.eddyacc">

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


    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

---------------------------------------------


package innocenti.luca.com.eddyacc;

import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.estimote.coresdk.common.config.EstimoteSDK;
import com.estimote.coresdk.recognition.packets.Eddystone;
import com.estimote.coresdk.recognition.packets.EstimoteTelemetry;
import com.estimote.coresdk.service.BeaconManager;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.List;





public class MainActivity extends AppCompatActivity {

    private BeaconManager beaconManager;
    private String scanId;




    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EstimoteSDK.initialize(getApplicationContext(),"eddyacc-ev0","f73efb85963579672c048fc92de64039");

        beaconManager = new BeaconManager(this);

        beaconManager.setEddystoneListener(new BeaconManager.EddystoneListener() {
            @Override public void onEddystonesFound(List<Eddystone> eddystones) {
                for (Eddystone e : eddystones){
                    if (e.telemetry != null)
                    {
                        String aa = "http://150.217.73.108/luca/test.php?temperatura="+Double.toString(e.telemetry.temperature);
                        Double myTaskParameters = e.telemetry.temperature;
                        new invia().execute(myTaskParameters);

                        Log.d("Eddy", e.macAddress + " temperature :" + e.telemetry.temperature + " ");
                    }
                }

            }
        });


        beaconManager.setTelemetryListener(new BeaconManager.TelemetryListener() {
            @Override            public void onTelemetriesFound(List<EstimoteTelemetry> telemetries) {
                for (EstimoteTelemetry tlm : telemetries) {
                    Log.d("TELEMETRY", "beaconID: " + tlm.deviceId +
                            ", temperature: " + tlm.temperature + " °C" + tlm.accelerometer.x);
                }
            }
        });
    }




    @Override protected void onStart() {
        super.onStart();
        beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
            @Override            public void onServiceReady() {
                beaconManager.startEddystoneDiscovery();
                beaconManager.startTelemetryDiscovery();
            }
        });
    }

    @Override protected void onStop() {
        super.onStop();
        beaconManager.stopEddystoneDiscovery();

        beaconManager.stopTelemetryDiscovery();
    }

    @Override protected void onDestroy(){
        super.onDestroy();
        beaconManager.disconnect();
    }

    private class invia extends AsyncTask<Double, Void, String> {

        @Override        protected String doInBackground(Double... params) {
            // These two need to be declared outside the try/catch            // so that they can be closed in the finally block.            HttpURLConnection urlConnection = null;
            Double t = params[0];

            try {

                URL url = new URL("http://150.217.73.108/luca/test.php?temperatura="+Double.toString(t));
                urlConnection = (HttpURLConnection) url.openConnection();
                urlConnection.setRequestMethod("GET");
                urlConnection.connect();
                urlConnection.getInputStream();


            } catch (ProtocolException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (urlConnection != null) {
                    urlConnection.disconnect();
                }

            }
            return null;
        }

            @Override            protected void onPostExecute (String s)
            {
                super.onPostExecute(s);
            }

        }
}

venerdì 28 agosto 2015

EddyStone Beacons


Eddystone e' una specifica per beacons a formato aperto (che si differenzia da IBeacons di marchio Apple) recentemente uscita e sponsorizzata da Google

Non tutti i beacon sono in grado di trasmettere in formato Eddystone ma quelli riprogrammabili (e di  marca) come Radius ed Estimote possono essere trasformati in modalita' Eddystone

Beacon Estimote in modalita' Eddystone

C'e' da dire che le due modalita' sono esclusive (od il beacon trasmette in modalita' IBeacon od in EddyStone) e che la durata stimata delle batterie su Eddystone e' inferiore a quella IBeacon


C'e' pero' da osservare un paio di aspetti importanti:

1) Eddystone permette di trasmettere, oltre all'UUID come IBeacon, anche stringhe di testo. In questo modo si puo' evitare l'utilizzo di un server esterno se per esempio si vuole pubblicizzare un prodotto in una vetrina (per esempio) . Si programma il beacon per puntare ad un link sullo store invece che ad un proprio server che legge l'UUID, interroga il database e fornisce il link del prodotto.

2) il formato e' libero e quindi meno soggetto alle guerre tra marchi (in questo modo verra' sdoganato l'uso dei beacon anche su Android)

Google ha pubblicato gli esempi sull'utilizzo (sia per Android che IOS) a questo link.
Oltre al protocollo Eddystone Google fornisce anche una infrastruttura cloud per gestire una eventuale flotta di beacons (un po' sullo stile di cio' che gia' offre Estimte) tramite le Proximity API

ps: alla data attuale l'applicazione Estimote per IOS non gestisce il protocollo Eddystone e non riconosce il broadcast da questi dispositivi. L'applicazione Estimote per Android invece funziona perfettamente con il nuovo formato

Geologi

  E so anche espatriare senza praticamente toccare strada asfaltata