unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Mqtt support in guile?
@ 2024-10-31  2:24 Alan Wedel
  2024-10-31  8:17 ` Nala Ginrut
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Alan Wedel @ 2024-10-31  2:24 UTC (permalink / raw)
  To: guile-user

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?


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-10-31  2:24 Mqtt support in guile? Alan Wedel
@ 2024-10-31  8:17 ` Nala Ginrut
  2024-10-31  8:48 ` Ricardo G. Herdt
  2024-11-09 15:50 ` Mikael Djurfeldt
  2 siblings, 0 replies; 13+ messages in thread
From: Nala Ginrut @ 2024-10-31  8:17 UTC (permalink / raw)
  To: Alan Wedel; +Cc: Guile User

If there's no any, I hope someone can do it.

Best regards.

On Thu, Oct 31, 2024, 11:25 Alan Wedel <alanwedel19@gmail.com> wrote:

> 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?
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-10-31  2:24 Mqtt support in guile? Alan Wedel
  2024-10-31  8:17 ` Nala Ginrut
@ 2024-10-31  8:48 ` Ricardo G. Herdt
  2024-10-31 12:01   ` Matt Wette
  2024-11-09 15:50 ` Mikael Djurfeldt
  2 siblings, 1 reply; 13+ messages in thread
From: Ricardo G. Herdt @ 2024-10-31  8:48 UTC (permalink / raw)
  To: Alan Wedel; +Cc: guile-user

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?



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-10-31  8:48 ` Ricardo G. Herdt
@ 2024-10-31 12:01   ` Matt Wette
  2024-10-31 23:49     ` Mikael Djurfeldt
  0 siblings, 1 reply; 13+ messages in thread
From: Matt Wette @ 2024-10-31 12:01 UTC (permalink / raw)
  To: guile-user

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







^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-10-31 12:01   ` Matt Wette
@ 2024-10-31 23:49     ` Mikael Djurfeldt
  2024-11-01 13:32       ` Matt Wette
  0 siblings, 1 reply; 13+ messages in thread
From: Mikael Djurfeldt @ 2024-10-31 23:49 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user, Mikael Djurfeldt

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 <matt.wette@gmail.com> 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
>
>
>
>
>
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-10-31 23:49     ` Mikael Djurfeldt
@ 2024-11-01 13:32       ` Matt Wette
  2024-11-01 13:37         ` Matt Wette
  0 siblings, 1 reply; 13+ messages in thread
From: Matt Wette @ 2024-11-01 13:32 UTC (permalink / raw)
  To: mikael; +Cc: guile-user

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 <matt.wette@gmail.com> 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
>
>
>
>
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-11-01 13:32       ` Matt Wette
@ 2024-11-01 13:37         ` Matt Wette
  2024-11-01 14:05           ` Matt Wette
  0 siblings, 1 reply; 13+ messages in thread
From: Matt Wette @ 2024-11-01 13:37 UTC (permalink / raw)
  To: mikael; +Cc: guile-user

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 <matt.wette@gmail.com> 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
>>
>>
>>
>>
>>




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-11-01 13:37         ` Matt Wette
@ 2024-11-01 14:05           ` Matt Wette
  2024-11-01 15:08             ` Mikael Djurfeldt
  0 siblings, 1 reply; 13+ messages in thread
From: Matt Wette @ 2024-11-01 14:05 UTC (permalink / raw)
  To: mikael; +Cc: guile-user

And one more thing.   There is a manual for cdata.  There is a link on 
this page

https://www.nongnu.org/nyacc/


On 11/1/24 6:37 AM, Matt Wette wrote:
> 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 <matt.wette@gmail.com> 
>>> 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
>>>
>>>
>>>
>>>
>>>
>
>




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-11-01 14:05           ` Matt Wette
@ 2024-11-01 15:08             ` Mikael Djurfeldt
  2024-11-01 15:10               ` Mikael Djurfeldt
  0 siblings, 1 reply; 13+ messages in thread
