Temperature measuring problem

So I just started using these little devices which after a while are pretty cool. I don’t code much but can understand most code that is written and tweak it to what I want to do.
Currently I followed a tutorial that is using a digital sensor to measure the temperature. This is cool. I got it up and running no problems.
HOWEVER. there is 1 problem that i have discovered after using it quite a bit. I have my data posted to ubidots and it gives me incorrect data only sometimes. I post the data of the temp 1 time a minute.

Here is the tutorial i followed

The problem I have is, it sometimes gives me a -127 Celsius temp sometimes which skews my entire graph and what I am trying to do.
My project is i live in a cold flat in Scotland and the landlord doesn’t want to insulate it nor can he if he wanted to because it is a really old complex protected by the government from being changed.
So I hate getting up in the morning when its freezing in my room. I hate getting up in general; cold just makes it worse. So I took this example and it is posting the data to Ubidots then I have an alert it sends back to the particle if its under a certain temperature to turn on my heater IF its past 6AM giving it enough time to warm my room up before I get up.

Below is some sample data that I have pulled over the past hour from my device and in it you will notice the -127. Originally without the resistor I was getting a constant -127 but as soon as I added the pull up resistor it started working.

I can not find any correlation in it. I can have it update 1 time a second or 1 time an hour and it can still happen. Obviously if I post more often the -127 will show more often.

What am I doing wrong. my code is exactly as the example shown with the exception of the device ID’s
I have tried my other particle as well and same problem. Tried on a different pin same thing. Is there a bug in the code I am not seeing?
I did notice one thing if I updated every second sometimes my particle for some reason couldn’t handle it. It would crash blink red; restart and start working again.
Googling a few people had similar issues but not exactly so they didn’t really help in solving the situation
2015-10-21 23:31:18 +0100 22.0625
2015-10-21 23:30:16 +0100 22.0625
2015-10-21 23:29:15 +0100 -127
2015-10-21 23:28:13 +0100 22
2015-10-21 23:27:12 +0100 21.9375
2015-10-21 23:26:10 +0100 21.9375
2015-10-21 23:25:08 +0100 21.875
2015-10-21 23:24:07 +0100 21.875
2015-10-21 23:23:05 +0100 -127
2015-10-21 23:22:04 +0100 21.8125
2015-10-21 23:21:02 +0100 -127
2015-10-21 23:20:00 +0100 21.75
2015-10-21 23:18:59 +0100 21.75
2015-10-21 23:17:57 +0100 21.6875
2015-10-21 23:16:55 +0100 21.625
2015-10-21 23:15:53 +0100 21.6875
2015-10-21 23:14:52 +0100 21.625
2015-10-21 23:13:50 +0100 21.625
2015-10-21 23:12:48 +0100 21.625
2015-10-21 23:11:47 +0100 21.5
2015-10-21 23:10:45 +0100 21.5
2015-10-21 23:09:44 +0100 21.4375
2015-10-21 23:08:42 +0100 21.375
2015-10-21 23:07:40 +0100 21.3125
2015-10-21 23:06:39 +0100 21.3125
2015-10-21 23:05:37 +0100 21.25
2015-10-21 23:04:36 +0100 21.1875
2015-10-21 23:03:34 +0100 21.125
2015-10-21 23:02:32 +0100 21.0625
2015-10-21 23:01:31 +0100 21
2015-10-21 23:00:29 +0100 20.875
2015-10-21 22:59:28 +0100 20.8125
2015-10-21 22:58:26 +0100 20.75
2015-10-21 22:57:24 +0100 20.625
2015-10-21 22:56:23 +0100 20.5
2015-10-21 22:55:21 +0100 20.4375
2015-10-21 22:54:19 +0100 20.25
2015-10-21 22:53:17 +0100 20.0625
2015-10-21 22:52:16 +0100 19.8125
2015-10-21 22:49:02 +0100 19.0625
2015-10-21 22:48:01 +0100 18.75
2015-10-21 22:46:59 +0100 18.375
2015-10-21 22:45:55 +0100 -127
2015-10-21 22:44:53 +0100 17.6875

If the sensor is a Dallas OneWire/DS18B20 read this. May still be relevant. It is a timing issue and best answer is to check for bad temp returns and toss them. I also published a library that you can use to verify for a bad CRC which will help you verify the data before doing anything with it. Link in this thread.

1 Like

interesting i will give this a read. so me being a noob at coding from what I understand. I would include your library in my main file and call sensorobj.crccheck() and if they return false redo the sensor call?

haha I may have to have someone help me implement this but I will give it a shot

You understand it in essence. I am no old hat, I just pulled together a few other people’s work to make that lib. Look at the example app and you will see how it can be used. sensorobj is replaced by your instance of the DS18B20 lib…does that make sense? The example app in the lib will really help you understand that.