I must be missing something but I can't seem to figure out how to make this work.
I have two computers (soon to be Raspberry Pis but for now one is a Raspberry Pi and the others is a Windows PC).
I have a mosquitto broker running on the RPi. This has been running fine for almost a year, publishing and subscribing to many items on the RPi. All done using the C programming language.
Now I want to add a second RPi running a different C program. I would like to subscribe to and publish through the existing broker (unless there is another way).
My problem is the broker is created on the first computer using:
void createMosquitto(){
mosquitto_lib_init();
mosq = mosquitto_new("345Mz",true,NULL);
mosquitto_loop_start(mosq);
mosquitto_connect_async(mosq,MQTT_Host,MQTT_Port,60);
}
which gives me mosq to use in publish and subscribe functions:
mosquitto_publish(mosq,NULL,Topic,strlen(action),action,2,false);
All of this is done on the first computer.
If I want to publish from the second computer I need mosq for the publish function above. How can I get the second computer the value of mosq for the broker on the first computer.
I feel like I have everything set up because I can open terminal windows on the RPi and the PC and subscribe and publish back and forth.