From: Mikael Djurfeldt @ 2024-11-01 15:08 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

Thanks!

Doing the (make-cdata struct-mosquitto_message* message) as well as
changing cdata-ref to cdata*-ref works fine.

Obviously, what someone should do is to write a nice schemey interface on
top of what you get with (ffi mosquitto).

Best regards,
Mikael

On Fri, Nov 1, 2024 at 3:05 PM Matt Wette <matt.wette@gmail.com> wrote:

> And one more thing.   There is a manual for cdata.  There is a link on
> this page
>
> https://www.nongnu.org/nyacc/
>
>
> On 11/1/24 6:37 AM, Matt Wette wrote:
> > 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 <matt.wette@gmail.com>
> >>> 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
> >>>
> >>>
> >>>
> >>>
> >>>
> >
> >
>
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-11-01 15:08             ` Mikael Djurfeldt
@ 2024-11-01 15:10               ` Mikael Djurfeldt
  2024-11-01 16:29                 ` Matt Wette
  0 siblings, 1 reply; 13+ messages in thread
From: Mikael Djurfeldt @ 2024-11-01 15:10 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

BTW,

I did:

(mosquitto_message_callback_set mosq (procedure->pointer void
receive-message (list '* '* '*)))

Is it correct to pass '* as argument type for the struct mosquitto_message
pointer (3rd arg)?

On Fri, Nov 1, 2024 at 4:08 PM Mikael Djurfeldt <mikael@djurfeldt.com>
wrote:

> Thanks!
>
> Doing the (make-cdata struct-mosquitto_message* message) as well as
> changing cdata-ref to cdata*-ref works fine.
>
> Obviously, what someone should do is to write a nice schemey interface on
> top of what you get with (ffi mosquitto).
>
> Best regards,
> Mikael
>
> On Fri, Nov 1, 2024 at 3:05 PM Matt Wette <matt.wette@gmail.com> wrote:
>
>> And one more thing.   There is a manual for cdata.  There is a link on
>> this page
>>
>> https://www.nongnu.org/nyacc/
>>
>>
>> On 11/1/24 6:37 AM, Matt Wette wrote:
>> > 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 <matt.wette@gmail.com>
>> >>> 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
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >
>> >
>>
>>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-11-01 15:10               ` Mikael Djurfeldt
@ 2024-11-01 16:29                 ` Matt Wette
  0 siblings, 0 replies; 13+ messages in thread
From: Matt Wette @ 2024-11-01 16:29 UTC (permalink / raw)
  To: mikael; +Cc: guile-user

I'm not seeing all of the context, but I think this should work

   (define (my-msg-handler mos data msg)
      (display (pointer->string (cdata*-ref msg 'message) (cdata*-ref 
msg 'messagesize)))
     (newline))

   (mosquitto_message_callback_set mosq my-msg-handler)

in my-msg-handler, mos will be <cdata struct-mosquitto* 0xdeadbeef>, 
data will be of type <pointer > and msg will be of type <cdata 
struct-mosquitto_message* 0xdeadbeef>

A lot of the plumbing you are doing comes for free in the 
ffi/mosquitto.scm code.  You should not have be writining 
pointer->procedure code or using (make-cdata ...) from the callback 
arguments.

On 11/1/24 8:10 AM, Mikael Djurfeldt wrote:
> BTW,
>
> I did:
>
> (mosquitto_message_callback_set mosq (procedure->pointer void 
> receive-message (list '* '* '*)))
>
> Is it correct to pass '* as argument type for the struct 
> mosquitto_message pointer (3rd arg)?
>
> On Fri, Nov 1, 2024 at 4:08 PM Mikael Djurfeldt <mikael@djurfeldt.com> 
> wrote:
>
>     Thanks!
>
>     Doing the (make-cdata struct-mosquitto_message* message) as well
>     as changing cdata-ref to cdata*-ref works fine.
>
>     Obviously, what someone should do is to write a nice schemey
>     interface on top of what you get with (ffi mosquitto).
>
>     Best regards,
>     Mikael
>
>     On Fri, Nov 1, 2024 at 3:05 PM Matt Wette <matt.wette@gmail.com>
>     wrote:
>
>         And one more thing.   There is a manual for cdata.  There is a
>         link on
>         this page
>
>         https://www.nongnu.org/nyacc/
>
>
>         On 11/1/24 6:37 AM, Matt Wette wrote:
>         > 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
>         <matt.wette@gmail.com>
>         >>> 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
>         >>>
>         >>>
>         >>>
>         >>>
>         >>>
>         >
>         >
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
  2024-10-31  2:24 Mqtt support in guile? Alan Wedel
  2024-10-31  8:17 ` Nala Ginrut
  2024-10-31  8:48 ` Ricardo G. Herdt
@ 2024-11-09 15:50 ` Mikael Djurfeldt
       [not found]   ` <235874FE-F447-41D5-8256-A9F6E3CF3663@gmail.com>
  2 siblings, 1 reply; 13+ messages in thread
From: Mikael Djurfeldt @ 2024-11-09 15:50 UTC (permalink / raw)
  To: Alan Wedel; +Cc: guile-user

Hi Alan,

In another message, I just released guile-mqqt, as you might have seen:

https://github.com/mdjurfeldt/guile-mqqt

Best regards,
Mikael

On Thu, Oct 31, 2024 at 3:25 AM Alan Wedel <alanwedel19@gmail.com> wrote:

> 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?
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Mqtt support in guile?
       [not found]   ` <235874FE-F447-41D5-8256-A9F6E3CF3663@gmail.com>
