Hi all,
I am new to the plaltform, but i am trying to connect esp8266 with OR using mqtt broker.
To verify the connection I followed this tutorial from OR github wiki:
Tutorial: Connect your MQTT Client
I was able to connect MQTTX with localhost and GET and POST data using MQTTX software:
Now when I am trying to connect my ESP8266 with OR using the same credentials and code as provided in the github wiki(User Guide: Connect ESP32 or ESP8266 using MQTT)
I am getting below output in serial monitor.
Below is my ESP8266 Code and secret.h file:
ESP8266 :
> #include "secret.h"
> #include <ESP8266WiFi.h> // remove comment for ESP8266, and add comment at #include <WiFi.h>
> //#include <WiFi.h>
> #include <PubSubClient.h>
>
> //Objects
> WiFiClientSecure askClient; //SSL Client
> //WiFiClient askClient; //Non-SSL Client, also remove the comments for askClient.setCACert(local_root_ca);
>
> PubSubClient client(askClient);
>
> void setup() {
> Serial.begin(9600);
> Serial.println(ssid);
>
> WiFi.begin(ssid, password);
>
> while (WiFi.status() != WL_CONNECTED) {
> delay(500);
>
> }
>
> Serial.println(WiFi.localIP());
> //askClient.setCACert(local_root_ca); //If you use non SSL then comment out
> askClient.setCertificate_P(reinterpret_cast<const uint8_t*>(local_root_ca), strlen_P(local_root_ca));
> client.setServer(mqtt_server, mqtt_port);
> reconnect();
> client.setCallback(callback);
> reconnect();
> Serial.println(WiFi.localIP());
>
> }
>
> void loop() {
> //Publish Boolean format:
> client.publish("master/client123/writeattributevalue/writeAttribute/4q0u7wZVXGRMaewy2yRkhp", "1");
> //To publish Strings:
> //client.publish("yourrealm/ClientID/writeattributevalue/AttributeName/AssetID", String("Hello").c_str());
> delay(100);
>
> }
>
> //MQTT callback
> void callback(char* topic, byte * payload, unsigned int length) {
>
>
> for (int i = 0; i < length; i++) {
>
> Serial.println(topic);
> Serial.print(" has send ");
> Serial.print((char)payload[i]);
> }
>
> }
>
> //MQTT reconnect
> void reconnect() {
> // Loop until we're reconnected
> while (!client.connected()) {
> Serial.print("********** Attempting MQTT connection...");
> // Attempt to connect
> if (client.connect(ClientID, username, mqttpass, lastwill, 1, 1, lastwillmsg)) {
> Serial.println("-> MQTT client connected");
> client.subscribe(topic);
> Serial.print("Subscribed to: ");
> Serial.println(topic);
> } else {
> Serial.print("failed, rc=");
> Serial.print(client.state());
> Serial.println("-> try again in 5 seconds");
> // Wait 5 seconds before retrying
> delay(5000);
> }
> }
> }
secret.h
> // Wifi
> const char* ssid = "403"; // Wifi SSID
> const char* password = "12345678"; // Wifi Password
>
> //MQTT Broker
> const char* mqtt_server = "localhost";
> unsigned int mqtt_port = 1883; //SSL 8883 NoneSSL 1883
> const char* username = "master:mqttuser"; // Service User Realm:Serviceuser
> const char* mqttpass = "yvIudfWHC4R4dfzJbsa4l2nwWRkhasBr"; // Service User Secret
> const char* ClientID = "client123";
> //LastWill
> const char* lastwill = "master/client123/writeattributevalue/writeAttribute/4q0u7wZVXGRMaewy2yRkhp";
> const char* lastwillmsg = "0";
>
>
> //subscribing Topic
> const char *topic = "master/client123/attribute/writeAttribute/4q0u7wZVXGRMaewy2yRkhp"; //see Subscribing Topics in Documentation https://github.com/openremote/openremote/wiki/User-Guide%3A-Manager-APIs#mqtt-api-mqtt-broker
>
>
> //Local CA
>
> const char* local_root_ca = \
> "-----BEGIN CERTIFICATE-----\n" \
> "MIIDnzCCAoegAwIBAgIUE3jYzxKpepVM0CSLZd9GNv6BHj8wDQYJKoZIhvcNAQEL\n" \
> "BQAwUDELMAkGA1UEBhMCR0IxHTAbBgNVBAMMFE9wZW5SZW1vdGUgRGVtbyBDZXJ0\n" \
> "MRMwEQYDVQQKDApPcGVuUmVtb3RlMQ0wCwYDVQQLDAREZW1vMCAXDTIwMDYwODE5\n" \
> "MTc1MVoYDzIwNTAwNjAxMTkxNzUxWjBQMQswCQYDVQQGEwJHQjEdMBsGA1UEAwwU\n" \
> "T3BlblJlbW90ZSBEZW1vIENlcnQxEzARBgNVBAoMCk9wZW5SZW1vdGUxDTALBgNV\n" \
> "BAsMBERlbW8wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCrKEk77HcJ\n" \
> "B5SqvoN2UbRsDh9d0ECN8tOU5hC2poih+6XBJgikQ8gdy7ptt477KRh3ZIiw3ZTX\n" \
> "Hg0//Ju71D/4EDBYwHxoSK9WehP5Kz/LrBHhtArXK3RYH8pFS13CDOPjXnm6LMN5\n" \
> "2mRGwm2gCwKwRTbfm+D9hjpVuwt0sfHaXVETlUc4JystlfYVurMcfsox9tsbRuzl\n" \
> "EakyK9Cr1V7bgaLMosHDX3NSuEyzb9DQZ3PBK3JjJhSeYkGNuP/NocMrWy/JHd2v\n" \
> "2Wev9W+D1Pv46Sqfrvd6K7oP00FL0CdODkMRBVTlb1wq/6uJdRbnVUM0PGA9enrQ\n" \
> "vMB11fFglHa3AgMBAAGjbzBtMB0GA1UdDgQWBBT0ixs03BOrns+E2+xSU+nfP9KX\n" \
> "iTAfBgNVHSMEGDAWgBT0ixs03BOrns+E2+xSU+nfP9KXiTAPBgNVHRMBAf8EBTAD\n" \
> "AQH/MBoGA1UdEQQTMBGCCWxvY2FsaG9zdIcEfwAAATANBgkqhkiG9w0BAQsFAAOC\n" \
> "AQEAawmLoD7bzFTM0Z58PR6jQR3ypD6IAyei6xiBI7wvxbjyxqQrk1i0rK2Aexjk\n" \
> "v2ZsAUmtrm5k5pWpBsokNuRddPV1K2OZjTj9HPc9AxqjyHKyqRXmVKWkzbWQDLVS\n" \
> "lGRk7yviUFS8nRuY0vLfqZzF7e2HeasThILJibY8rUVLuq+iMS35RDwQ9usIOiYz\n" \
> "dF4CO3HFZ6NtDheM1mPAy4Q76H1P1fINuA8mp/by9J8heexqjgpBKYexiQhjb1A7\n" \
> "NBdWbJPXoNJplGXjGIbj8KxW61ih1wDRE2ZseOflRstO9/Txm7+Cuqo+WBOK39cU\n" \
> "CXPKre2pqmkIu65wJ6VcTKeSqw==" \
> "-----END CERTIFICATE-----";
Can someone please help me to find out what is the root cause of the problem that I am facing.
Is it related to arduino code? Is it related to docker file? it is issue with mqtt port.
I am okay to connect to OR using non SSL that is port 1883.
kindly help