Skip to content

Instantly share code, notes, and snippets.

@milosjovac
milosjovac / gist:29b748244206378a39cf19f5c2fe6bb9
Last active January 19, 2018 14:56
Node-Red minimal flow for error - MQTT node is not reconnecting
[{
"id": "e52504bc.b70398",
"type": "tab",
"label": "Flow 1"
}, {
"id": "fa569fa9.8b626",
"type": "tls-config",
"z": "",
"name": "Server Cert Only",
"cert": "",
[{
"id": "4b69ebbb.ef6144",
"type": "modbus-getter",
"z": "a0a135f0.1c2668",
"name": "Hz",
"showStatusActivities": true,
"showErrors": true,
"unitid": "1",
"dataType": "HoldingRegister",
"adr": "272",
0x00ce9F958957f1f8A0059f36004f8aF9E4814006
@milosjovac
milosjovac / mongoose.js
Last active September 20, 2017 12:24
Permanent mongoose connection
var mongoose = require('mongoose')
let dbURI = 'localhost:27017/laimdb'
var timeToWaitOnConnection = 3000 // 3sec
var maxTimeToWaitOnConnection = 30000 // 30sec
mongoose.connection.on('error', function (error) {
console.error('Error in MongoDb connection: ' + error)
mongoose.disconnect() // force disconnect since connection.readyState is still 1
})
// PRIVATE - no need for permissions here
// private dir in internal storage:
Context.getFilesDir(); // system doesn't clean this memory, put sensitive user data here. Not even user can read this files
Context.getCacheDir(); // system will clear this when low on memory
// (app specific) private dir in "external"(readable by all apps with READ/WRITE_EXTERNAL_STORAGE_PERMISSION) storage
Context.getExternalFilesDir();
Context.getExternalFilesDirs(); // plural! As of KitKat it returns "external" directory folder, but also one from the SD card
Context.getExternalCacheDir();
Context.getExternalCacheDirs(); // same here