ok thanks for the tip, but for now it’s the only device I have that has 2 temperature sensors. it sends the info every minute…
so what can I do now?
ok thanks for the tip, but for now it’s the only device I have that has 2 temperature sensors. it sends the info every minute…
so what can I do now?
Your devices are connecting, they should be sending messages across the bus.
you are subscribing to #
on MQTT.FX? You should see data flowing across. If you manually publish something, anything, you should see it too. If you aren’t, are you sure you’re connected correctly?
I’m sure I’m connected and I did subscribe to #.
I’m sure because when I restarted the broker it disconnected and I could connect when the log said it’s up.
when I publish on # I get nothing but when I publish on “sensor/” I can see it.
still nothing from the node.
you don’t publish to #
. if you can publish to sensor/
then mqtt is working.
What does the code for your sensors look like?
void loop() {
ArduinoOTA.handle();
if (!client.connected()) {
reconnect();
}
client.loop();
long now = millis();
if (now - lastMsg > minuteInterval * 60000) {
lastMsg = now;
DS18B20.requestTemperatures();
DS18B20.requestTemperatures();
float temp1 = DS18B20.getTempCByIndex(0);
float temp2 = DS18B20.getTempCByIndex(1);
if ( debug ) {
Serial.print("Temperature : ");
Serial.print(temp1);
Serial.print(" | Temprature 2 : ");
Serial.println(temp2);
}
client.publish(temperature_topic_small, String(temp1).c_str(), true); // Publish temperature on temperature_topic
client.publish(temperature_topic_big, String(temp2).c_str(), true);
}
}
this was the loop function.
this is the callback function:
void callback(char* topic, byte* payload, unsigned int length) {
int i = 0;
if ( debug ) {
Serial.println("Message recu => topic: " + String(topic));
Serial.print(" | longueur: " + String(length,DEC));
}
// create character buffer with ending null terminator (string)
for(i=0; i<length; i++) {
message_buff[i] = payload[i];
}
message_buff[i] = '\0';
String msgString = String(message_buff);
if ( debug ) {
Serial.println("Payload: " + msgString);
}
}
and these are the defines that goes with it:
#define temperature_topic_big “sensor/fats_temperature_big”
#define temperature_topic_small “sensor/fats_temperature_small”
I hope I’m posting it correctly. with all the code and all.
I didn’t change a thing other than the connection parameters and it worked before all the crisis.
I know the node gets the data from the sensors cause I can see it on serial monitor at the arduino IDE that is open for now until I’ll get it to work on the hassio page.
Can you do a screen print from mqtt.fx, so we can see what you are seeing
Ok that looks like a problem. I don’t see any transactions
Hopefully I can send you an example of what I have
Is 10.0.0.100 where you have the broker? Is that where your ESP devices are publishing to
yeah I figured that there is a problem… lol…
but I don’t know where to even look…
do you follow a sketch for any esp node?
maybe it’s something with my code?
on hassio config.yaml what should be the mqtt broker attribute? right it’s localhost for me… should it be something else?
I use hassbian but I also use localhost.
Let’s go to the Publish Tab of mqtt.fx
type in Test/Test in the topic area and This is a TEST in the Message area & press Publish
Then jump back over to Subscribe, is it there?
yeah I can see that, so that’s probably working as well.
Post the whole sketch. We can’t help you from bits and pieces.
Which Arduino are you using?
If your MQTT tool connects to the broker IP, then when you subscribe to #, you will see everything going through the broker.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <DHTesp.h>
#define minuteInterval 15
#define wifi_ssid "*********"
#define wifi_password "***********"
#define mqtt_server "***********"
#define mqtt_username "Mansesnsors"
#define mqtt_password "welcome1"
#define temperature_topic_big "sensor/fats_temperature_big"
#define temperature_topic_small "sensor/fats_temperature_small"
#define ONE_WIRE_BUS D6 // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
//Buffer to decode MQTT messages
char message_buff[100];
long lastMsg = 0;
long lastRecu = 0;
bool debug = true; //Display log message if True
WiFiClient espClient;
PubSubClient client(espClient);
DHTesp dht;
DHTesp dhtFurther;
void setup() {
Serial.begin(115200);
DS18B20.begin();
//dht.setup(4); //Pin 2 on board
//dhtFurther.setup(12); //Pin 6 on board
setup_wifi();
ArduinoOTA.onStart([]() {
Serial.println("Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(wifi_ssid);
ArduinoOTA.setHostname("Temp_Fats_Storeroom");
WiFi.mode(WIFI_STA);
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
// If you do not want to use a username and password, change next line to
// if (client.connect("ESP8266Client")) {
if (client.connect("ESP8266Client",mqtt_username,mqtt_password)) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
ArduinoOTA.handle();
if (!client.connected()) {
reconnect();
}
client.loop();
long now = millis();
if (now - lastMsg > minuteInterval * 60000) {
lastMsg = now;
DS18B20.requestTemperatures();
DS18B20.requestTemperatures();
float temp1 = DS18B20.getTempCByIndex(0);
float temp2 = DS18B20.getTempCByIndex(1);
if ( debug ) {
Serial.print("Temperature : ");
Serial.print(temp1);
Serial.print(" | Temprature 2 : ");
Serial.println(temp2);
}
client.publish(temperature_topic_small, String(temp1).c_str(), true); // Publish temperature on temperature_topic
client.publish(temperature_topic_big, String(temp2).c_str(), true);
}
}
void callback(char* topic, byte* payload, unsigned int length) {
int i = 0;
if ( debug ) {
Serial.println("Message recu => topic: " + String(topic));
Serial.print(" | longueur: " + String(length,DEC));
}
// create character buffer with ending null terminator (string)
for(i=0; i<length; i++) {
message_buff[i] = payload[i];
}
message_buff[i] = '\0';
String msgString = String(message_buff);
if ( debug ) {
Serial.println("Payload: " + msgString);
}
}
This is it. I hope it’s good.
lol, you commented out mqtt_server is that 10.0.0.100?
yeah. that’s that.
In your configuration.yaml are you using user name & password?
yes the same as in the sketch.
Which Arduino are you using, and do you have a terminal to watch the printf output? Do you see:
“Attempting MQTT connection…”
followed by:
“connected”
Let’s try this in mqtt.fx publish sensor/fats_temperature_big & sensor/fats_temperature_small
with message equal to 99
Does that show up in HA?