I don’t know if it is appropiate to post this here but here we go.
I wanna publish a lot of sensor data with mqtt to OpenHAB but I don’t know if my ESP8266 will support it. I have like a total of 16 sensors (temp,Hum,Lux,PIR) distributed in 3 floors, each sensor will provide a 2 byte data (PIR only 1 byte) and I am gonna publish it with 1 second samplig. The problem is that I don’t know how exactly works the PubSubClient.h, if it will send all the data at the same time or will send it by parts and how Mosquitto broker will send it to OpenHAB.
If by any chance I clear the payload char each time the ESP8266 published 4 data sensors per example, it will help or not?
Here is a part of the code, don’t mind some values please it’s not finished yet. I post only this part so the entire code is very large because it receives data from 4 Xbee’s and other things. If anyone could help me I appreciated.
char msg[50]; // Not sure about the exact size of the payload, I don't know if it will publish all the data at the same time or what
// Dont mind please, it is not finihed yet
float tempC, Humidity, Lux = 0;
int pir_int = 0;
float tempC, Humidity, Lux = 0;
int pir_int = 0;
float tempC, Humidity, Lux = 0;
int pir_int = 0;
float tempC, Humidity, Lux = 0;
int pir_int = 0;
// Declaració dels topics mqtt
// Soterrani
#define st_temp "casa/st/soterrani/temperatura"
#define st_hum "casa/st/soterrani/humitat"
#define st_pir "casa/st/soterrani/pir"
#define st_llums "casa/st/soterrani/llums" // per codi actuador
#define st_lux "casa/st/soterrani/lux"
#define st_rent "casa/st/soterrani/rentadora" // per codi actuador
#define st_cald "casa/st/soterrani/caldera" // per codi actuador
// Cuina
#define st_temp "casa/pb/cuina/temperatura"
#define st_hum "casa/pb/cuina/humitat"
#define st_llums "casa/pb/cuina/llums" // per codi actuador
#define st_co "casa/pb/cuina/co"
// Saló
#define st_temp "casa/pb/salo/temperatura"
#define st_hum "casa/pb/salo/humitat"
#define st_pir "casa/pb/salo/pir"
#define st_llums "casa/pb/salo/llums" // per codi actuador
#define st_alarma "casa/pb/salo/alarma" // per codi actuador
#define st_lux "casa/pb/salo/lux"
// Dormitori
#define st_temp "casa/pp/dormitori/temperatura"
#define st_hum "casa/pp/dormitori/humitat"
#define st_pir "casa/pp/dormitori/pir"
#define st_llums "casa/pp/dormitori/llums" // per codi actuador
#define st_lux "casa/pp/dormitori/lux"
// Oficina
#define st_temp "casa/pp/oficina/temperatura"
#define st_hum "casa/pp/oficina/humitat"
#define st_llums "casa/pp/oficina/llums" // per codi actuador
#define st_lux "casa/pp/oficina/lux"
void loop()
{
// Fem la primera connexió del client i les següents que siguin necessàries
if (!client.connected()) {
reconnect();
}
// Inicialitzem la funció de tractament de dades
parseData();
// Publiquem les dades dels sensors cada un cert temps
long now = millis();
if (now - lastMsg > 29000) {
lastMsg = now;
// tractem les variables amb 2 enters i 2 decimals de precisió i les convertim a string
// Soterrani
String Pir_s = String(pir_int);
client.publish(st_pir, Pir_s);
client.publish(st_temp, dtostrf(tempC, 4, 2, msgbuf));
client.publish(st_hum, dtostrf(Humidity, 4, 2, msgbuf));
client.publish(st_lux, dtostrf(Lux, 4, 2, msgbuf); // revisar
// Not finished yet, here are the other sensor data I wanna publish
String Pir_s = String(pir_int);
client.publish(st_pir, Pir_s);
client.publish(st_temp, dtostrf(tempC, 4, 2, msgbuf));
client.publish(st_hum, dtostrf(Humidity, 4, 2, msgbuf));
client.publish(st_lux, dtostrf(Lux, 4, 2, msgbuf); // revisar
String Pir_s = String(pir_int);
client.publish(st_pir, Pir_s);
client.publish(st_temp, dtostrf(tempC, 4, 2, msgbuf));
client.publish(st_hum, dtostrf(Humidity, 4, 2, msgbuf));
client.publish(st_lux, dtostrf(Lux, 4, 2, msgbuf); // revisar
String Pir_s = String(pir_int);
client.publish(st_pir, Pir_s);
client.publish(st_temp, dtostrf(tempC, 4, 2, msgbuf));
client.publish(st_hum, dtostrf(Humidity, 4, 2, msgbuf));
client.publish(st_lux, dtostrf(Lux, 4, 2, msgbuf); // revisar
}
// Fem una connexió en cada loop amb client per refrescar dades per publicar i mantenir la connexió
client.loop();
}