Нужно мерить температуру в семи точках, на столе у компютера обкатал всё с пятью датчиками работало, но когда всё прикрутил к котлу - смотрю а там везде 0 температуры, на котёл семь датчиков DS18B20, скетчь тоже написал на семь, как только один отключаю всё данные пошли , как только подключаю любой больше 5-ти всё нолики. Где беда.
Датчики подключены примерно по такой схеме, и выкладываю часть скетча, где про температуры.
Код: Выделить всё
#include <SPI.h>
#include <Ethernet2.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip{192, 168, 1, 24};
IPAddress server{192, 168, 1, 240};
void callback(char* topic, byte* payload, unsigned int length);
EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float temp1;
float temp2;
float temp3;
float temp4;
float temp5;
float temp6;
float temp7;
byte sensor1[8] = {0x28, 0x88, 0xD9, 0x46, 0x92, 0x11, 0x02, 0xE2};
byte sensor2[8] = {0x28, 0xCC, 0xAF, 0x45, 0x92, 0x0C, 0x02, 0x57};
byte sensor3[8] = {0x28, 0x95, 0x03, 0x46, 0x92, 0x09, 0x02, 0x8A};
byte sensor4[8] = {0x28, 0x04, 0x2B, 0x46, 0x92, 0x05, 0x02, 0x87};
byte sensor5[8] = {0x28, 0x76, 0x7F, 0x53, 0x2D, 0x19, 0x01, 0xE2};
byte sensor6[8] = {0x28, 0x18, 0xF0, 0x3C, 0x2D, 0x19, 0x01, 0x9C};
byte sensor7[8] = {0x28, 0xB0, 0x87, 0x70, 0x2D, 0x19, 0x01, 0xAF};
//--------------------------- MQTT ---------------------------------------------------------
void callback(char* topic, byte* payload, unsigned int length){
// Выделяем необходимое кол-во памяти для копии payload
byte* p = (byte*)malloc(length);
// Копирование payload в новый буфер
memcpy(p, payload, length);
client.publish("Heater", p, length);
// clear memory
free(p);
}
void setup(){
sensors.begin();
Ethernet.begin(mac, ip);
}
void loop(){
sensors.requestTemperatures();
//----------------------------------------------------------------------------------------
if (client.connect("MAJORDOMO")){
client.publish("Heater/alarm", (buttonState == 0) ? "0" : "1");
client.publish("Heater/level", (Liquid_level == 0) ? "0" : "1");
client.publish("Heater/VK1", String(temp1).c_str());
client.publish("Heater/VK2", String(temp2).c_str());
client.publish("Heater/HK", String(temp3).c_str());
client.publish("Heater/GR", String(temp4).c_str());
client.publish("Heater/KVP", String(temp5).c_str());
client.publish("Heater/TP", String(temp6).c_str());
client.publish("Heater/TG", String(temp7).c_str());
delay(2000);
client.disconnect(); //
}
}
//-----------------------------------------------------------------------------------------
void printTemperature(DeviceAddress address) {
float tempC = sensors.getTempC(address);
// Serial.print(tempC);
// Serial.println();
if (address == sensor1){temp1 = tempC;}
if (address == sensor2){temp2 = tempC;}
if (address == sensor3){temp3 = tempC;}
if (address == sensor4){temp4 = tempC;}
if (address == sensor5){temp5 = tempC;}
if (address == sensor6){temp6 = tempC;}
if (address == sensor7){temp7 = tempC;}
}