Parsing data from mqtt ttn


Postingan kali ini adalah lanjutan dari postingan saya sebelumnya disini , nah pada postingan saya kali ini akan membahas bagaimana cara memparsing data json yang kita dapat dari ttn kemudian menampilkannya ke dalam dashboard, sehingga hasilnya seperti dibawah ini

[{"id":"1f1f6ed1.81cf91","type":"mqtt in","z":"7609c47a.c51b3c","name":"","topic":"+/devices/+/up","qos":"2","broker":"7833904b.af11d","x":220,"y":200,"wires":[["d839d790.4b77c8"]]},{"id":"d839d790.4b77c8","type":"json","z":"7609c47a.c51b3c","name":"","property":"payload","action":"obj","pretty":true,"x":470,"y":200,"wires":[["e2efc94c.1de158","47698174.a787f","9db17467.71c868","b38807c2.074058","6cc7cd06.b7c634"]]},{"id":"e2efc94c.1de158","type":"function","z":"7609c47a.c51b3c","name":"battery","func":"var obj = msg.payload;\nmsg.payload = obj.payload_fields.analog_in_3;\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":180,"wires":[["9ea82fec.53c49"]]},{"id":"47698174.a787f","type":"function","z":"7609c47a.c51b3c","name":"temperature","func":"var obj = msg.payload;\nmsg.payload = obj.payload_fields.temperature_1;\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":240,"wires":[["491b941b.7cb80c"]]},{"id":"9db17467.71c868","type":"function","z":"7609c47a.c51b3c","name":"humidity","func":"var obj = msg.payload;\nmsg.payload = obj.payload_fields.relative_humidity_2;\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":300,"wires":[["754ca03c.46161"]]},{"id":"491b941b.7cb80c","type":"ui_chart","z":"7609c47a.c51b3c","name":"","group":"7fb7eee3.fc934","order":1,"width":0,"height":0,"label":"Temperature","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":930,"y":240,"wires":[[],[]]},{"id":"9ea82fec.53c49","type":"ui_gauge","z":"7609c47a.c51b3c","name":"","group":"d98f26c6.56b8b8","order":1,"width":0,"height":0,"gtype":"gage","title":"Battery","label":"units","format":"{{value}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":920,"y":180,"wires":[]},{"id":"754ca03c.46161","type":"ui_chart","z":"7609c47a.c51b3c","name":"","group":"7fb7eee3.fc934","order":2,"width":0,"height":0,"label":"Humidity","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":920,"y":300,"wires":[[],[]]},{"id":"b38807c2.074058","type":"function","z":"7609c47a.c51b3c","name":"rssi","func":"var obj = msg.payload;\nmsg.payload = obj.metadata.gateways[0].rssi;\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":360,"wires":[["9e68c3c6.729e5"]]},{"id":"9e68c3c6.729e5","type":"ui_chart","z":"7609c47a.c51b3c","name":"","group":"9a2e91ee.5594a","order":2,"width":0,"height":0,"label":"RSSI","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":910,"y":360,"wires":[[],[]]},{"id":"6cc7cd06.b7c634","type":"function","z":"7609c47a.c51b3c","name":"rssi","func":"var obj = msg.payload;\nmsg.payload = obj.metadata.gateways[0].snr;\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":420,"wires":[["c2e09073.55f99"]]},{"id":"c2e09073.55f99","type":"ui_chart","z":"7609c47a.c51b3c","name":"","group":"9a2e91ee.5594a","order":3,"width":0,"height":0,"label":"SNR","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":910,"y":420,"wires":[[],[]]},{"id":"7833904b.af11d","type":"mqtt-broker","z":"","name":"application_name","broker":"asia-se.thethings.network","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"7fb7eee3.fc934","type":"ui_group","z":"","name":"Chart","tab":"5d83a158.d5268","order":2,"disp":true,"width":"6","collapse":false},{"id":"d98f26c6.56b8b8","type":"ui_group","z":"","name":"Gauge","tab":"5d83a158.d5268","order":1,"disp":true,"width":"6","collapse":false},{"id":"9a2e91ee.5594a","type":"ui_group","z":"","name":"Others","tab":"5d83a158.d5268","order":3,"disp":true,"width":"6","collapse":false},{"id":"5d83a158.d5268","type":"ui_tab","z":"","name":"Home","icon":"timeline"}]
Advertisements

Displaying data from RHF1S001 in node-red


rhf1s001The RisingHF’s Temperature and humidity LoRaWAN sensor node RHF1S001 is aimed at outdoor application with it’s IP64 protection level. And thanks to it’s high performance internal antenna and LoRa technology used, the sensor could operate in extremely hard environment or ultra-long range application. In addition to all above, the ultra-low sleep current help it to work in a long life, 5 years (uplink every 2 minutes) or even 10 (uplink every 5 minutes) years.

Here is sample code to displaying data to dashboard node-red, Raw data taken from MQTT convert to JSON Object.

Screenshot from 2018-07-03 07-53-19

[{"id":"4e63f2ca.376b64","type":"mqtt in","z":"b6605d08.a927b","name":"","topic":"thrf/#","qos":"2","broker":"ce3645f8.a18d78","x":70,"y":2920,"wires":[["9c30a7cc.16ac38"]]},{"id":"a4fb0e04.52f6b","type":"function","z":"b6605d08.a927b","name":"decode temp","func":"var obj = msg.payload;\nvar data = obj.data;\n\nvar temp1 = data.toString().substr(2, 2);\nvar temp2 = data.toString().substr(4, 2);\nvar temp = temp2 + temp1;\n// var tmp = \"0x\" + temp; \n\nfunction hexToDec(hex) {\n return hex.toLowerCase().split('').reduce( (result, ch) =>\n result * 16 + '0123456789abcdefgh'.indexOf(ch), 0);\n}\n\nvar value = hexToDec(temp);\n\nvar t = ((175 * value)/65536) - 46.85;\n\nmsg.payload = t.toFixed(2);\n// return msg;\n// msg.payload = obj.data;\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":2980,"wires":[["db7f0faf.eec008"]]},{"id":"de0b9d41.21bd3","type":"function","z":"b6605d08.a927b","name":"data","func":"var obj = msg.payload;\nmsg.payload = obj.data;\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":2920,"wires":[["88553271.5b5678"]]},{"id":"88553271.5b5678","type":"debug","z":"b6605d08.a927b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":2920,"wires":[]},{"id":"9c30a7cc.16ac38","type":"json","z":"b6605d08.a927b","name":"","property":"payload","action":"obj","pretty":true,"x":210,"y":2920,"wires":[["de0b9d41.21bd3","a4fb0e04.52f6b","3ef4e4a1.49fcac","cbbcecc.d9fbc9"]]},{"id":"3ef4e4a1.49fcac","type":"function","z":"b6605d08.a927b","name":"decode hum","func":"var obj = msg.payload;\nvar data = obj.data;\n\n\nvar humidity = data.toString().substr(6, 2);\n// var hum = \"0x\" + humidity; \n\nfunction hexToDec(hex) {\n return hex.toLowerCase().split('').reduce( (result, ch) =>\n result * 16 + '0123456789abcdefgh'.indexOf(ch), 0);\n}\n\nvar value = hexToDec(humidity);\n\n\nvar RH = (((125 * value)/256) -6);\n\nmsg.payload = RH.toFixed(2);\n\n// return msg;\n// msg.payload = obj.data;\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":3040,"wires":[["3dd9c892.32f9b8"]]},{"id":"cbbcecc.d9fbc9","type":"function","z":"b6605d08.a927b","name":"decode batt","func":"var obj = msg.payload;\nvar data = obj.data;\nvar batt = data.toString().substr(16, 2);\n\nfunction hexToDec(hex) {\n return hex.toLowerCase().split('').reduce( (result, ch) =>\n result * 16 + '0123456789abcdefgh'.indexOf(ch), 0);\n}\n\n\n\nmsg.payload = (hexToDec(batt) + 150) * 0.01;\n\n// msg.payload = RH.toFixed(2);\n\n// return msg;\n// msg.payload = obj.data;\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":3100,"wires":[["c70731a.a7ba85"]]},{"id":"3dd9c892.32f9b8","type":"ui_chart","z":"b6605d08.a927b","name":"","group":"44b692c4.bec04c","order":0,"width":0,"height":0,"label":"hum rhf","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":640,"y":3040,"wires":[[],[]]},{"id":"c70731a.a7ba85","type":"ui_chart","z":"b6605d08.a927b","name":"","group":"44b692c4.bec04c","order":0,"width":0,"height":0,"label":"batt rhf","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":640,"y":3100,"wires":[[],[]]},{"id":"db7f0faf.eec008","type":"ui_chart","z":"b6605d08.a927b","name":"","group":"44b692c4.bec04c","order":0,"width":0,"height":0,"label":"temperture rhf","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":660,"y":2980,"wires":[[],[]]},{"id":"ce3645f8.a18d78","type":"mqtt-broker","z":"","name":"loralocal","broker":"00.00.00.00","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"44b692c4.bec04c","type":"ui_group","z":"","name":"RHF","tab":"b031aecd.a463f","order":1,"disp":true,"width":"6","collapse":false},{"id":"b031aecd.a463f","type":"ui_tab","z":"","name":"GATEWAY","icon":"desktop_mac","order":2}]

Datasheet sensor

http://www.risinghf.com/#/product-details?product_id=1&lang=en

lora mini dev and ttn


lora_mini_devKali ini nyobain lora module buatan dragino namanya lora mini dev, uniknya dari module ini adalah sudah jadi satu antara RF dan mikro kontrollernya, untuk programmingnya sendiri cukup mudah karena sudah ada usb nya jadi tinggal colok aja mikro usb bawaannya terus bisa diprogram menggunakan arduino ide.

Reviewnya menyusul ya ini tadi baru  test OTAA ke thethingsnetwork si lancar jaya cuman awalnya sempat bingung untuk pin mapping lmicnya, soalnya nyari nyari didokumentasinya ngga nemu.

Beruntung banget pas lagi browsing nemu, nah dibawah ini adalah pinout mappingnya karena kalau pinout ini salah dijamin lora mini dev ini ngga akan bekerja di lmic

 const lmic_pinmap lmic_pins = {
 .nss = 10,
 .rxtx = LMIC_UNUSED_PIN,
 .rst = 9,
 .dio = {2, 6, 7},
};

Silahkan yang pingin nyoba nyoba ini modul bisa pake lmic standard tinggal nanti menyesuaikan lmicnya seperti diatas.

kalau mau liat2 codingannya ke github saya disini tinggal ganti lmicnya seperti diatas

Happy Coding ..

Salam ngoprek …

connect to mqtt thethingsnetwork (ttn)


Akhirnya setelah kesana kemari browsing ketemu juga cara mqtt ke ttn kebetulan belakangan ini lagi iseng2 main lora dan gampangnya karena belum punya server sendiri saya pakai thethingsnetwork.org untuk test upload data ke server.

Nah semingguan ini saya penasaran ada ngga ya cara paling mudah untuk konek ke server ttn tanpa harus masuk ke console ttn, nah akhirnya ketemu juga caranya ternyata data kita di ttn bisa dibaca lewat mqtt.

Dengan mosquitto_sub kita bisa mengakses data di ttn, postingan ini sekali lagi bukan buat show off cuman sebagai catatan pribadi saya dan siapa tau bisa berguna buat yang lain juga.

mosquitto_sub -h <server>.thethings.network -t '+/devices/+/up' -u '<nama appid>' -P 'ttn-account-v2.<accesskey>' -v

Ganti beberapa paramater berikut saya bolak balik nyari akhirnya ketemu juga

  • <server> = server yang kita gunakan untuk upload data ke server ttn karena saya pake ttn handler asia sebagai server maka <server> saya ganti dengan asia-se
  • <nama appid> = lihat settingan di ttn ganti dengan Application ID
  • <access key> = ganti dengan access keys di bagian bawah applications

kalau berhasil maka di terminal kita akan muncul random text yang isinnya uplink data kita ke ttn atau mau lihat yang lain juga bisa baca baca formatnya disini

Semoga bermanfaat lanjut ngoprek …

Setting raspberry pi sebagai mongo db server


Hari ini kita akan membuat raspberry pi sebagai mongo db server agar bisa diakses dari mana saja sebagai rest api server, untuk instalasi mongo db di raspberry pi silahkan cari tutorial yang lain ya, untuk menjadikan raspberry pi sebagai mongo db server caranya cukup mudah yang pertama adalah buka lewat terminal /etc/mongod.conf

sudo nano /etc/mongod.conf

lalu edit di bagian bind hapus # didepan bind_ip lalu masukkan ip dari raspberry kita menjadi seperti dibawah ini

bind_ip = 127.0.0.1,192.168.0.100 //pisahkan dengan koma ip raspberri kita

done selesai setting mongod.conf langakah selanjutnya adalah restart service mongodb

sudo service mongodb restart

selanjutnya adalah kita membuat user di mongo db, dengan langkah sebagai berikut

use namadb //nama db bisa diganti sesuka hati

db.addUser({user : "admin", pwd:"password1234", roles :["readWrite","dbAdmin" ] })

selanjutnya adalah kita coba masukkan data yang nantinya bisa dipanggil dan ditampilkan caranya gampang kalau mau lebih lengkap silahkan baca doc mongodb, dan jangan lupa cek dulu versi mongo db yang kita gunakan.

untuk memasukkan data via terminal caranya gampang tinggal ketikkan perintah dibawah

db.user.insert({ nama : "eko" , email: "email@gmail.com", phone :"bla bla"}) //user adalah nama table silahkan ganti sesuai kebutuhan

Silahkan masukkan sesuka hati datanya mau berapa banyak, untuk memeriksa apakah data tadi masuk ketikkan

db.user.find() //user adalah nama table silahkan ganti sesuai kebutuhan

 

Done selesai kalau mau coba silahkan coba script dibawah ini saya menggunakan express js dan monggoClient untuk mengakses mongodb

Dibawah ini hasil coba coba saya menggunakan mongo db, Good Luck

https://github.com/susiloharjo/mongoexpress.git

Happy Coding

Membuat git server sendiri di raspberry pi


credit pict by https://www.git-tower.com

Tentu sudah kenal dengan git dong, git adalah

free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git dikembangkan oleh linus torvalds yang penemu linux itu, mungkin waktu itu dia asyik2 coding eh kesulitan memonitor perubahan perubahan atau buat alternatif alternatif coding yang sangat banyak dan harus juga bekerja sama dengan banyak orang yang akhirnya riweh sendiri karena masing masing orang punya cara dan style sendiri2 didalam pemrograman akhirnya dibuatlah git.

Bagi programmer yang levelnya medium to advance  pasti rata rata sudah menggunakan tools ini untuk mempermudah dan mentrace coding codingnya apalagi untuk programmer yang bekerja dengan banyak team, tentu saja git ini sangat berguna sekali.

Kalau kita bicara tentang git sudah sangat banyak sekali git server yang gratis yang biasa digunakan untuk menaruh file file kita di internet sehingga bisa digunakan sendiri maupun bersama rekan rekan yang lain , adapun git server tersebut adalah

  1. github.com
  2. gitlab.com
  3. bitbucket
  4. dll

Nah semua tempat yang sebutkan diatas adalah gratis tapi ada tapinya untuk file file yang ditaruh disana sifatnya adalah public, sehingga semua orang bisa mengaksesnya. Lalu bagaimana supaya kita bisa membuat git server sendiri dan hanya bisa diakses oleh kita atau team kita, maka dibawah ini saya akan sharing bagaimana caranya membuat raspberry pi sebagai git server.

Pertama tama yang harus disiapkan adalah tentu saja raspberry pi, lalu pastikan raspberry pi terkoneksi dengan internet sehingga kita bisa menginstall git servernya karena kita perlu mendownload beberapa aplikasi untuk menjalankan git server tersebut.

Ok setelah semua siap maka kita perlu memastikan raspberry pi telah menggunakan update software terakhir lakukan.

sudo apt-get update && sudo apt-get install -y

Setelah selesai maka kita tinggal menginstall software git server lakukan perintah dibawah ini

sudo apt-get install wget git-core

Setelah selesai maka kita bisa menset directrory mana yang akan kita gunakan untuk menaruh file kita, bisa di dalam flashdisk atau hardisk tambahan atau kalau ngga ya cukup di taruh di home. Anggap lah kita akan menaruhnya di /home, maka lakukan langkah berikut

mkdir /home/pi/git

Setelah selesai maka ketikkan didalam folder yang tadi sudah kita buat

git init --bare

Done selesai, langkah selanjutnya tinggal mengakses folder yang sudah kita buat di raspberry kita tadi, caranya adalah kita bisa menggunakan komputer yang berbeda untuk mengetest apakah git server kita tadi sudah berhasil jalan apa tidak.

Continue reading Membuat git server sendiri di raspberry pi

Jquery select on change function


Kali ini bermain main dengan jquery select on change, bermain main dengan jquery itu ternyata menyenangkan juga, baru kali ini mulai belajar belajar lagi jquery. Kali ini saya ingin sharing tentang cara bagaimana bermain main dengan form dengan jquery, kali ini saya menggabungkan fungsi select dan input, jadi ketika kita memilih select option tertentu maka akan mempengaruhi input box dalam hal ini saya menggunakan class yang sudah ada di html yaitu class required dan disabled, langsung saja kira kira seperti ini scriptnya.

Pertama tama tentu saja kita sudah memastikan jquery sudah terload

https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js

Selanjutnya adalah membuat select dan input di html

<select id="metode" required name="metode" class="form-control">
 <option value="Cash">Cash</option>
 <option value="Debit">Debit</option>
 <option value="Kredit">Kredit</option>
</select>

 <select name="bank" id="bank" disabled class="form-control">
 <option value="">Pilih Bank</option>
 <option value="Mandiri">Mandiri</option>
 <option value="Danamon">Danamon</option>
 <option value="BRI">BRI</option>
 <option value="BNI">BNI</option>
 <option value="BCA">BCA</option>
 <option value="Bukopin">Bukopin</option>
 <option value="CIMB Niaga">CIMB Niaga</option>
 <option value="Mayapada">Mayapada</option>
 <option value="Muamalat">Muamalat</option>
 <option value="BTN">BTN</option>
 </select>

 <input id="kartu" name="kartu" disabled placeholder="Nomor Kartu" class="form-control" type="text">

Continue reading Jquery select on change function