I can't pull data from Adruino to OpenRemote even though it works in MQTT server

Hello everyone, first of all thank you for your time staying here and help me solve my own problem.
The problem I having right now is when I am using MQTT explorer I can Publish data for example Temprature 29 to the Assets but in Adruino I can not do the same and it still keeping the data from MQTT Explorder. Oh and I’m using ESP8266 in this Adruino

Hoping that anyone in here can help me solve this thing because I’m kinda new to OpenRemote

Dear

Rande

Hi,

Arduino =! ESP

It would help us if you can share your code.

oh my bad I forgot about that so here is docker-compose.yml:

the below one I run just fine as the setting like I just fresh download, but when I change the port like this: cmd /C “set OR_HOSTNAME=192.168.1.241 && docker compose -p openremote up -d”
and now even MQTT can’t even change attribute and it said “Attribute may have been deleted before event could be processed or it never existed”

OpenRemote v3

Profile that runs the stack by default on https://localhost using a self-signed SSL certificate,

but optionally on https://$OR_HOSTNAME with an auto generated SSL certificate from Letsencrypt.

It is configured to use the AWS logging driver.

version: ‘2.4’

volumes:
proxy-data:
manager-data:
postgresql-data:

services:

proxy:
image: openremote/proxy:${PROXY_VERSION:-latest}
restart: always
depends_on:
manager:
condition: service_healthy
ports:
- “80:80” # Needed for SSL generation using letsencrypt
- “${OR_SSL_PORT:-443}:443”
- “8883:8883”
- “1883:1883” # Localhost metrics access
volumes:
- proxy-data:/deployment
environment:
LE_EMAIL: ${OR_EMAIL_ADMIN:-}
DOMAINNAME: ${OR_HOSTNAME:-localhost}
DOMAINNAMES: ${OR_ADDITIONAL_HOSTNAMES:-}
# USE A CUSTOM PROXY CONFIG - COPY FROM https://raw.githubusercontent.com/openremote/proxy/main/haproxy.cfg
#HAPROXY_CONFIG: ‘/data/proxy/haproxy.cfg’

postgresql:
restart: always
image: openremote/postgresql:${POSTGRESQL_VERSION:-latest}
shm_size: 128mb
volumes:
- postgresql-data:/var/lib/postgresql/data
- manager-data:/storage

keycloak:
restart: always
image: openremote/keycloak:${KEYCLOAK_VERSION:-latest}
depends_on:
postgresql:
condition: service_healthy
volumes:
- ./deployment:/deployment
environment:
KEYCLOAK_ADMIN_PASSWORD: ${OR_ADMIN_PASSWORD:-secret}
KC_HOSTNAME: ${OR_HOSTNAME:-localhost}
KC_HOSTNAME_PORT: ${OR_SSL_PORT:–1}

manager:

privileged: true

restart: always
image: openremote/manager:${MANAGER_VERSION:-latest}
depends_on:
  keycloak:
    condition: service_healthy
ports:
  - "1883:1883" #"127.0.0.1:8405:8405" # Localhost metrics access
environment:
  OR_SETUP_TYPE:
  OR_ADMIN_PASSWORD:
  OR_SETUP_RUN_ON_RESTART:
  OR_EMAIL_HOST:
  OR_EMAIL_USER:
  OR_EMAIL_PASSWORD:
  OR_EMAIL_X_HEADERS:
  OR_EMAIL_FROM:
  OR_EMAIL_ADMIN:
  OR_METRICS_ENABLED: ${OR_METRICS_ENABLED:-true}
  OR_HOSTNAME: ${OR_HOSTNAME:-localhost}
  OR_ADDITIONAL_HOSTNAMES:
  OR_SSL_PORT: ${OR_SSL_PORT:--1}
  OR_DEV_MODE: ${OR_DEV_MODE:-false}

  # The following variables will configure the demo
  OR_FORECAST_SOLAR_API_KEY:
  OR_OPEN_WEATHER_API_APP_ID:
  OR_SETUP_IMPORT_DEMO_AGENT_KNX:
  OR_SETUP_IMPORT_DEMO_AGENT_VELBUS:
volumes:
  - manager-data:/storage

and this is my Adruino code that I make it so Humidity and Temprature can run a random number because I don’t have sensor to run them and yes It’s accpect the ESP but it’s not apply data into them:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// Wi-Fi and MQTT credentials
const char* ssid = “#”;
const char* password = “#”;
const char* mqtt_server = “192.168.1.241”;
const int mqtt_port = 1883;
const char* username = “#”;
const char* mqttpass = “#”;

// MQTT topics
const char* lastwill = “master/mqtt-explorer-26cd1ecb/writeattributevalue/temperature/29dd4TlxsvNcRQhACOr6Xp”;
const char* humidityTopic = “master/mqtt-explorer-26cd1ecb/writeattributevalue/humidity/29dd4TlxsvNcRQhACOr6Xp”;

// Objects
WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
Serial.begin(115200);

// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“Connected to Wi-Fi”);

// Set up MQTT
client.setServer(mqtt_server, mqtt_port);
client.setCallback(callback);

// Attempt to connect to MQTT
reconnect();
}

void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();

// Generate random temperature between 22C and 31C
int temp = random(22, 32);
String tempStr = String(temp) + “C”;
if (client.publish(temperatureTopic, tempStr.c_str())) {
Serial.println(“Temperature data published successfully”);
} else {
Serial.println(“Failed to publish temperature data”);
}

// Generate random humidity between 40% and 70%
int humidity = random(40, 71);
String humidityStr = String(humidity) + “%”;
if (client.publish(humidityTopic, humidityStr.c_str())) {
Serial.println(“Humidity data published successfully”);
} else {
Serial.println(“Failed to publish humidity data”);
}

delay(10000); // Wait 10 seconds before publishing new values
}

// MQTT callback
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived on topic: ");
Serial.println(topic);

Serial.print("Message: ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}

// MQTT reconnect
void reconnect() {
while (!client.connected()) {
Serial.print(“Attempting MQTT connection…”);

if (client.connect("ESP8266Client", username, mqttpass)) {
  Serial.println("-> MQTT client connected");
} else {
  Serial.print("Failed, rc=");
  Serial.print(client.state());
  Serial.println(" -> try again in 5 seconds");
  delay(5000);
}

}
}

You got several problems in your code, as I can see. I will help you tomorrow, I am at smartphone right now.

Please edit your forum post, the credentials in your code aren‘t for public.

Oh sorry again I already fixed the form and yet I only have like 10 more hours left to put them for my teacher so I just gonna keep finding in forum and docs thanks for your answer Denis.

Begin with the ClientID

The topic client ID isn’t matching with your login at reconnect().

You also got no temperatureTopic defined.

Like I said, you got some several issues in your code.

1 Like

Okay I’m gonna start with fixing my code first

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.