Mundarija:

SmartBin: 8 qadam
SmartBin: 8 qadam

Video: SmartBin: 8 qadam

Video: SmartBin: 8 qadam
Video: Redmi smart Band 2024, Noyabr
Anonim
SmartBin
SmartBin

Umumiy hisob -kitoblarga ko'ra, hech qanday ma'lumot yo'q, chunki siz hech qanday ma'lumotga ega bo'lmagansiz, bu sizning shaxsiy ma'lumotlaringiz, ma'lumotlaringiz va ma'lumotlaringiz bilan bog'liq.

Mana, eng zarur loyiha:

  • NodeMCU
  • Ultrassonico de Distancia sensori
  • Caixa de papelão
  • Protoboard
  • Kabos
  • Android uchun dispozitsiya

1 -qadam: Conectando O sensori

Boshqaruv, NODEMCU va ultrasonik sensorlar yordamida amalga oshiriladi. NodeMCU D4 va D3 port portlarini ishga tushirish sensori sifatida vamos conectar:

// pin raqamlarini belgilaydi #pino_trigger 2 ni aniqlang // D4

#pino_echo 0 ni aniqlang // D3

Sensor, o'qish yoki FilipeFlop -dan foydalanish uchun maxsus dasturlardan foydalanish mumkin.

float cmMsec, inMsec;

uzoq mikrosaniya = ultrasonik. vaqt ();

cmMsec = ultrasonic.convert (mikrosaniya, Ultrasonik:: CM);

inMsec = ultrasonic.convert (mikrosaniya, Ultrasonik:: IN);

// Exibe informacoes ketma -ket monitor yo'q

Serial.print ("Distancia em sm:");

Serial.print (cmMsec);

Serial.print (" - Distancia em polegadas:");

Serial.println (inMsec);

String ma'lumotlari = String (cmMsec);

Serial.println (ma'lumotlar);

2 -qadam: Montando va Lixeyra

Agora, vamos montar va lixeira inteligente. Ultrasonik sensorlar "teto" va "lixeira" ga ega emas. Masalan, foydalanish mumkin emas. Ma'lum bo'lishicha, har bir kishi o'z vazifasini bajaradi. Yo'q, 26, 3 sm. Qachonki, bu juda katta ahamiyatga ega.

O'chirish sensori ultrasonik va boshqa algoritmlar yordamida tasodifiy ravishda 4 ta masofadan farq qiladi.

// Simulando 4 lixeyra

uzoq lixeyraID;

void loop () {

lixeiraID = tasodifiy (1, 5);

}

3 -qadam: Nuvem -ni yuklang

Aqlli ma'lumotlarga ko'ra, bu eng muhimi. ThingSpeak eskolxi yoki tanish tanishish uchun. Boshlang'ich kanal, zarur kanallar, 4 parametrlar, havolalar yoki katta hajmli havolalar.

ThingSpeak yoki API -ni o'rnatish uchun kanallarni o'rnatish zarur. Saga os passos descritos rasmiy sayt yo'q.

ThingSpeak, ESP8266WiFi.h va biblioteka ma'lumotlarini ThingSpeak va boshqa ilovalar yordamida olish mumkin.

Boshlang'ich vazifani bajaring, bu sizning vazifangizdir (oldindan belgilash, o'tish , o'tish, [identifikator va boshqa ma'lumotlarni aniqlash].

bekor ulanishWifi () {

Serial.print ("ulanish"+ *ssid);

WiFi.begin (ssid, pass);

esa (WiFi.status ()! = WL_CONNECTED) {

kechikish (500);

Serial.print (".");

}

Serial.println ("");

Serial.print ("Conectado na rede");

Serial.println (ssid);

Serial.print ("IP:");

Serial.println (WiFi.localIP ());

}

O'rnatish, sozlash va qayta ishlashni davom ettiring.

bo'sh o'rnatish () {

Serial.begin (9600);

Serial.println ("Lendo dados sensor …");

// Konektando yoki Wi-Fi

ulanish Wi -Fi ();

}

ThingSpeak -ning asosiy vazifasi - bu HTTP -ni o'chirib qo'yish, API -ni o'rnatish va sozlash.