@ 2024-11-09 21:33     ` Mikael Djurfeldt
  0 siblings, 0 replies; 13+ messages in thread
From: Mikael Djurfeldt @ 2024-11-09 21:33 UTC (permalink / raw)
  To: Alan Wedel; +Cc: Mikael Djurfeldt, guile-user

Hi Alan,

Greg Troxel earlier this evening (at my place) pointed out that I had used
a misspelled URL for the repository. In fact, the repository itself had the
wrong name. I made a brutal correction and removed the old repository and
created a new with the correct name:

https://github.com/mdjurfeldt/guile-mqtt

Hope that this hasn't already created a lot of trouble.

Best regards,
Mikael

On Sat, Nov 9, 2024 at 6:56 PM Alan Wedel <alanwedel19@gmail.com> wrote:

> Thanks a lot, I will definitely check it out!
>
>
> On November 9, 2024 9:50:41 AM CST, Mikael Djurfeldt <mikael@djurfeldt.com>
> wrote:
>
>> Hi Alan,
>>
>> In another message, I just released guile-mqqt, as you might have seen:
>>
>> https://github.com/mdjurfeldt/guile-mqqt
>>
>> Best regards,
>> Mikael
>>
>> On Thu, Oct 31, 2024 at 3:25 AM Alan Wedel <alanwedel19@gmail.com> wrote:
>>
>>> 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?
>>>
>>


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-11-09 21:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-31  2:24 Mqtt support in guile? Alan Wedel
2024-10-31  8:17 ` Nala Ginrut
2024-10-31  8:48 ` Ricardo G. Herdt
2024-10-31 12:01   ` Matt Wette
2024-10-31 23:49     ` Mikael Djurfeldt
2024-11-01 13:32       ` Matt Wette
2024-11-01 13:37         ` Matt Wette
2024-11-01 14:05           ` Matt Wette
2024-11-01 15:08             ` Mikael Djurfeldt
2024-11-01 15:10               ` Mikael Djurfeldt
2024-11-01 16:29                 ` Matt Wette
2024-11-09 15:50 ` Mikael Djurfeldt
     [not found]   ` <235874FE-F447-41D5-8256-A9F6E3CF3663@gmail.com>
2024-11-09 21:33     ` Mikael Djurfeldt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).