Ta strona wygląda najlepiej z włączoną obsługą JavaScript

Jak zaimplementować timer Pomodoro używając Node-RED w Ulanzi TC001

 ·  ☕ 4 min czytania  ·  🐧 sysadmin
  1. Skopiuj schemat
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
[
    {
        "id": "work-timer-start",
        "type": "inject",
        "z": "305da690670f67c0",
        "name": "Start Work Timer",
        "props": [{"p": "payload"}],
        "repeat": "",
        "crontab": "",
        "once": false,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 100,
        "wires": [["work-timer-function"]]
    },
    {
        "id": "work-timer-function",
        "type": "function",
        "z": "305da690670f67c0",
        "name": "Countdown Timer",
        "func": "var duration = 25 * 60; // 25 minutes in seconds\nfunction countdown() {\n    if (flow.get('workTimerRunning') === false) {\n        return;\n    }\n    var message = {\n        payload: {\n            text: 'Time left: ' + duration + ' sec',\n            icon: \"82\",\n            color: '#FFA500',\n            duration: 1500\n        }\n    };\n    node.send(message);\n    duration--;\n    if (duration >= 0) {\n        setTimeout(countdown, 1000);\n    } else {\n        var endMessage = {\n            payload: {\n                text: 'Work Period Ended',\n                icon: \"29802\",\n                color: '#00FF00',\n                duration: 20\n            }\n        };\n        node.send(endMessage);\n    }\n}\nflow.set('workTimerRunning', true);\ncountdown();\nreturn null;",
        "outputs": 1,
        "x": 300,
        "y": 100,
        "wires": [["mqtt-out-work"]]
    },
    {
        "id": "mqtt-out-work",
        "type": "mqtt out",
        "z": "305da690670f67c0",
        "name": "MQTT Work Timer",
        "topic": "awtrix_b6d76c/custom/work_timer",
        "broker": "346df2a95aac5785",
        "x": 500,
        "y": 100,
        "wires": []
    },
    {
        "id": "work-timer-stop",
        "type": "inject",
        "z": "305da690670f67c0",
        "name": "Stop Work Timer",
        "props": [{"p": "payload"}],
        "repeat": "",
        "crontab": "",
        "once": false,
        "topic": "",
        "payload": "stop",
        "payloadType": "str",
        "x": 100,
        "y": 160,
        "wires": [["stop-work-timer-function"]]
    },
    {
        "id": "stop-work-timer-function",
        "type": "function",
        "z": "305da690670f67c0",
        "name": "Stop Work Timer Function",
        "func": "flow.set('workTimerRunning', false);\nvar message = {\n    payload: {\n        text: 'Work Timer Stopped',\n        icon: \"29802\",\n        color: '#FF0000',\n        duration: 20\n    }\n};\nreturn message;",
        "outputs": 1,
        "x": 300,
        "y": 160,
        "wires": [["mqtt-out-work"]]
    },
    {
        "id": "break-timer-start",
        "type": "inject",
        "z": "305da690670f67c0",
        "name": "Start Break Timer",
        "props": [{"p": "payload"}],
        "repeat": "",
        "crontab": "",
        "once": false,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 200,
        "wires": [["break-timer-function"]]
    },
    {
        "id": "break-timer-function",
        "type": "function",
        "z": "305da690670f67c0",
        "name": "Break Countdown Timer",
        "func": "var duration = 5 * 60; // 5 minutes in seconds\nfunction countdown() {\n    if (flow.get('breakTimerRunning') === false) {\n        return;\n    }\n    var message = {\n        payload: {\n            text: 'Break time left: ' + duration + ' sec',\n            icon: \"6396\",\n            color: '#FFA500',\n            duration: 300\n        }\n    };\n    node.send(message);\n    duration--;\n    if (duration >= 0) {\n        setTimeout(countdown, 1000);\n    } else {\n        var endMessage = {\n            payload: {\n                text: 'Break Period Ended',\n                icon: \"29802\",\n                color: '#00FF00',\n                duration: 20\n            }\n        };\n        node.send(endMessage);\n    }\n}\nflow.set('breakTimerRunning', true);\ncountdown();\nreturn null;",
        "outputs": 1,
        "x": 300,
        "y": 200,
        "wires": [["mqtt-out-break"]]
    },
    {
        "id": "mqtt-out-break",
        "type": "mqtt out",
        "z": "305da690670f67c0",
        "name": "MQTT Break Timer",
        "topic": "awtrix_b6d76c/custom/break_timer",
        "broker": "346df2a95aac5785",
        "x": 500,
        "y": 200,
        "wires": []
    },
    {
        "id": "break-timer-stop",
        "type": "inject",
        "z": "305da690670f67c0",
        "name": "Stop Break Timer",
        "props": [{"p": "payload"}],
        "repeat": "",
        "crontab": "",
        "once": false,
        "topic": "",
        "payload": "stop",
        "payloadType": "str",
        "x": 100,
        "y": 260,
        "wires": [["stop-break-timer-function"]]
    },
    {
        "id": "stop-break-timer-function",
        "type": "function",
        "z": "305da690670f67c0",
        "name": "Stop Break Timer Function",
        "func": "flow.set('breakTimerRunning', false);\nvar message = {\n    payload: {\n        text: 'Break Timer Stopped',\n        icon: \"29802\",\n        color: '#FF0000',\n        duration: 20\n    }\n};\nreturn message;",
        "outputs": 1,
        "x": 300,
        "y": 260,
        "wires": [["mqtt-out-break"]]
    }
]
  1. Zmień prefix awtrix_b6d76c na własny.

  2. Zaimportuj schemat do Node-RED, tak jak przedstawiłem na filmie.

  3. Prześlij ikony na swoje urządzenie Ulanzi TC001, tak jak pokazałem na filmie. Możesz użyć ikon stąd: ikony

  4. Sprawdź łączność z twoim brokerem MQTT.

  5. Zmień schemat według swoich potrzeb.

  6. Wdroż schemat na urządzenie Ulanzi TC001.

Podziel się

sysadmin
UTWORZONE PRZEZ
sysadmin
QA & Linux Specialist