void sendDataTS (float cmMsec, uzoq identifikator) {

if (client.connect (server, 80)) {

Serial.println ("ThingSpeak" uchun "Enviando dados");

String postStr = apiKey;

postStr += "& maydon";

postStr += id;

postStr += "=";

postStr += String (cmMsec);

postStr += "\ r / n / r / n";

Serial.println (postStr);

client.print ("POST /yangilash HTTP /1.1 / n");

client.print ("Xost: api.thingspeak.com / n");

client.print ("Ulanish: yopish / n");

client.print ("X-THINGSPEAKAPIKEY:" + apiKey + "\ n");

client.print ("Content-Type: application/x-www-form-urlencoded / n");

client.print ("Content-Length:");

client.print (postStr.length ());

client.print ("\ n / n");

client.print (postStr);

kechikish (1000);

}

client.stop ();

}

Parametrlar ulanish sensori ulanish texnologiyasiga mos keladi. Shaxsiy ma'lumotlarga ko'ra, bu sizning tasodifiy tasodifingizdir (1 -dan 4 -gacha).

U identifikatsiya qilish uchun xizmat ko'rsatishni o'z ichiga oladi va yuklaydi.

4 -qadam: Recuperando Dados ThingSpeak qiling

Bu ThingSpeak kanalini, JSON xizmatlarini ko'rsatish uchun ruxsat beradi. Kanalni ochish uchun kanallarni ochish usuli quyidagicha:

www.mathworks.com/help/thingspeak/get-a-ch…

Nimani tanlash kerak bo'lsa, biz ham buni bilib olamiz. URL manzilini belgilang:

api.thingspeak.com/channels/CHANNEL_ID/fields/FIELD_NUMBER/last.json?api_key=API_KEY&status=true

Bu erda hech qanday ma'lumot yo'q. Mana shu muhim loyihalar uchun:

  • CHANNEL_ID: kanalni ochish
  • FIELD_NUMBER: omadli bo'lsin
  • API_KEY: API -ni sozlash

Bu URL -ni Android -da, ThingSpeak -da o'rnatish uchun javob beradi.

5 -qadam: Criando va Android ilovasi

Android Studio yo'q, Android uchun yangi loyiha. Agar siz AndroidManifest -ga ruxsat bersangiz, u holda siz konfiguratsiya qilishingiz kerak.

Google xaritalari yoki Google xaritalari bilan bog'laning. Bu erda hech qanday havola yo'q.

Umumiy holda, biz konfiguratsiyani o'rnatamiz.

Google Xaritalarga asoslangan API-lar uchun API kaliti simli manba sifatida belgilanadi.

("Res/values/google_maps_api.xml" faylini ko'ring).

E'tibor bering, API kaliti APK -ni imzolash uchun ishlatiladigan shifrlash kalitiga bog'langan. Sizga har bir shifrlash kaliti uchun boshqa API kaliti kerak bo'ladi, shu jumladan APK -ni nashr qilish uchun imzolash uchun ishlatiladigan kalit. Src/debug/va src/release/da disk raskadrovka va chiqarish maqsadlari kalitlarini belgilashingiz mumkin.

<meta-ma'lumotlar

android: nomi = "com.google.android.geo. API_KEY"

android: value = "@string /google_maps_key" />

AndroidManifest -ni loyihalash yoki o'rnatish uchun to'liq sozlash.

n

6 -qadam: Recuperando O Feed No Android

Android, MainActivity, ThingSpeak dasturlari bilan bir qatorda, 4 ta farqli buyruqlar mavjud:

xususiy String url_a = "https://api.thingspeak.com/channels/429823/fields/1/last.json?api_key="+API_THINGSPEAK_KEY+"&status=true"; shaxsiy String url_b = "https://api.thingspeak.com/channels/429823/fields/2/last.json?api_key="+API_THINGSPEAK_KEY+"&status=true"; private String url_c = "https://api.thingspeak.com/channels/429823/fields/3/last.json?api_key="+API_THINGSPEAK_KEY+"&status=true"; shaxsiy String url_d = "https://api.thingspeak.com/channels/429823/fields/4/last.json?api_key="+API_THINGSPEAK_KEY+"&status=true";

Agar siz Android -ni, JSONObject -ni va Android -ni ishlatishni xohlasangiz, u holda bu sizning kompyuteringiz uchun kerak bo'ladi. Ma'lum bo'lishicha, URL manzili:

JSONObject javobLixeiraA; JSONObject javobLixeiraB; JSONObject javobLixeiraC; JSONObject javobLixeiraD;

HttpJsonParser -ga ulanish, bir -biriga bog'lanmagan yordamchi dasturlar. Javoblar URL manzili, shuningdek, JSON -ni qayta o'rnatish yoki o'chirish uchun javob beradi.

umumiy JSONObject makeHttpRequest (String url, String usuli, Xarita parametrlari) {

sinab ko'ring {

Uri. Builder quruvchisi = yangi Uri. Builder (); URL urlObj; String encodedParams = ""; if (params! = null) {for (Map. Entry yozuvi: params.entrySet ()) {builder.appendQueryParameter (entry.getKey (), entry.getValue ()); }} if (builder.build (). getEncodedQuery ()! = null) {encodedParams = builder.build (). getEncodedQuery ();

}

if ("GET". teng (usul)) {url = url + "?" + kodlanganParams; urlObj = yangi URL (url); urlConnection = (HttpURLConnection) urlObj.openConnection (); urlConnection.setRequestMethod (usul);

} boshqa {

urlObj = yangi URL (url); urlConnection = (HttpURLConnection) urlObj.openConnection (); urlConnection.setRequestMethod (usul); urlConnection.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded"); urlConnection.setRequestProperty ("Content-Length", String.valueOf (encodedParams.getBytes (). uzunlik)); urlConnection.getOutputStream (). yozish (encodedParams.getBytes ()); } // urlConnection.connect () serveriga ulanish; // Javobni o'qing = urlConnection.getInputStream (); BufferedReader o'quvchi = yangi BufferedReader (yangi InputStreamReader (is)); StringBuilder sb = yangi StringBuilder (); Qator chizig'i;

// Javobni tahlil qiling

while ((line = reader.readLine ())! = null) {sb.append (satr + "\ n"); } is.close (); json = sb.toString (); // Javobni JSON Objectga aylantirish jObj = new JSONObject (json);

} catch (UnsupportedEncodingException e) {

e.printStackTrace (); } catch (ProtocolException e) {e.printStackTrace (); } catch (IOException e) {e.printStackTrace (); } catch (JSONException e) {Log.e ("JSON Parser", "Ma'lumotlarni tahlil qilishda xato" + e.toString ()); } catch (Istisno e) {Log.e ("Istisno", "Ma'lumotlarni tahlil qilishda xato" + e.toString ()); }

// JSON ob'ektini qaytarish

qaytish jObj;

}

}

O'qituvchi o'z vazifalarini bajaradi, bu erda siz o'zingizni qiziqtirgan savollarga javob berasiz, bu erda ham siz ham, InInsta -da ham o'zingizni qiziqtirasiz.

@Override himoyalangan String doInBackground (String… params) {HttpJsonParser jsonParser = new HttpJsonParser ();

ResponseLixeiraA = jsonParser.makeHttpRequest (url_a, "GET", null);

javobLixeiraB = jsonParser.makeHttpRequest (url_b, "Oling", null); javobLixeiraC = jsonParser.makeHttpRequest (url_c, "GET", null); ResponseLixeiraD = jsonParser.makeHttpRequest (url_d, "GET", null);

qaytarish null;}

DoPackExecute -ni o'rnatish uchun Android -ni boshqarish uchun Android -ni boshqaring. ThingSpeak -ning eng mashhur va eng mashhur usullari:

himoyalangan void onPostExecute (String natijasi) {pDialog.dismiss (); runOnUiThread (yangi Runnable () {public void run () {

// ListView listView = (ListView) findViewById (R.id.feedList);

ViewVinView = (Ko'rish) findViewById (R.id.activity_main); if (muvaffaqiyat == 1) {urinish {// Cria feedDetail para cada lixeira Lixeira feedDetails1 = new Lixeira (); Lixeira feedDetails2 = yangi Lixeira (); Lixeira feedDetails3 = yangi Lixeira (); Lixeira feedDetails4 = yangi Lixeira ();

feedDetails1.setId ('A');

feedDetails1.setPesoLixo (Double.parseDouble (answerLixeiraA.getString (KEY_FIELD1))))); feedDetails1.setVolumeLixo (Double.parseDouble (answerLixeiraA.getString (KEY_FIELD1)))));

feedDetails2.setId ("B");

feedDetails2.setPesoLixo (Double.parseDouble (answerLixeiraB.getString (KEY_FIELD2))))); feedDetails2.setVolumeLixo (Double.parseDouble (answerLixeiraB.getString (KEY_FIELD2)))));

feedDetails3.setId ('C');

feedDetails3.setPesoLixo (Double.parseDouble (answerLixeiraC.getString (KEY_FIELD3))))); feedDetails3.setVolumeLixo (Double.parseDouble (answerLixeiraC.getString (KEY_FIELD3))));

feedDetails4.setId ('D');

feedDetails4.setPesoLixo (Double.parseDouble (answerLixeiraD.getString (KEY_FIELD4))))); feedDetails4.setVolumeLixo (Double.parseDouble (answerLixeiraD.getString (KEY_FIELD4))));

