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