# Unable to use MQTT library example

**URL:** <https://swi-prolog.discourse.group/t/unable-to-use-mqtt-library-example/3584>\
**Category:** Predicate\
**Tags:** bug, how-to, error\_message\
**Created:** [February 10, 2021, 8:46am UTC](https://swi-prolog.discourse.group/t/unable-to-use-mqtt-library-example/3584 "2021-02-10T08:46:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amanm6925](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/amanm6925/32/3306_2.png) [@amanm6925](https://swi-prolog.discourse.group/u/amanm6925)\
**Post date:** [February 10, 2021, 8:46am UTC](https://swi-prolog.discourse.group/t/unable-to-use-mqtt-library-example/3584/1 "2021-02-10T08:46:55Z")

</div>

I am using the callbacks.pl example which comes with MQTT pack when downloaded from official website. I have installed MQTT library in my Ubuntu 18 system by pack\_install(). Then on using simple\_sub(), I am facing this issue which traces to the function c\_mqtt\_connect(). I am unable to understand the error. Please help me.

```prolog
For online help and background, visit [https://www.swi-prolog.org](https://www.swi-prolog.org/)
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- consult('callbacks.pl').
true.

?- gtrace, simple_pub(Temp,27).
% The graphical front-end will be used for subsequent tracing

SWI-Prolog [thread 1 (main) at Wed Feb 10 13:57:33 2021]: received fatal signal 11 (segv)
C-stack trace labeled "crash":
[0] PL_strtod() at ??:? [0x7fe57cb87268]
[1] bstore_print_backtrace_named() at ??:? [0x7fe57cb8741e]
[2] bstore_print_backtrace_named() at ??:? [0x7fe57cb8753f]
[3] PL_get_signum_ex() at ??:? [0x7fe57cb14103]
[4] killpg() at ??:? [0x7fe57c6bd040]
[5] __GI___ libc_free() at /build/glibc-S7xCS9/glibc-2.27/malloc/malloc.c:3113 [0x7fe57c715a6d]
[6] c_mqtt_connect() at /home/olozyns/prolog_src/my_packs/swi-mqtt-pack/c/mqtt.c:1074 [0x7fe57a4c390d]
[7] PL_next_solution() at ??:? [0x7fe57caacac4]
[8] pl_skip_list3_va() at ??:? [0x7fe57caf95f4]
[9] pl_skip_list3_va() at ??:? [0x7fe57caf9e9b]
[10] PL_toplevel() at ??:? [0x7fe57caa58bd]
[11] prolog(+0x7c5) [0x56209c0e07c5]
[12] __libc_start_main() at /build/glibc-S7xCS9/glibc-2.27/csu/../csu/libc-start.c:344 [0x7fe57c69fbf7]
[13] prolog(+0x80a) [0x56209c0e080a]
Prolog stack:
[13] mqtt:c_mqtt_connect/4 [PC=1 in supervisor]
[12] mqtt:mqtt_connect/4 [PC=33 in clause 1]
[11] simple_pub/2 [PC=95 in clause 1]
[10] system:/1 [PC=7 in clause -1]
[9] $toplevel:toplevel_call/1 [PC=3 in clause 1]
[8] $toplevel:stop_backtrace/1 [PC=4 in clause 1]
[7] $tabling:$wfs_call/2 [PC=17 in clause 1]
[5] $toplevel:$execute_goal2/3 [PC=29 in clause 1]
[3] $toplevel:$query_loop/0 [PC=39 in clause 2]
[2] $toplevel:$runtoplevel/0 [PC=19 in clause 1]
[1] $toplevel:$toplevel/0 [PC=3 in clause 1]
[0] system:$c_call_prolog/0 [PC=0 in top query clause]
Running on_halt hooks with status 139
Killing 3518 with default signal handlers
Segmentation fault (core dumped)

```

 ![Screenshot from 2021-02-10 13-57-53](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/f/f9e2569d1c77c095e4c0b18d80603e0ca7fb5429.png)

---

<div class="post-metadata">

**Author:** ![sprior](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/sprior/32/108_2.png) [@sprior](https://swi-prolog.discourse.group/u/sprior)\
**Post date:** [February 18, 2021, 11:06pm UTC](https://swi-prolog.discourse.group/t/unable-to-use-mqtt-library-example/3584/2 "2021-02-18T23:06:56Z")

</div>

Wow, I didn’t know anyone else was trying MQTT with Prolog these days. The mqtt pack from the official website has some issues and doesn’t appear to be under active development by the original author so I’ve been working on it. Nothing to release quite yet, but my fork is at [GitHub - sprior/swi-mqtt-pack: MQTT pack for SWI-Prolog](https://github.com/sprior/swi-mqtt-pack) though I’ve been working on some fixes this last week which aren’t there yet.

In any case I’m not as familiar with the original examples, but have you installed the mosquitto broker (not just the client library) on your local machine and/or changed from localhost to the IP of your broker in your example code?

---

<div class="post-metadata">

**Author:** ![amanm6925](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/amanm6925/32/3306_2.png) [@amanm6925](https://swi-prolog.discourse.group/u/amanm6925)\
**Post date:** [February 19, 2021, 4:13am UTC](https://swi-prolog.discourse.group/t/unable-to-use-mqtt-library-example/3584/3 "2021-02-19T04:13:56Z")

</div>

Not yet. Currently I am trying to connect on localhost.

---

<div class="post-metadata">

**Author:** ![sprior](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/sprior/32/108_2.png) [@sprior](https://swi-prolog.discourse.group/u/sprior)\
**Post date:** [February 19, 2021, 5:24am UTC](https://swi-prolog.discourse.group/t/unable-to-use-mqtt-library-example/3584/4 "2021-02-19T05:24:07Z")

</div>

If you don’t have a mosquitto broker installed on localhost it’s not going to work.
