Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <stdlib.h>
  4. int finder = 0;
  5. OneWire ds(2); // Connect your 1-wire device to pin 2
  6. typedef struct {
  7. DeviceAddress addr;
  8. char name[8]; //must contain number 0-9
  9. float temp;
  10. float setpoint;
  11. int state;
  12. int id; //on the db table
  13. } Sensor;
  14.  
  15. struct Node {
  16. Sensor *sensor;
  17. Node *next;
  18. };
  19. Node *list = nullptr;
  20.  
  21. Sensor sensor_list[] = {
  22. { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone0", 45.00, 44.44, 0, 0 },
  23. { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone1", 45.00, 44.44, 0, 1 },
  24. { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone2", 45.00, 44.44, 0, 2 },
  25. { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone3", 45.00, 44.44, 0, 3 },
  26. { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone4", 45.00, 44.44, 0, 4 }
  27. };
  28.  
  29. void setup(void) {
  30. Serial.begin(9600);
  31. discoverOneWireDevices();
  32. }
  33.  
  34. void discoverOneWireDevices(void) {
  35. byte i;
  36. byte present = 0;
  37. byte data[12];
  38. byte addr[8];
  39.  
  40. Serial.print("Looking for 1-Wire devices...\n\r");
  41. while (ds.search(addr)) {
  42. //essentialy what I need to do is
  43. //sensor_list[finder].addr = addr;
  44.  
  45. list = new Node{new Sensor{addr, "SensorName", NaN}, list};
  46.  
  47. finder = finder + 1;
  48. //Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
  49. for( i = 0; i < 8; i++) {
  50. Serial.print("0x");
  51. if (addr[i] < 16) {
  52. Serial.print('0');
  53. }
  54. Serial.print(addr[i], HEX);
  55. if (i < 7) {
  56. Serial.print(", ");
  57. }
  58. }
  59. if ( OneWire::crc8( addr, 7) != addr[7]) {
  60. Serial.print("CRC is not valid!\n");
  61. return;
  62. }
  63. }
  64. //Serial.print("\n\r\n\rThat's it.\r\n");
  65. ds.reset_search();
  66. return;
  67. }
  68.  
  69. void loop(void) {
  70. // nothing to see here
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement