Код: Выделить всё
if (!memcmp(tempSensor[i], idTempDat[n], 16)){
*Информирует об ошибке при потере связи с датчиком.
*Переделал вывод в сериал ид датчиков (для удобства копирование)
*немного оптимизировал функцию подбора ИД датчиков memcmp
Код: Выделить всё
/*
Modul Temperature
part of Arduino Mega Server project
*/
#ifdef TEMP_FEATURE
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS 2
byte const MAX_TEMP_SENSORS = 15;
byte const MAX_ID_DIGITS = 7;
char objSens[MAX_TEMP_SENSORS][12] = {"tempSTR", "tempHOM", "tempWRM", "sens4", "sens5", "sens6", "sens7", "colecIN", "colecOUT", "colec1", "colec2", "colec3", "colec4", "colec5", "colec6"};
// Sensors ID's
byte idTempDat[MAX_TEMP_SENSORS][MAX_ID_DIGITS] = {
{40, 48, 197, 179, 0, 0, 0, },
{40, 88, 199, 185, 0, 0, 0, },
{40, 36, 193, 184, 0, 0, 0, },
{40, 52, 197, 178, 0, 0, 0, },
{40, 82, 194, 183, 0, 0, 0, },
{40, 50, 197, 183, 0, 0, 0, },
{40, 54, 197, 184, 0, 0, 0, },
{40, 65, 194, 177, 0, 0, 0, },
{40, 33, 198, 179, 0, 0, 0, },
{40, 49, 197, 177, 0, 0, 0, },
{40, 53, 197, 184, 0, 0, 0, },
{40, 83, 198, 178, 0, 0, 0, },
{40, 51, 197, 185, 0, 0, 0, },
{40, 71, 196, 184, 0, 0, 0, },
{40, 55, 197, 184, 0, 0, 0, },
};
float current_temp[MAX_TEMP_SENSORS];
int temp_[MAX_TEMP_SENSORS];
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempSensor[MAX_TEMP_SENSORS];
void tempInit() {
initStart("Temperature");
sensors.begin();
timeStamp();
Serialprint(" Parasite power ");
if (sensors.isParasitePowerMode()) {
Serialprint("ON\n");
}
else {
Serialprint("OFF\n");
}
oneWire.reset_search();
// locate devices on the bus
timeStamp();
Serialprint(" Found ");
Serial.print(sensors.getDeviceCount());
Serialprint(" devices\n");
for (byte i = 0; i < MAX_TEMP_SENSORS; i++) {
sensors.getAddress(tempSensor[i], i);
}
oneWire.reset_search();
showSensorsId();
modulTemp = MODUL_ENABLE;
initDone();
}
void showSensorsId() {
for (byte n = 0; n < MAX_TEMP_SENSORS; n++) {
//timeStamp();
//Serialprint("#");
//Serial.print(n);
Serialprint("{");
for (byte i = 0; i < MAX_ID_DIGITS; i++) {
Serial.print(tempSensor[n][i]);
Serialprint(", ");
}
Serialprint("}, \n");
}
}
void tempWorks() {
sensors.requestTemperatures();
for (byte i = 0; i < MAX_TEMP_SENSORS; i++)
getTemperature(i);
}
void getTemperature(byte n) {
for (byte i = 0; i < (MAX_TEMP_SENSORS + 1); i++) {
if (!memcmp(idTempDat[n], tempSensor[i], MAX_ID_DIGITS)) {
current_temp[i] = sensors.getTempC(tempSensor[i]);
timeStamp();
Serial.print(objSens[n]);
Serialprint(": ");
Serial.println(current_temp[i]);
temp_[i] = (current_temp[i] - (int)current_temp[i]) * 100;
if ((current_temp[i] > -1) && (current_temp[i] < 0)) {
#ifdef MAJORDOMO_FEATURE
sendRequestMinusM(objSens[n], "-", (int)current_temp[i], abs(temp_[i]));
#endif
} else {
#ifdef MAJORDOMO_FEATURE
sendRequestMinusM(objSens[n], "", (int)current_temp[i], abs(temp_[i]));
#endif
}
return; //если нашли нужный датчик, то переходим на следующий
}
else if (i == MAX_TEMP_SENSORS) { //если датчик не нашли, то сообщаем об этом (сюда можно добавить GET с ошибкой
timeStamp();
Serial.print(objSens[n]);
Serialprint(" ");
Serialprint("Sensor error");
Serialprint("\n");
}
}
} // getTemperature( )
#endif // TEMP_FEATURE