Librus Synergia: new school grades & notes → MQTT / SMS
Checks the Polish school register Librus Synergia on a school-day schedule and sends new grades and teacher notes – with what they are for – to MQTT, ready for an SMS gateway.
Requires the node node-red-contrib-afya-librus (npm install node-red-contrib-afya-librus).
Schedule
- 07:00–15:00 – every 45 min (inject + a small time filter; change
OD/DOat the top of the function), - 15:00–21:00 – every hour,
- 22:00–07:00 – no checks.
Hours use the time zone of the Node-RED server – set TZ=Europe/Warsaw.
MQTT topics
| Topic | When | Payload |
|---|---|---|
librus/dane (retained) |
after every check | full result: ok, nowe, oceny, tablica, uwagi … or ok: false + blad |
librus/sms/json |
only when something is new | { "do", "tresc", "od", "flash" } for an SMS gateway |
librus/sms/tekst |
only when something is new | plain SMS text |
Keep the variant your SMS gateway uses and delete the other one.
Setup
- Set the Librus login and password in Librus – oceny (stored as Node-RED credentials).
- Set the broker address in the MQTT nodes.
- Set the phone number(s) and the sender name in SMS jako JSON.
- Click test SMS – the latest grade is reported as new, so you can check the whole path at once.
The first check only remembers the current grades, so you do not get an SMS with the whole school year.
Example SMS:
Librus Kowalski Jaś: 4[1](2) z Matematyka (Kartkówka) | oceny: 5(3), 3-(2), +, 4[1](2)
Librus Kowalski Jaś: uwaga negatywna – Brak zadania domowego (Testowa Anna)
4[1](2) = 4 after improving 1, weight 2.
Polski
Sprawdza dziennik Librus Synergia według harmonogramu i wysyła nowe oceny i uwagi – z informacją, za co – do MQTT, gotowe dla bramki SMS.
- 7:00–15:00 co 45 min, 15:00–21:00 co godzinę, 22:00–7:00 bez sprawdzeń (ustaw
TZ=Europe/Warsaw), librus/dane(retain) – pełny wynik po każdym sprawdzeniu,librus/sms/json–{ do, tresc, od, flash }, tylko gdy coś nowego,librus/sms/tekst– sam tekst SMS, tylko gdy coś nowego.
Po imporcie ustaw login i hasło w węźle Librus – oceny, adres brokera w węzłach MQTT, numer i nadawcę w SMS jako JSON, a potem kliknij test SMS. Pierwsze sprawdzenie tylko zapamiętuje oceny.
Unofficial project, not affiliated with Librus. / Projekt nieoficjalny, niezwiązany z firmą Librus.
[{"id":"b7a1c0de00000001","type":"comment","name":"Librus → MQTT · 7–15 co 45 min · 15–21 co 1 h · noc 22–7 cisza","info":"## Harmonogram\n\n* **Zegar 1** – inject co 45 min; filtr przepuszcza go tylko między 7:00 a 15:00.\n* **Zegar 2** – inject co godzinę 15:00–21:00 (ostatnie sprawdzenie 21:00).\n* **22:00–7:00** – nic nie jest sprawdzane.\n\nGodziny liczone wg strefy czasowej serwera Node-RED (ustaw `TZ=Europe/Warsaw`).\n\n## MQTT\n\n| Temat | Kiedy | Treść |\n|---|---|---|\n| `librus/dane` (retain) | po każdym sprawdzeniu | cały wynik: `ok`, `nowe`, `oceny`, `tablica`, `uwagi`… albo `ok:false` + `blad` |\n| `librus/sms/json` | tylko gdy coś nowego | wariant A: `{ \"do\", \"tresc\", \"od\", \"flash\" }` |\n| `librus/sms/tekst` | tylko gdy coś nowego | wariant B: zwykły tekst SMS |\n\nZostaw wariant, którego używa Twoja bramka SMS, drugi możesz usunąć.\n\n## Do ustawienia\n\n1. Login i hasło w węźle **Librus – oceny**.\n2. Adres brokera w węzłach MQTT.\n3. Numer(y) i nadawcę w węźle **SMS jako JSON**.\n4. Kliknij **test SMS**, żeby od razu sprawdzić całą ścieżkę.","x":290,"y":40,"wires":[]},{"id":"b7a1c0de00000002","type":"inject","name":"zegar 1: co 45 min","props":[],"repeat":"2700","crontab":"","once":true,"onceDelay":"20","topic":"","x":160,"y":100,"wires":[["b7a1c0de00000003"]]},{"id":"b7a1c0de00000003","type":"function","name":"tylko 7:00–15:00","func":"// Zegar 1 przepuszczamy tylko w godzinach szkolnych.\n// Po 15:00 pracuje zegar 2 (co godzinę do 21:00), w nocy 22–7 cisza.\nconst OD = 7; // od tej godziny\nconst DO = 15; // do tej godziny (bez niej)\n\nconst teraz = new Date();\nconst godz = teraz.toLocaleTimeString('pl-PL', { hour: '2-digit', minute: '2-digit' });\nif (teraz.getHours() >= OD && teraz.getHours() < DO) {\n node.status({ fill: 'green', shape: 'dot', text: 'sprawdzam · ' + godz });\n return msg;\n}\nnode.status({ fill: 'grey', shape: 'ring', text: 'poza ' + OD + '–' + DO + ' · ' + godz });\nreturn null;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":100,"wires":[["b7a1c0de00000006"]]},{"id":"b7a1c0de00000004","type":"inject","name":"zegar 2: co 1 h, 15–21","props":[],"repeat":"","crontab":"0 15-21 * * *","once":false,"onceDelay":0.1,"topic":"","x":170,"y":160,"wires":[["b7a1c0de00000006"]]},{"id":"b7a1c0de00000005","type":"inject","name":"test SMS","props":[{"p":"test","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":220,"wires":[["b7a1c0de00000006"]]},{"id":"b7a1c0de00000006","type":"afya-librus","name":"Librus – oceny","szablon":"","bezPl":false,"zTablica":true,"uwagi":true,"szablonUwagi":"","x":620,"y":160,"wires":[["b7a1c0de00000007","b7a1c0de00000008","b7a1c0de0000000d"]]},{"id":"b7a1c0de00000007","type":"mqtt out","name":"librus/dane","topic":"librus/dane","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"b7a1c0de0000000e","x":880,"y":100,"wires":[]},{"id":"b7a1c0de00000008","type":"switch","name":"coś nowego?","property":"payload.tekst","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":870,"y":180,"wires":[["b7a1c0de00000009","b7a1c0de0000000b"]]},{"id":"b7a1c0de00000009","type":"function","name":"SMS jako JSON","func":"// Wariant A – obiekt JSON dla bramki SMS: { do, tresc, od, flash }\nconst NUMERY = '48600000000'; // numer odbiorcy; kilka po przecinku: '48600000000,48600000001'\nconst NADAWCA = 'DZIENNIK'; // pole „od” – nazwa nadawcy SMS\n\nmsg.payload = {\n do: NUMERY,\n tresc: msg.payload.tekst,\n od: NADAWCA,\n flash: false\n};\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":160,"wires":[["b7a1c0de0000000a"]]},{"id":"b7a1c0de0000000a","type":"mqtt out","name":"librus/sms/json","topic":"librus/sms/json","qos":"1","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"b7a1c0de0000000e","x":1300,"y":160,"wires":[]},{"id":"b7a1c0de0000000b","type":"change","name":"SMS jako tekst","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.tekst","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":220,"wires":[["b7a1c0de0000000c"]]},{"id":"b7a1c0de0000000c","type":"mqtt out","name":"librus/sms/tekst","topic":"librus/sms/tekst","qos":"1","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"b7a1c0de0000000e","x":1300,"y":220,"wires":[]},{"id":"b7a1c0de0000000d","type":"debug","name":"wynik","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":850,"y":260,"wires":[]},{"id":"b7a1c0de0000000e","type":"mqtt-broker","name":"broker MQTT","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]