feedList.add (feedDetails1);

feedList.add (feedDetails2); feedList.add (feedDetails3); feedList.add (feedDetails4);

// Dados das lixeiras hisob -kitoblari

SmartBinService kalkulyatori = yangi SmartBinService (); calculator.montaListaLixeiras (feedList);

// Recupera komponentlari

TextView createDate = (TextView) mainView.findViewById (R.id.date); ListView listaDeLixeiras = (ListView) findViewById (R.id.lista); adapter.addAll (feedList);

// Ma'lumotlar

DateTimeTime = Calendar.getInstance (). GetTime (); SimpleDateFormat simpleDate = yangi SimpleDateFormat ("dd/MM/yyyy"); String currentDate = simpleDate.format (currentTime); createDate.setText (KEY_DATE + currentDate + ""); listaDeLixeiras.setAdapter (adapter);

} catch (JSONException e) {

e.printStackTrace (); }

} boshqa {

Toast.makeText (MainActivity.this, "Ma'lumotlarni yuklashda xatolik yuz berdi", Toast. LENGTH_LONG).show ();

}

} }); }

Qolaversa, bu sizning xohishingizga ko'ra, har qanday ma'lumotni o'z ichiga oladi.

7 -qadam: Mostrando No Mapa

Mostrando xaritasi yo'q
Mostrando xaritasi yo'q

Aniq ma'lumotlarga ko'ra, siz xaritada boshqa hech qanday aloqaga ega bo'lmaysiz.

/ ** Foydalanuvchi Mapa tugmachasini bosganda chaqiriladi*/ public void openMaps (View view) {Intent aim = new Intent (this, LixeiraMapsActivity.class);

// Lexeiras ro'yxati

Paket to'plami = yangi to'plam (); bundle.putParcelableArrayList ("lixeiras", feedList); niyat.putExtralar (to'plam);

startActivity (niyat);

}

Hech qanday xarita yo'q, ijrochilarni ajratib ko'rsatish mumkin:

  1. marcar a posichão atual do caminha de lixo
  2. marcar os pontos muxbirlari, hech qanday xarita yo'q
  3. traçar a rota entre os pontos

Bu Google Yo'nalishining API -ni ishlatgan holda amalga oshiriladi. Google API Android V2 Google yo'nalishlarida Google yo'nalishlaridan foydalanib, ikkita joy o'rtasida haydash yo'nalishlarini chizish.

Boshlang'ich, mahalliy aholi punktlari:

// Joylar

xususiy LatLng oqimi;

xususiy LatLng lixeiraA; xususiy LatLng lixeiraB; xususiy LatLng lixeiraC; shaxsiy LatLng lixeiraD;.

Siz hech qanday xaritaga ega bo'lmagansiz yoki yo'qsiz:

private void checkLocationandAddToMap () {// Foydalanuvchining ruxsat berganligini tekshirish, agar ACCESS_COARSE_LOCATION)!! qaytish; }

// Fus yordamida oxirgi ma'lum bo'lgan joyni olish

Joylashuv manzili = LocationServices. FusedLocationApi.getLastLocation (googleApiClient);

// MarkerOptions yangi Marker yaratish uchun ishlatiladi, MarkerOptions yordamida manzil, sarlavha va boshqalarni belgilashingiz mumkin.

this.current = yangi LatLng (location.getLatitude (), location.getLongitude ()); MarkerOptions markerOptions = yangi MarkerOptions (). Pozitsiya (joriy).title ("Posicão atual");

// Yaratilgan belgini xaritaga qo'shish, kamerani joyiga ko'chirish

markerOptions.icon (BitmapDescriptorFactory.defaultMarker (BitmapDescriptorFactory. HUE_GREEN)); System.out.println ("++++++++++++++++++++++++++++"); mMap.addMarker (markerOptions);

// Kamerani 15 ga yaqinlashtirish bilan darhol joyga ko'chiring.

mMap.moveCamera (CameraUpdateFactory.newLatLngZoom (joriy, 15));

// Kattalashtirish, kamerani jonlantirish.

mMap.animateCamera (CameraUpdateFactory.zoomTo (14), 2000, null);

}

Masalan, aka abaixo o'xshash:

private void addBinALocation () {// Foydalanuvchining ruxsat berganligini tekshirish (ActivityCompat.checkSelfPermission (bu, android. Manifest.permission. ACCESS_FINE_LOCATION)! = PackageManager. PERMISSION_GRANTED && ActivityCompat.checkSelfPermission (bu, ACCESS_COARSE_LOCATION)!! qaytish; }

// Praça da Estacao

er -xotin kenglik = -19.9159578; ikki uzunlik = -43.9387856; this.lixeiraA = yangi LatLng (kenglik, uzunlik);

MarkerOptions markerOptions = yangi MarkerOptions (). Pozitsiya (lixeiraA).title ("Lixeira A");

markerOptions.icon (BitmapDescriptorFactory.defaultMarker (BitmapDescriptorFactory. HUE_RED)); mMap.addMarker (markerOptions); }

Kenglik va uzunlik uzunliklari Google Xaritalar xizmatlaridan foydalangan holda, hech qanday aniqlik yo'q. Idealmentes, Firesase (masalan, Firebase -ning asosiy vazifasi). Boshlang'ich loyihani amalga oshiring!

Ochiq havola qilish kerak, chunki biz bu ishni bajaramiz. Yo'nalishlarni aniqlab olish muhim ahamiyatga ega, shuning uchun siz yo'l nuqtalarini ko'rishingiz mumkin!

Qachonki, bu erda hamma narsa yaxshi bo'ladi:

private String getDirectionsUrl (LatLng kelib chiqishi, LatLng dest, Yo'nalish nuqtalari ro'yxati) {

// Marshrutning kelib chiqishi

String str_origin = "Origin ="+Origin. Latitude+","+Origin. Longitude;

// Marshrutning maqsadi

String str_dest = "destination ="+dest.latitude+","+dest.longitude;

// Yo'nalish bo'ylab yo'nalish nuqtalari

//waypoints=optimize:true| 19.9227365, -43.9473546 | -19.9168006, -43.9361124 String yo'l nuqtalari = "yo'l nuqtalari = optimallashtirish: rost"; uchun (LatLng nuqtasi: waypointsList) {yo'l nuqtalari += "|" + nuqta.lenglik + "," + nuqta. uzunlik; }

// Sensor yoqilgan

String sensori = "sensor = noto'g'ri";

// Veb -xizmat parametrlarini yaratish

String parametrlari = str_origin+"&"+str_dest+"&"+sensor+"&"+yo'l nuqtalari;

// Chiqish formati

String chiqishi = "json";

// Veb -xizmatga url yaratish

String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters; System.out.println ("++++++++++++++"+url);

qaytish url;

}

E, por fim, juntando tudo no método main da classe, onMapReady:

@Ommaviy bo'shliqni onMapReady (GoogleMap googleMap) {mMap = googleMap;

checkLocationandAddToMap ();

if (lixeirasList.get (0).getVolumeLixo ()> Lixeira. MIN_VOLUME_GARBAGE

|| lixeirasList.get (0).getPesoLixo ()-10> Lixeira. MIN_SIZE_GARBAGE) {addBinALocation (); } if (lixeirasList.get (1).getVolumeLixo ()> Lixeira. MIN_VOLUME_GARBAGE || lixeirasList.get (1).getPesoLixo ()> Lixeira. MIN_SIZE_GARBAGE) {addBinBLocation (); } if (lixeirasList.get (2).getVolumeLixo ()> Lixeira. MIN_VOLUME_GARBAGE || lixeirasList.get (2).getPesoLixo ()> Lixeira. MIN_SIZE_GARBAGE) {addBinCLocation (); } if (lixeirasList.get (3).getVolumeLixo ()> Lixeira. MIN_VOLUME_GARBAGE || lixeirasList.get (3).getPesoLixo ()> Lixeira. MIN_SIZE_GARBAGE) {addBinDLocation (); }

// Marshrutlarni chizish

// Google Directions API -ga URL olish

Ro'yxat nuqtalari = yangi ArrayList (); ball.add (lixeiraB); ball.add (lixeiraC); ball.add (lixeiraD);

String url = getDirectionsUrl (joriy, lixeiraA, ball);

DownloadTask downloadTask = yangi DownloadTask (); // Google Directions API downloadTask.execute (url) dan json ma'lumotlarini yuklab olishni boshlang; }

Aqua passamos apenas pelos pontos principais. Maslahatlashuvni amalga oshirish uchun siz o'z vazifangizni bajarishingiz kerak.

8 -qadam: Xulosa

IoT -ni o'rnatish juda qiyin, shuning uchun siz o'zingizning ma'lumotlaringizni ishlatishingiz mumkin. Android -da hech qanday muammo yo'q, lekin siz ularni o'chirib qo'yishingiz mumkin.

Tavsiya: