MQTT Client lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Mi-Ki · 2024-12-22 08:02 Good morning. I have Mosquitto MQTT Broker on my raspberry. I have a switch that I control via the terminal and it works. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mosquitto_pub -t 'zigbee2mqtt/0xa4c138dfe4ce8c20/set' -m '{ "state_left": "TOGGLE" }' How to do this via lazarus? https://github.com/cutec-chris/TMQTTClient This works but writes an error. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MQTTClient.Publish('zigbee2mqtt/0xa4c138dfe4ce8c20/set', '{ "state_left": "TOGGLE" }'); Is this library good or used by another? Thank you. ---------------------------------------------------------------------- cdbc · 2024-12-22 08:35 Hi Edited later: The entire MQTT-Framework being worked with in this thread is released on my GitLab repo, referenced HERE. With that little code, it's hard to tell...  You could also take a look here to see if there should be a solution to your conundrum... Regards Benny ---------------------------------------------------------------------- Mi-Ki · 2024-12-23 07:45 Quote from: cdbc on December 22, 2024, 09:35:09 amHi With that little code, it's hard to tell...  You could also take a look here to see if there should be a solution to your conundrum... Regards Benny Hi. I have MQTT installed but I don't know how to do it. Any sample, demo? Thank you. ---------------------------------------------------------------------- cdbc · 2024-12-23 08:13 Hi There are 3 demo apps included in directory 'Apps', I thought there would be something you could use...? I don't do 'LNet' but give me some time, then I can rewrite the demos to use 'Synapse' or 'Indy'... I've just swiftly glanced over it, as I haven't needed it yet... The 'MQTTClient' looks promising. Regards Benny ---------------------------------------------------------------------- cdbc · 2024-12-27 15:20 Hi Ok, so I did some testing and ended up forking Bond Keevil's MQTT- framework, because as I tried to make it work with Synapse instead of LNet, I found his implementation lacking and he himself states, that he's not putting any more work into that. Quotehttps://github.com/cutec-chris/TMQTTClient This works but writes an error.Nope, tested against mosquitto and my own new synapse-mqtt-broker (finished last night), IT DOES NOT WORK! ...So hang on and I'll see, what can be done, /client-wise/. bkeevil's code-base is good and I can build on that, maybe even support protocol 5 and introduce plugin-architecture, for the network- backend... Regards Benny ---------------------------------------------------------------------- cdbc · 2024-12-27 18:33 Hi Here's the synapse dependent broker project attached: Regarding the 4 digit numbers in use:  - look at your phone's dial-keypad, almost every number has 3..4 letters     asociated with it, e.g.: 3 = (def) & 7 = (pqrs), so you can spell a little... The forked & changed 'mqttserver' unit is necessary for this to work... It won't work with bkeevil's version of the code! Bond Keevil's code can be found HERE and it works nicely with 'LNet'. My own fork, is private for the time being. It has been tested against 'Eclipse Mosquitto's own apps, to work. Regards Benny edit: Oooopsss: forgot to mention, it makes use of @Warfley's excellent terminal library found HERE. ---------------------------------------------------------------------- cdbc · 2024-12-28 09:30 Hi Forgot this... If you really need it, just rebase it on 'TQueue' from 'contnrs' unit... ...or buy the excellent book by Julian Bucknall: "Tomes of Delphi, Algorithms and Datastructures"  Regards Benny ---------------------------------------------------------------------- cdbc · 2024-12-29 18:18 Helllllloooooooo  Right, attached is a preliminary sneak preview of a first working /Synapse dependent/ MQTT-Client...  I've added the missing 'Queue'-piece of the puzzle, based on TQueue from 'contnrs'... Plus I made the net-connection a plugin-interface... so this project needs the forked 'mqtt.client.pas'!!! -contained in the zip. Well, anyway here it is, PRE-ALPHA Tested against mosquitto's apps and my own broker to work Have fun ---------------------------------------------------------------------- cdbc · 2025-01-08 18:49 Hi So, I've been fiddling with the client, because it came out the door in a hurry. I've fixed a lot of things and tried even more, I had hoped this was a good candidate for a 'lazy/sleeping thread' -backend, but alas, I can't seem to get the MQTT-framework to accept a repeat connection with the original values... The lazy backend does work and makes use of my new 'ITSQueue' and 'InterlockedExchange' amo. You can follow it in the live log, how it goes to sleep when 'Paused' and back to life, but the MQTT won't play nice, till now at least  I've zipped a working app with common and forked files, a bit nicer ui and (I think) no mem-leaks  Again it's been tested against 'Mosquitto' and my own broker, to work. If you want to play with the 'Lazy' /branch/ there's a compiler switch {-$define lazy} you need to enable by removing the hyphen in front As always - Have Fun Regards Benny ---------------------------------------------------------------------- cdbc · 2025-01-12 21:48 Hi For those of you who are more *Indy* inclined, here's an Indy-Netlink- plugin for you, together with 2 updated views and the other 2 polished plugins for Synapse  ...oh and the api-interface has been updated slightly, but should compile and run with the other components I've uploaded  Note: The Indy itself, you'll have to provide yourself... In the hope it can be of use to someone  Regards Benny ---------------------------------------------------------------------- cdbc · 2025-01-15 09:50 Hi Sorry, but I can't help myself... this is funny  Right, so here is a piece of kit, that'll run with fpc >= 3.2.2 straight out of the box, NO external libs required...! (...other than mqtt & mine) This plugin uses fpc's own 'fcl-net' technology... Nifty huh?  The zip contains an updated 'Main.View' too, 'cause these plugins are 'Mutually Exclusive'. In the hope, it can be of use to someone  Have fun Benny ---------------------------------------------------------------------- dbannon · 2025-01-15 10:16 OK, so I almost commented further up. See, I looked at using MQTT on a project a while ago, but was put off with all the layers necessary. When I saw you playing with Synapse, then Indy, I thought, "whats wrong with fcl-net, must be a reason " ? Nicely done Benny, I'll have a play in the unlikely event I get some spare time ! Thanks, bet its good too. Davo ---------------------------------------------------------------------- cdbc · 2025-01-15 11:39 Hi Davo Thanks mate  You know, when you go to the sandbox to play a little ...and suddenly your momma's calling 'Dinner is ready' - one gets submerged in having fun  (That analogy is my wife's from last night). I too found it too tightly coupled in the layers, so I tried to go the plugin trail, to see if I could decouple it a bit... This architecture works from 'so/dll's too. Please do, have a play and let me know what you think... Regards Benny ---------------------------------------------------------------------- Thaddy · 2025-01-15 12:33 It is better than my own -unpublished but working- implementation. I use mqtt for controlling a cluster of rpi's ( 16 x Raspberry Zero 2 W for 64 cores in total , super computing for less than 250 euro) Nice work, Benny. ---------------------------------------------------------------------- cdbc · 2025-01-15 14:06 Hi Thanks Thaddy, I'm having fun  Regards Benny ---------------------------------------------------------------------- cdbc · 2025-01-16 17:08 Hi So all this MQTT-Circus started with me *not* doing 'LNet', for networking... In order to come full circle, I /forced/ LNet upon myself and made a plugin for LNet as well  ...I was right, /I really don't like LNet, think it's weird in a roundabout sort of way/, but hey - now it's done and I don't have to touch it again, in a foreseeable future  As always, tested to work against Mosquitto and my own broker... I think now is the time for me to dive deeper into the MQTT-Abyss and have a 'LookSee'... Let me know what you think and don't hesitate to ask questions. Regards Benny ---------------------------------------------------------------------- cdbc · 2025-01-17 07:54 Hi @Thaddy: Your 'supercomputer' is rambling around in my head  - What do you use it for? - How do you partition a collective workload? - I guess, mqtt is used for comms amongst them? - All the other questions, you can think of, I probably have?!? Curious as h*ll, is what I am... Please spill... Regards Benny ---------------------------------------------------------------------- Thaddy · 2025-01-17 13:03 Depends. currently it is running dummy loads to test some MPC algorithms at the protocol level. When that is stable I will try to implement some MPC tasks from the theory. I started off with the examples from the Magpi from a few years ago. I built it just out of curiosity with no predefined plans for it. Maybe run some AI models locally. ---------------------------------------------------------------------- cdbc · 2025-01-17 13:36 Hi Thaddy Cool  Quite an interesting little project... Regards Benny ---------------------------------------------------------------------- Thaddy · 2025-01-17 15:11 BTW my mqtt code is based on a synapse version, but I am rebasing it to use fcl-net and fcl-web ---------------------------------------------------------------------- cdbc · 2025-01-17 15:18 Hi Thaddy I used the /old/(er) fcl-net, because that's what's in 3.2.2, had a look at the newer 'fpsockets' by @Warfley, but I actually don't much like 'Generics'... I don't think they should be *smeared* allover code, just because you can. ...And the generics libraries pull in a lot of code, that I mostly do not need. I actually like fcl-net and Synapse the most  Just my 2 cents worth. Regards Benny ---------------------------------------------------------------------- Thaddy · 2025-01-17 17:10 It is more that I prefer fpc-net and fcl-web since they are actively maintained. And fcl-net has some of its roots in synapse anyway. But yes, I am mostly on trunk/main and that can differ considerably from 3.2.2/3.2 fixes. ---------------------------------------------------------------------- dbannon · 2025-01-17 23:07 Quote from: Thaddy on January 15, 2025, 01:33:29 pmI use mqtt for controlling a cluster of rpi's ( 16 x Raspberry Zero 2 W for 64 cores in total , super computing for less than 250 euro) In early RasPi times, I designed, on paper, a rasberrypi supercomputer as an April Fools Day joke for our newsletter. At the time, I ran the largest supercomputer south of the Tropic of Cancer (clever claim, most big SCs are well north to cheapen cooling). My machine used tens of thousand RasPis mounted in a modified IBM tape robot, the idea being that reliability of the Pi's (OK in tens to hundreds, poor in the thousands) could be managed by automatically replacing any faulty hardware. It triggered a storm of suggestions about how we could capture a memory image before replacing a Pi so as to avoid disrupting a large MPI job. Some actually sounded (slightly) feasible. Sadly, some people did not see the joke, triggering a series of complaints that VPAC was wasting money developing a 32bit ARM system  Davo ---------------------------------------------------------------------- Thaddy · 2025-01-18 05:41 Well, these clusters such as I made exist since the early Raspberry Pi one days, more than 10 years ago. So the April fool's joke did not land for many, because these clusters were not a joke at all but a genuine introduction in MPC (massive parallel compute). Several universities and scientific institutions built RPi clusters for educational purposes. (Cambridge, MIT, Delft to name a few). It is a nice toy to have. The nice thing is that because of mqtt it scales:if you have the odd $250 lying around, build the same contraption, and feel like it, we can add clusters on the go, independent of location. Note power supply is more expensive than the boards. My setup is relatively small, I know of some really silly numbers, at least 5 times mine. Btw: it is not about the speed, it is about understanding MPC. You would not expect a toy train to reach the same speed as a TGV or Shenzen.