sensors_oneWire.ino 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. #ifdef ENABLE_SENSORS_ONEWIRE
  2. #define DALLAS_TEMPERATURE_PRECISION 12
  3. void oneWireSensors_setup() {
  4. oneWireSensors.begin();
  5. //Serial.print("Locating devices...");
  6. //Serial.print("Found ");
  7. //Serial.print(oneWireSensors.getDeviceCount(), DEC);
  8. //Serial.println(" devices.");
  9. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: found %d devices", oneWireSensors.getDeviceCount());
  10. sendLog(logBuf, LOGLEVEL_INFO);
  11. // report parasite power requirements
  12. //Serial.print("Parasite power is: ");
  13. //if (oneWireSensors.isParasitePowerMode()) Serial.println("ON");
  14. //else Serial.println("OFF");
  15. // Search for devices on the bus and assign based on an index. Ideally,
  16. // you would do this to initially discover addresses on the bus and then
  17. // use those addresses and manually assign them (see above) once you know
  18. // the devices on your bus (and assuming they don't change).
  19. //
  20. // method 1: by index
  21. //if (!oneWireSensors.getAddress(oneWireSensor0, 0)) Serial.println("Unable to find address for Device 0");
  22. //if (!oneWireSensors.getAddress(oneWireSensor1, 1)) Serial.println("Unable to find address for Device 1");
  23. //if (!oneWireSensors.getAddress(oneWireSensor2, 2)) Serial.println("Unable to find address for Device 1");
  24. for (uint8_t i=0; i < oneWireSensors.getDeviceCount(); i++) {
  25. if (!oneWireSensors.getAddress(oneWireSensors_IndexToAddress[i], i)) {
  26. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: Unable to find address for Device %d", i);
  27. sendLog(logBuf, LOGLEVEL_ERROR);
  28. //Serial.print("Unable to find address for Device");
  29. //Serial.println(i);
  30. }
  31. }
  32. // method 2: search()
  33. // search() looks for the next device. Returns 1 if a new address has been
  34. // returned. A zero might mean that the bus is shorted, there are no devices,
  35. // or you have already retrieved all of them. It might be a good idea to
  36. // check the CRC to make sure you didn't get garbage. The order is
  37. // deterministic. You will always get the same devices in the same order
  38. //
  39. // Must be called before search()
  40. //oneWire.reset_search();
  41. // assigns the first address found to insideThermometer
  42. //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
  43. // assigns the seconds address found to outsideThermometer
  44. //if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer");
  45. // show the addresses we found on the bus
  46. for (uint8_t i=0; i < oneWireSensors.getDeviceCount(); i++) {
  47. //Serial.print("Device ");
  48. //Serial.print(i);
  49. //Serial.print(" Address: ");
  50. //oneWireSensors_printAddress(oneWireSensors_IndexToAddress[i]);
  51. //Serial.println();
  52. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: Device: %d, Address: %02x%02x%02x%02x%02x%02x%02x%02x", i, oneWireSensors_IndexToAddress[i][0], oneWireSensors_IndexToAddress[i][1], oneWireSensors_IndexToAddress[i][2], oneWireSensors_IndexToAddress[i][3], oneWireSensors_IndexToAddress[i][4], oneWireSensors_IndexToAddress[i][5], oneWireSensors_IndexToAddress[i][6], oneWireSensors_IndexToAddress[i][7]);
  53. sendLog(logBuf, LOGLEVEL_INFO);
  54. }
  55. //Serial.print("Device 0 Address: ");
  56. //oneWireSensors_printAddress(oneWireSensor0);
  57. //Serial.println();
  58. //
  59. //Serial.print("Device 1 Address: ");
  60. //oneWireSensors_printAddress(oneWireSensor1);
  61. //Serial.println();
  62. //
  63. //Serial.print("Device 2 Address: ");
  64. //oneWireSensors_printAddress(oneWireSensor2);
  65. //Serial.println();
  66. // set the resolution to 9 bit per device
  67. //oneWireSensors.setResolution(oneWireSensor0, DALLAS_TEMPERATURE_PRECISION);
  68. //oneWireSensors.setResolution(oneWireSensor1, DALLAS_TEMPERATURE_PRECISION);
  69. //oneWireSensors.setResolution(oneWireSensor2, DALLAS_TEMPERATURE_PRECISION);
  70. for (uint8_t i=0; i < oneWireSensors.getDeviceCount(); i++) {
  71. oneWireSensors.setResolution(oneWireSensors_IndexToAddress[i], DALLAS_TEMPERATURE_PRECISION);
  72. }
  73. //Serial.print("Device 0 Resolution: ");
  74. //Serial.print(oneWireSensors.getResolution(oneWireSensor0), DEC);
  75. //Serial.println();
  76. //
  77. //Serial.print("Device 1 Resolution: ");
  78. //Serial.print(oneWireSensors.getResolution(oneWireSensor1), DEC);
  79. //Serial.println();
  80. //
  81. //Serial.print("Device 2 Resolution: ");
  82. //Serial.print(oneWireSensors.getResolution(oneWireSensor2), DEC);
  83. //Serial.println();
  84. }
  85. // // function to print a device address
  86. // void oneWireSensors_printAddress(DeviceAddress deviceAddress)
  87. // {
  88. // for (uint8_t i = 0; i < 8; i++)
  89. // {
  90. // // zero pad the address if necessary
  91. // if (deviceAddress[i] < 16) Serial.print("0");
  92. // Serial.print(deviceAddress[i], HEX);
  93. // }
  94. // }
  95. //
  96. // // function to print the temperature for a device
  97. // void oneWireSensors_printTemperature(DeviceAddress deviceAddress)
  98. // {
  99. // float tempC = oneWireSensors.getTempC(deviceAddress);
  100. // if (tempC == DEVICE_DISCONNECTED_C)
  101. // {
  102. // Serial.println("Error: Could not read temperature data");
  103. // return;
  104. // }
  105. // Serial.print("Temp C: ");
  106. // Serial.print(tempC);
  107. // }
  108. //
  109. // // function to print a device's resolution
  110. // void oneWireSensors_printResolution(DeviceAddress deviceAddress)
  111. // {
  112. // Serial.print("Resolution: ");
  113. // Serial.print(oneWireSensors.getResolution(deviceAddress));
  114. // Serial.println();
  115. // }
  116. // main function to print information about a device
  117. // void oneWireSensors_printData(DeviceAddress deviceAddress)
  118. // {
  119. // Serial.print("Device Address: ");
  120. // oneWireSensors_printAddress(deviceAddress);
  121. // Serial.print(" ");
  122. // oneWireSensors_printTemperature(deviceAddress);
  123. // Serial.println();
  124. // }
  125. //float owTemp_lastValue_feed, owTemp_lastValue_return, owTemp_lastValue_out;
  126. void oneWireSensors_getData()
  127. {
  128. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: reading temperatures");
  129. sendLog(logBuf, LOGLEVEL_DEBUG);
  130. oneWireSensors.requestTemperatures();
  131. // print the device information
  132. //oneWireSensors_printData(oneWireSensors_IndexToAddress[oneWireSensor_index[ONEWIRE_SENSOR_INDEX_FEED]]);
  133. //oneWireSensors_printData(oneWireSensors_IndexToAddress[oneWireSensor_index[ONEWIRE_SENSOR_INDEX_RETURN]]);
  134. //oneWireSensors_printData(oneWireSensors_IndexToAddress[oneWireSensor_index[ONEWIRE_SENSOR_INDEX_OUTSIDE]]);
  135. float tempC;
  136. // sensor feed
  137. if (oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_FEED] < oneWireSensors.getDeviceCount()) {
  138. tempC = oneWireSensors.getTempC(oneWireSensors_IndexToAddress[oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_FEED]]);
  139. if (tempC == DEVICE_DISCONNECTED_C)
  140. {
  141. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: error reading sensor 'FEED'");
  142. sendLog(logBuf, LOGLEVEL_ERROR);
  143. owTemp_feed = -127;
  144. }
  145. else {
  146. // filter value 85 as it is used as an error code by the lib
  147. // if the last measured value was >=80 and <=90 assume the value is OK
  148. bool _valueOK = false;
  149. if ((int)tempC == 85) {
  150. if (owTemp_feed >= 80 && owTemp_feed <= 90) _valueOK = true;
  151. }
  152. else _valueOK = true;
  153. if (_valueOK) {
  154. owTemp_feed = tempC;
  155. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'FEED' = %1.1f", owTemp_feed);
  156. sendLog(logBuf, LOGLEVEL_INFO);
  157. }
  158. }
  159. }
  160. else {
  161. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: WARNING - sensor 'FEED' not properly assigned");
  162. sendLog(logBuf, LOGLEVEL_WARN);
  163. }
  164. // sensor return
  165. if (oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_RETURN] < oneWireSensors.getDeviceCount()) {
  166. tempC = oneWireSensors.getTempC(oneWireSensors_IndexToAddress[oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_RETURN]]);
  167. if (tempC == DEVICE_DISCONNECTED_C)
  168. {
  169. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: error reading sensor 'RETURN'");
  170. sendLog(logBuf, LOGLEVEL_ERROR);
  171. owTemp_return = -127;
  172. }
  173. else {
  174. // filter value 85 as it is used as an error code by the lib
  175. // if the last measured value was >=80 and <=90 assume the value is OK
  176. bool _valueOK = false;
  177. if ((int)tempC == 85) {
  178. if (owTemp_feed >= 80 && owTemp_feed <= 90) _valueOK = true;
  179. }
  180. else _valueOK = true;
  181. if (_valueOK) {
  182. owTemp_return = tempC;
  183. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'RETURN' = %1.1f", owTemp_return);
  184. sendLog(logBuf, LOGLEVEL_INFO);
  185. }
  186. }
  187. }
  188. else {
  189. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: WARNING - sensor 'RETURN' not properly assigned");
  190. sendLog(logBuf, LOGLEVEL_WARN);
  191. }
  192. // sensor out
  193. if (oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_OUT] < oneWireSensors.getDeviceCount()) {
  194. tempC = oneWireSensors.getTempC(oneWireSensors_IndexToAddress[oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_OUT]]);
  195. if (tempC == DEVICE_DISCONNECTED_C)
  196. {
  197. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: error reading sensor 'OUT'");
  198. sendLog(logBuf, LOGLEVEL_ERROR);
  199. owTemp_out = -127;
  200. }
  201. else {
  202. // filter value 85 as it is used as an error code by the lib
  203. // if the last measured value was >=80 and <=90 assume the value is OK
  204. bool _valueOK = false;
  205. if ((int)tempC == 85) {
  206. if (owTemp_feed >= 80 && owTemp_feed <= 90) _valueOK = true;
  207. }
  208. else _valueOK = true;
  209. if (_valueOK) {
  210. owTemp_out = tempC;
  211. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'OUT' = %1.1f", owTemp_out);
  212. sendLog(logBuf, LOGLEVEL_INFO);
  213. }
  214. }
  215. }
  216. else {
  217. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: WARNING - sensor 'OUT' not properly assigned");
  218. sendLog(logBuf, LOGLEVEL_WARN);
  219. }
  220. }
  221. void oneWireSensors_loadAssignments() {
  222. oneWireSensors_loadAssignments(false);
  223. }
  224. void oneWireSensors_loadAssignments(bool force) {
  225. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: load sensor assignments...");
  226. sendLog(logBuf, LOGLEVEL_INFO);
  227. if(force) {
  228. snprintf(logBuf, LOG_BUFFER_SIZE, " FORCED");
  229. sendLog(logBuf, LOGLEVEL_INFO);
  230. for (uint8_t i = 0; i < ONEWIRE_SENSORS_COUNT; i++) {
  231. oneWireSensor_assignedDevToIndex[i] = 255;
  232. }
  233. }
  234. for (uint8_t i = 0; i < ONEWIRE_SENSORS_COUNT; i++) {
  235. if(i < oneWireSensors.getDeviceCount()) {
  236. bool addrMatch = true;
  237. // check if it is Sensor "FEED"
  238. if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_FEED] == 255) {
  239. for (uint8_t i2 = 0; i2 < 8; i2++)
  240. {
  241. if(oneWireSensors_IndexToAddress[i][i2] != confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][i2]) addrMatch = false;
  242. }
  243. if(addrMatch) {
  244. //Serial.print("OneWire Sensor ");
  245. oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_FEED] = i;
  246. //oneWireSensors_printAddress(oneWireSensors_IndexToAddress[i]);
  247. //Serial.println(" is sensor 'FEED'");
  248. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'FEED': index=%d, address=%02x%02x%02x%02x%02x%02x%02x%02x", i, confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][0], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][1], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][2], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][3], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][4], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][5], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][6], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][7]);
  249. sendLog(logBuf, LOGLEVEL_INFO);
  250. }
  251. }
  252. // check if it is Sensor "RETURN"
  253. if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_RETURN] == 255) {
  254. addrMatch = true;
  255. for (uint8_t i2 = 0; i2 < 8; i2++)
  256. {
  257. if(oneWireSensors_IndexToAddress[i][i2] != confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][i2]) addrMatch = false;
  258. }
  259. if(addrMatch) {
  260. //Serial.print("OneWire Sensor ");
  261. oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_RETURN] = i;
  262. //oneWireSensors_printAddress(oneWireSensors_IndexToAddress[i]);
  263. //Serial.println(" is sensor 'RETURN'");
  264. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'RETURN': index=%d, address=%02x%02x%02x%02x%02x%02x%02x%02x", i, confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][0], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][1], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][2], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][3], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][4], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][5], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][6], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][7]);
  265. sendLog(logBuf, LOGLEVEL_INFO);
  266. }
  267. }
  268. // check if it is Sensor "OUT"
  269. if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_OUT] == 255) {
  270. addrMatch = true;
  271. for (uint8_t i2 = 0; i2 < 8; i2++)
  272. {
  273. if(oneWireSensors_IndexToAddress[i][i2] != confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][i2]) addrMatch = false;
  274. }
  275. if(addrMatch) {
  276. oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_OUT] = i;
  277. //Serial.print("OneWire Sensor ");
  278. //oneWireSensors_printAddress(oneWireSensors_IndexToAddress[i]);
  279. //Serial.println(" is sensor 'OUT'");
  280. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'OUT': index=%d, address=%02x%02x%02x%02x%02x%02x%02x%02x", i, confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][0], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][1], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][2], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][3], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][4], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][5], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][6], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][7]);
  281. sendLog(logBuf, LOGLEVEL_INFO);
  282. }
  283. }
  284. }
  285. }
  286. // check for still unassigned configured sensors
  287. for (uint8_t i=0; i < ONEWIRE_SENSORS_COUNT; i++) {
  288. if(oneWireSensor_assignedDevToIndex[i] >= ONEWIRE_SENSORS_COUNT) {
  289. char sensName[10];
  290. if(i==0) sprintf(sensName, "FEED");
  291. else if(i==1) sprintf(sensName, "RETURN");
  292. else if(i==2) sprintf(sensName, "OUT");
  293. char sensAddr[25];
  294. sprintf(sensAddr, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", confSens.oneWireDevAddress[i][0], confSens.oneWireDevAddress[i][1], confSens.oneWireDevAddress[i][2], confSens.oneWireDevAddress[i][3], confSens.oneWireDevAddress[i][4], confSens.oneWireDevAddress[i][5], confSens.oneWireDevAddress[i][6], confSens.oneWireDevAddress[i][7]);
  295. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: WARNING - configured sensor '%s', addr='%s' not found", sensName, sensAddr);
  296. sendLog(logBuf, LOGLEVEL_WARN);
  297. }
  298. }
  299. }
  300. void oneWireSensors_show() {
  301. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20 sensors");
  302. sendLog(logBuf, LOGLEVEL_INFO);
  303. snprintf(logBuf, LOG_BUFFER_SIZE, "found:");
  304. sendLog(logBuf, LOGLEVEL_INFO);
  305. for (uint8_t i=0; i < oneWireSensors.getDeviceCount(); i++) {
  306. snprintf(logBuf, LOG_BUFFER_SIZE, " [%d]: %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", i, oneWireSensors_IndexToAddress[i][0], oneWireSensors_IndexToAddress[i][1], oneWireSensors_IndexToAddress[i][2], oneWireSensors_IndexToAddress[i][3], oneWireSensors_IndexToAddress[i][4], oneWireSensors_IndexToAddress[i][5], oneWireSensors_IndexToAddress[i][6], oneWireSensors_IndexToAddress[i][7]);
  307. sendLog(logBuf, LOGLEVEL_INFO);
  308. }
  309. snprintf(logBuf, LOG_BUFFER_SIZE, "configured:");
  310. sendLog(logBuf, LOGLEVEL_INFO);
  311. snprintf(logBuf, LOG_BUFFER_SIZE, " FEED: %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][0], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][1], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][2], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][3], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][4], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][5], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][6], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_FEED][7]);
  312. sendLog(logBuf, LOGLEVEL_INFO);
  313. if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_FEED] < oneWireSensors.getDeviceCount()) {
  314. snprintf(logBuf, LOG_BUFFER_SIZE, " assigned to device [%d]", oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_FEED]);
  315. sendLog(logBuf, LOGLEVEL_INFO);
  316. }
  317. else {
  318. snprintf(logBuf, LOG_BUFFER_SIZE, " not assigned to existing device");
  319. sendLog(logBuf, LOGLEVEL_INFO);
  320. }
  321. snprintf(logBuf, LOG_BUFFER_SIZE, " RETURN: %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][0], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][1], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][2], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][3], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][4], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][5], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][6], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_RETURN][7]);
  322. sendLog(logBuf, LOGLEVEL_INFO);
  323. if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_RETURN] < oneWireSensors.getDeviceCount()) {
  324. snprintf(logBuf, LOG_BUFFER_SIZE, " assigned to device [%d]", oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_RETURN]);
  325. sendLog(logBuf, LOGLEVEL_INFO);
  326. }
  327. else {
  328. snprintf(logBuf, LOG_BUFFER_SIZE, " not assigned to existing device");
  329. sendLog(logBuf, LOGLEVEL_INFO);
  330. }
  331. snprintf(logBuf, LOG_BUFFER_SIZE, " OUT: %02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][0], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][1], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][2], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][3], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][4], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][5], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][6], confSens.oneWireDevAddress[ONEWIRE_SENSOR_INDEX_OUT][7]);
  332. sendLog(logBuf, LOGLEVEL_INFO);
  333. if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_OUT] < oneWireSensors.getDeviceCount()) {
  334. snprintf(logBuf, LOG_BUFFER_SIZE, " assigned to device [%d]", oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_OUT]);
  335. sendLog(logBuf, LOGLEVEL_INFO);
  336. }
  337. else {
  338. snprintf(logBuf, LOG_BUFFER_SIZE, " not assigned to existing device");
  339. sendLog(logBuf, LOGLEVEL_INFO);
  340. }
  341. }
  342. bool oneWireSensor_assign(uint8_t devIndex_found, uint8_t devIndex) {
  343. // assign found sensor to saved sensor number by index
  344. // stores device address to confSens.oneWireDevAddress[devIndex]
  345. // get address of found device
  346. char sensName[10];
  347. if(devIndex==0) sprintf(sensName, "FEED");
  348. else if(devIndex==1) sprintf(sensName, "RETURN");
  349. else if(devIndex==2) sprintf(sensName, "OUT");
  350. else {
  351. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: ERROR - sensor assign got invalid target index");
  352. sendLog(logBuf, LOGLEVEL_ERROR);
  353. return false;
  354. }
  355. snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: assigning sensor [%d]=%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x --> '%s'", devIndex_found, oneWireSensors_IndexToAddress[devIndex_found][0], oneWireSensors_IndexToAddress[devIndex_found][1], oneWireSensors_IndexToAddress[devIndex_found][2], oneWireSensors_IndexToAddress[devIndex_found][3], oneWireSensors_IndexToAddress[devIndex_found][4], oneWireSensors_IndexToAddress[devIndex_found][5], oneWireSensors_IndexToAddress[devIndex_found][6], oneWireSensors_IndexToAddress[devIndex_found][7], sensName);
  356. sendLog(logBuf, LOGLEVEL_INFO);
  357. for(uint8_t i=0; i < 8; i++) {
  358. confSens.oneWireDevAddress[devIndex][i] = oneWireSensors_IndexToAddress[devIndex_found][i];
  359. }
  360. oneWireSensor_assignedDevToIndex[devIndex] = devIndex_found;
  361. return true;
  362. }
  363. #endif