unable to use mqtt

180 views
Skip to first unread message

gururaj revankar

unread,
Apr 12, 2021, 4:48:49 AM4/12/21
to rabbitmq-users
hello, im trying to connect to rabbitmq over mqtt protocol using esp8266 
i followed the following instruction using pubsubclient, https://funprojects.blog/2018/12/07/rabbitmq-for-iot/

i want to know what should be my mqtt server adress as to connect to rabbitmq mqtt ,how to use it to connect to rabbitmq server from esp8266 , i have folowed the same instruction as per the above listed website,  but unable to connect to rabbitmq using esp8266,
im running my rabbitmq server over a virtual machine with  a public ip,  what should  be my mqtt host adress  in esp8266

commands used toi start rabbit mq

apt-get update
 apt-get install rabbitmq-server 
 service rabbitmq-server start

 command for plugin enable

rabbitmq-plugins enable rabbitmq_mqtt 
rabbitmq-plugins enable rabbitmq_management

create new user and set administrator access

rabbitmqctl add_user admin1 admin1 
rabbitmqctl set_permissions -p / admin1 ".*" ".*" ".*" 
rabbitmqctl set_user_tags admin1 management administrator


code for esp8266


/* Basic ESP8266 MQTT publish client example */
#include <ESP8266WiFi.h> 
#include <PubSubClient.h> // Update these with values suitable for your network. 
const char* ssid = "your_ssid"; 
const char* password = "your_password";
const char* mqtt_server = "192.168.0.121";
  const char* mqtt_user = "admin1"; 
const char* mqtt_pass= "admin1"; 

//the MQ2 analog input pin
WiFiClient espClient; 
PubSubClient client(espClient); 

  void setup_wifi() {  /
/ Connecting to a WiFi network 
  WiFi.begin(ssid, password);  
while (WiFi.status() != WL_CONNECTED) {    
delay(500);  
  Serial.print(".");  }  
Serial.println("WiFi connected");  
Serial.println("IP address: "); 
  Serial.println(WiFi.localIP()); } 

  void reconnect() {  
// Loop until we're reconnected 
  Serial.println("In reconnect..."); 
  while (!client.connected()) {    
Serial.print("Attempting MQTT connection..."); 
    // Attempt to connect   
 if (client.connect("Arduino_Gas", mqtt_user, mqtt_pass)) 
{      Serial.println("connected");    } 
else {      Serial.print("failed, rc=");     
 Serial.print(client.state());     
 Serial.println(" try again in 5 seconds");      delay(5000);    }  } } 

  void setup() {  
Serial.begin(9600);
 setup_wifi(); 
  client.setServer(mqtt_server, 1883); }
void loop() { 
  char msg[8];  
if (!client.connected()) {    
reconnect(); 
  }  
sprintf(msg,"hai from esp8266"); 
  client.publish("mq2_mqtt", msg);
 Serial.print("message send::");
 Serial.println(msg);  delay(5000); }



what should be "  const char* mqtt_server = ???   "

cedric....@railnova.eu

unread,
Apr 14, 2021, 5:18:22 AM4/14/21
to rabbitmq-users
Hello,

mqtt_server would be the public ip of your vm on which rabbitmq is running.

Best,
Reply all
Reply to author
Forward
0 new messages