Skip to content

Instantly share code, notes, and snippets.

@dexif

dexif/README.md Secret

Created April 5, 2021 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexif/096a9a0f9f4da12f6168c0054abe5d7f to your computer and use it in GitHub Desktop.
Save dexif/096a9a0f9f4da12f6168c0054abe5d7f to your computer and use it in GitHub Desktop.
flespi device exceeded certain storage size - telegram notification

Example of telegram notifications that the flespi device storage is full to a certain volume.

In the subscribe command, you must now specify the size, when exceeding which you want to receive a notification in the telegram messenger:

/subscribe messages_size 1024

(1024 in this example is the storage size in bytes)

[
{
"id": "26fdb68f.692cda",
"type": "tab",
"label": "Device messages size",
"disabled": false,
"info": ""
},
{
"id": "3351aaec.720636",
"type": "mqtt in",
"z": "26fdb68f.692cda",
"name": "",
"topic": "flespi/state/gw/devices/+/messages_size",
"qos": "2",
"datatype": "utf8",
"broker": "b76fa1b5.ce51",
"x": 180,
"y": 160,
"wires": [
[
"1cb53414.e2676c"
]
]
},
{
"id": "261b1a03.6b9416",
"type": "debug",
"z": "26fdb68f.692cda",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 830,
"y": 100,
"wires": []
},
{
"id": "1cb53414.e2676c",
"type": "trigger",
"z": "26fdb68f.692cda",
"name": "",
"op1": "",
"op2": "",
"op1type": "nul",
"op2type": "payl",
"duration": "10",
"extend": false,
"overrideDelay": false,
"units": "s",
"reset": "",
"bytopic": "topic",
"topic": "topic",
"outputs": 1,
"x": 430,
"y": 160,
"wires": [
[
"e76f4405.0dbae8"
]
]
},
{
"id": "176adc5c.727354",
"type": "telegram sender",
"z": "26fdb68f.692cda",
"name": "",
"bot": "6eaebea0.ccff3",
"haserroroutput": false,
"outputs": 1,
"x": 850,
"y": 160,
"wires": [
[]
]
},
{
"id": "f27f7ff3.4ea52",
"type": "telegram receiver",
"z": "26fdb68f.692cda",
"name": "",
"bot": "6eaebea0.ccff3",
"saveDataDir": "",
"filterCommands": false,
"x": 390,
"y": 100,
"wires": [
[
"9d23cf10.cad8d"
],
[
"9d23cf10.cad8d"
]
]
},
{
"id": "e76f4405.0dbae8",
"type": "function",
"z": "26fdb68f.692cda",
"name": "Prepre telegram message",
"func": "var id = msg.topic.split('/')[4]\nvar chats = flow.get('chats') || {}\nvar devices = flow.get('devices') || {}\nvar messages = []\nvar current_size = parseInt(msg.payload)\nfor (var chatId in chats) {\n if (\n current_size >= chats[chatId] && \n (devices[id] || 0) < chats[chatId] && \n devices[id] < current_size\n ) {\n messages.push({topic: msg.topic, payload: {content: `Device ${id} is using too much storage (${current_size})`, type: 'message', chatId: chatId}})\n }\n}\ndevices[id] = current_size\nflow.set('devices', devices)\nreturn [messages]",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 630,
"y": 160,
"wires": [
[
"176adc5c.727354",
"261b1a03.6b9416"
]
]
},
{
"id": "9d23cf10.cad8d",
"type": "function",
"z": "26fdb68f.692cda",
"name": "Process commands",
"func": "var chats = flow.get('chats') || {}\nif (msg.payload.content.indexOf('/subscribe messages_size') == 0) {\n chats[msg.payload.chatId] = parseInt(msg.payload.content.replace('/subscribe messages_size', ''))\n}\nif (msg.payload.content === '/unsubscribe messages_size') {\n delete chats[msg.payload.chatId]\n}\nflow.set('chats', chats)\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "flow.set('chats', {})",
"finalize": "",
"x": 610,
"y": 100,
"wires": [
[
"261b1a03.6b9416"
]
]
},
{
"id": "9782a1dc.04acf",
"type": "comment",
"z": "26fdb68f.692cda",
"name": "Please use \"/subscribe messages_size 1024\" bot command after each restart (1024 bytes)",
"info": "",
"x": 330,
"y": 40,
"wires": [],
"icon": "node-red/alert.svg"
},
{
"id": "b76fa1b5.ce51",
"type": "mqtt-broker",
"name": "",
"broker": "mqtt.flespi.io",
"port": "1883",
"clientid": "noderedtest",
"usetls": false,
"compatmode": false,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "6eaebea0.ccff3",
"type": "telegram bot",
"botname": "Telegram notify bot",
"usernames": "",
"chatids": "",
"baseapiurl": "",
"updatemode": "polling",
"pollinterval": "300",
"usesocks": false,
"sockshost": "",
"socksport": "6667",
"socksusername": "anonymous",
"sockspassword": "",
"bothost": "",
"botpath": "",
"localbotport": "8443",
"publicbotport": "8443",
"privatekey": "",
"certificate": "",
"useselfsignedcertificate": false,
"sslterminated": false,
"verboselogging": false
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment