# Tutorial #4: Temperature Logger - Error in Event Data published

**URL:** <https://community.particle.io/t/tutorial-4-temperature-logger-error-in-event-data-published/50192>\
**Category:** Tutorials\
**Created:** [June 5, 2019, 4:12pm UTC](https://community.particle.io/t/tutorial-4-temperature-logger-error-in-event-data-published/50192 "2019-06-05T16:12:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bndanyi](https://avatars.discourse-cdn.com/v4/letter/b/58956e/32.png) [@bndanyi](https://community.particle.io/u/bndanyi)\
**Post date:** [June 5, 2019, 4:12pm UTC](https://community.particle.io/t/tutorial-4-temperature-logger-error-in-event-data-published/50192/1 "2019-06-05T16:12:18Z")

</div>

I copied the code from the tutorial to the build, verified, and flashed it to my device (Spark Core). Here is the URL [Tutorial #4: Temperature Logger](https://docs.particle.io/tutorials/hardware-projects/maker-kit/#tutorial-4-temperature-logger)

```auto
#include <OneWire.h>

OneWire ds = OneWire(D4); // 1-wire signal on pin D4

unsigned long lastUpdate = 0;

float lastTemp;

void setup() {
  Serial.begin(9600);
  // Set up 'power' pins, comment out if not used!
  pinMode(D3, OUTPUT);
  pinMode(D5, OUTPUT);
  digitalWrite(D3, LOW);
  digitalWrite(D5, HIGH);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;

  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }

  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();

  switch (addr[0]) {
    case 0x10:
      Serial.println(" Chip = DS1820/DS18S20");
      type_s = 1;
      break;
    case 0x28:
      Serial.println(" Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println(" Chip = DS1822");
      type_s = 0;
      break;
    case 0x26:
      Serial.println(" Chip = DS2438");
      type_s = 2;
      break;
    default:
      Serial.println("Unknown device type.");
      return;
  }

  ds.reset();   
  ds.select(addr);  
  // ds.write(0x44, 1);   
  ds.write(0x44, 0);        

  delay(1000);

  present = ds.reset();
  ds.select(addr);
  ds.write(0xB8,0); // Recall Memory 0
  ds.write(0x00,0); // Recall Memory 0

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE,0); // Read Scratchpad
  if (type_s == 2) {
    ds.write(0x00,0); // The DS2438 needs a page# to read
  }

  Serial.print(" Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  int16_t raw = (data[1] << 8) | data[0];
  if (type_s == 2) raw = (data[2] << 8) | data[1];
  byte cfg = (data[4] & 0x60);

  switch (type_s) {
    case 1:
      raw = raw << 3; // 9 bit resolution default
      if (data[7] == 0x10) {
        raw = (raw & 0xFFF0) + 12 - data[6];
      }
      celsius = (float)raw * 0.0625;
      break;
    case 0:
      if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
      if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
      if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
      celsius = (float)raw * 0.0625;
      break;

    case 2:
      data[1] = (data[1] >> 3) & 0x1f;
      if (data[2] > 127) {
        celsius = (float)data[2] - ((float)data[1] * .03125);
      }else{
        celsius = (float)data[2] + ((float)data[1] * .03125);
      }
  }

  if((((celsius <= 0 && celsius > -1) && lastTemp > 5)) || celsius > 125) {
      celsius = lastTemp;
  }

  fahrenheit = celsius * 1.8 + 32.0;
  lastTemp = celsius;
  Serial.print(" Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");

  String temperature = String(fahrenheit); 
  Particle.publish("temperature", temperature, PRIVATE);
  delay(10000);
}

```

No errors on the code but the console displays {count:15++} under Events instead of temperature

 ![EventLog](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/8/1/815a00145b5425b5ce4c554604dbee3a7e2ee658.jpeg). Please help.  
Wiring on my breadboard is as per image ![temp-logger-wiring](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/f/a/fa6cff90402483c535a7dd11a31dc4ee26c81f6e.png)  
Note: I am using a 10,000 Ohms resistor not 4,700 Ohms

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [June 5, 2019, 4:35pm UTC](https://community.particle.io/t/tutorial-4-temperature-logger-error-in-event-data-published/50192/2 "2019-06-05T16:35:52Z")

</div>

These events don’t come from your device but from a different source via the cloud.

The DEVICE column tells you the source is `api` and the event name is _ **not** _ your expected `temperature` event but some `iftt-trigger-status-check` (wherever that comes from).

You should check the serial output. Maybe this gives you a hint about the reason.

When you are refering to a tutorial, can you also post the link?

BTW, you say you are using a Spark Core but the topic is tagged as Photon 😕

---

<div class="post-metadata">

**Author:** ![bndanyi](https://avatars.discourse-cdn.com/v4/letter/b/58956e/32.png) [@bndanyi](https://community.particle.io/u/bndanyi)\
**Post date:** [June 5, 2019, 5:13pm UTC](https://community.particle.io/t/tutorial-4-temperature-logger-error-in-event-data-published/50192/3 "2019-06-05T17:13:06Z")

</div>

Thank you for shading the light on the source and event name. Let me also edit the post details, its my first post 🙂

---

<div class="post-metadata">

**Author:** ![bndanyi](https://avatars.discourse-cdn.com/v4/letter/b/58956e/32.png) [@bndanyi](https://community.particle.io/u/bndanyi)\
**Post date:** [June 5, 2019, 5:36pm UTC](https://community.particle.io/t/tutorial-4-temperature-logger-error-in-event-data-published/50192/4 "2019-06-05T17:36:28Z")

</div>

How do i know what kind of chip i have?

```auto
  Serial.println();

  // we have a good address at this point
  // what kind of chip do we have?
  // we will set a type_s value for known types or just return

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println(" Chip = DS1820/DS18S20");
      type_s = 1;
      break;
    case 0x28:
      Serial.println(" Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println(" Chip = DS1822");
      type_s = 0;
      break;
    case 0x26:
      Serial.println(" Chip = DS2438");
      type_s = 2;
      break;
    default:
      Serial.println("Unknown device type.");
      return;
  }

```

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [June 5, 2019, 6:24pm UTC](https://community.particle.io/t/tutorial-4-temperature-logger-error-in-event-data-published/50192/5 "2019-06-05T18:24:04Z")

</div>

The program should tell you via the serial output.  
It first retrieves the "serial number" of the chip and by looking of the first byte of that number it determins what type it is.

That's why I said

> [@ScruffR](#):
>
> You should check the serial output.

😉
