Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <stdlib.h>
- int finder = 0;
- OneWire ds(2); // Connect your 1-wire device to pin 2
- typedef struct {
- DeviceAddress addr;
- char name[8]; //must contain number 0-9
- float temp;
- float setpoint;
- int state;
- int id; //on the db table
- } Sensor;
- struct Node {
- Sensor *sensor;
- Node *next;
- };
- Node *list = nullptr;
- Sensor sensor_list[] = {
- { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone0", 45.00, 44.44, 0, 0 },
- { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone1", 45.00, 44.44, 0, 1 },
- { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone2", 45.00, 44.44, 0, 2 },
- { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone3", 45.00, 44.44, 0, 3 },
- { { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, "zone4", 45.00, 44.44, 0, 4 }
- };
- void setup(void) {
- Serial.begin(9600);
- discoverOneWireDevices();
- }
- void discoverOneWireDevices(void) {
- byte i;
- byte present = 0;
- byte data[12];
- byte addr[8];
- Serial.print("Looking for 1-Wire devices...\n\r");
- while (ds.search(addr)) {
- //essentialy what I need to do is
- //sensor_list[finder].addr = addr;
- list = new Node{new Sensor{addr, "SensorName", NaN}, list};
- finder = finder + 1;
- //Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
- for( i = 0; i < 8; i++) {
- Serial.print("0x");
- if (addr[i] < 16) {
- Serial.print('0');
- }
- Serial.print(addr[i], HEX);
- if (i < 7) {
- Serial.print(", ");
- }
- }
- if ( OneWire::crc8( addr, 7) != addr[7]) {
- Serial.print("CRC is not valid!\n");
- return;
- }
- }
- //Serial.print("\n\r\n\rThat's it.\r\n");
- ds.reset_search();
- return;
- }
- void loop(void) {
- // nothing to see here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement