Subscribing and Publishing From a C program on Another Computer

111 views
Skip to first unread message

PeteCal

unread,
Oct 21, 2020, 9:03:52 PM10/21/20
to MQTT
Something tells me I am missing something simple but I have spent many hours searching and experimenting and can't make the following configuration work.

I have an existing system consisting of a Raspberry Pi using a mosquitto broker.  It is mostly a C program that communicates to a home automation system (OpenHAB) via mqtt, all on the same computer.

I want to build another device that uses another RPi running a C program.  I want to publish from parts of that C program and subscribe from other parts of that program.  I just can't seem to find the right set of code to make this work.

I won't bore everyone with all that I have tried but I have gotten this far.  I haven't decided which RPi will do what I need so in the mean time I am using a Windows computer.
I have subscribed and published from the windows computer to the RPi.
I opened a Windows command window to publish and subscribed in an RPi window thusly:  (the RPi is192.168.1.115 and that is where mosquitto is.)
RPi window ...    mosquitto_sub   -t test
Windows window....  mosquitto_pub -t test -h 192.168.1.115  -m "Hello:World"
In the RPi window I get ... ▒Hello:World
So I think that means everybody is connected.

In the existing RPi I have the following code in the C program:

struct mosquitto* mosq = NULL;
    char* MQTT_Host = "192.168.1.115" ;
    int MQTT_Port = 1883;
    char Payload[3];
/* To get this to compile/link I had to add
-lmosquitto
Under Project, Build Options, Linker Settings, Other Link Options.
*/
void createMosquitto(){
    mosquitto_lib_init();
    mosq = mosquitto_new("345Mz",true,NULL);
    mosquitto_loop_start(mosq);
    mosquitto_connect_async(mosq,MQTT_Host,MQTT_Port,60);
    }

void publish(char *Topic, char *action)
{
    mosquitto_publish(mosq,NULL,Topic,strlen(action),action,2,false);
    //printf("Mosquitto Sending: %s %s to %s:%d\n",Topic,action,MQTT_Host,MQTT_Port);
}


 I can't get this to compile because "cannot find -lmosquitto"  I have searched high and low to find -lmosquitto for the windows computer.  It seems to be on the RPi already but I don't know why.
I have been using Code:Blocks as an IDE because it runs on both the RPi and Windows.

I have tried many variations but none seem to work.

Can someone show me what I am doing wrong or point me to a way to ferret this out?

Thanks.
Pete

Renato Maziero

unread,
Oct 22, 2020, 10:35:01 AM10/22/20
to mq...@googlegroups.com
Faça em uma máquina com Ubuntu 20.04. 



--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mqtt/4c6496d5-4e6c-4c74-a651-f6ecd26243den%40googlegroups.com.

PeteCal

unread,
Oct 22, 2020, 1:03:40 PM10/22/20
to MQTT
Please come again.
Google Translate thinks that is Spanish  and says:
Façade on a machine with Ubuntu 20.04.
What ever that means.
I asked my daughter-in-law who speaks many languages and she said:
"
Not idea!!! No Spanish or italiano or Portuges... :/"

Renato Maziero

unread,
Oct 22, 2020, 1:13:25 PM10/22/20
to mq...@googlegroups.com
Portugues. Brasil
Make on a machine with Ubuntu 20.04


PeteCal

unread,
Oct 22, 2020, 8:59:04 PM10/22/20
to MQTT
That doesn't help.  I need to use Windows.  I already have this running on Linux.
Reply all
Reply to author
Forward
0 new messages