Re: Mqtt support in guile?
Matt Wette <[email protected]>
| Newsgroups | gmane.lisp.guile.user |
|---|---|
| Message-ID | <[email protected]> |
I got this wrong. Sorry! This is it. What I gave previously was the old fh syntax. (msg (make-cdata struct-mosquitto_message* message)) On 11/1/24 6:32 AM, Matt Wette wrote: > assuming message is a Guile pointer: > > (define (receive-message mosq obj message) > (let ((msg (make-struct-mosquitto_message* message)) > (size (cdata-ref msg '* 'payloadsize)) > (payload (cdata-ref msg '* 'payload)) > (pointer->string payload size))) > > > On 10/31/24 4:49 PM, Mikael Djurfeldt wrote: >> Hi Matt, >> >> This is very nice indeed! :-) >> >> I got a small client working, but I found the unpacking of values in >> the message callback function a bit cumbersome. I now have: >> >> (define (pointer->struct-mosquitto_message pointer) >> (let* ((size (ctype-size struct-mosquitto_message)) >> (bvec (pointer->bytevector pointer size))) >> (Xcdata-ref bvec 0 struct-mosquitto_message))) ;The only way >> I found that worked! :) >> >> (define (receive-message mosq obj message) >> (let* ((message (pointer->struct-mosquitto_message message)) >> (payload (cdata-ref message 'payload)) >> (size (cdata-ref message 'payloadlen)) >> (payload (pointer->string payload size))) >> (display payload) >> (newline))) >> >> Is there some more convenient/right way to do that? >> >> Best regards, >> Mikael >> >> On Thu, Oct 31, 2024 at 1:02 PM Matt Wette <[email protected]> wrote: >> >> On 10/31/24 1:48 AM, Ricardo G. Herdt wrote: >> > Hi, >> > >> > never did it myself, but you can create some bindings to >> libmosquitto >> > for your usecase. There are bindings for chicken, one can take >> some >> > inspiration from there: >> http://wiki.call-cc.org/eggref/5/mosquitto#api >> > >> > Regards, >> > >> > Ricardo >> > >> > Am 31.10.2024 03:24 schrieb Alan Wedel: >> >> I have been working on a controller that uses a >> microcontroller to >> >> read some sensors and publish their data to a mqtt broker. I >> would >> >> like to have a guile program subscribe to the mqtt broker and >> log the >> >> sensor readings to a file. Is there anyone using guile with >> mqtt like >> >> this? If so, how are you doing it? >> > >> >> Here is a dot-ffi file for mosquitto using nyacc: >> >> (define-ffi-module (ffi mosquitto) >> #:pkg-config "libmosquitto" >> #:include '("mosquitto.h")) >> >> >> I just uploaded nyacc-2.01.2, needed to compile above. >> >> refs: >> https://savannah.nongnu.org/projects/nyacc >> https://www.nongnu.org/nyacc/nyacc-fh-ug.html >> >> Matt >> >> >> >> >>