0

Temperature drops occasionally from 59+C to -13C or to other random values. Used sketch and info from this site: http://internetofthinking.blogspot.com/2016/02/upload-ds18b20-temperature-sensor-data.html

NodeMCU powered by phone charger 5v 1a via microUSB. Placing 4.7 kOm resistor between data wire and 3v3 didn't help me.

Does anyone know how to solve this issue? Like filtering results and pushing to server only values that do not differ by more than n*C, or something like that?

Here is the sketch

#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define myPeriodic 15 //in sec | Thingspeak pub is 15sec
#define ONE_WIRE_BUS 2  // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float prevTemp = 0;
const char* server = "api.thingspeak.com";
String apiKey ="-";
const char* MY_SSID = "-"; 
const char* MY_PWD = "-";
int sent = 0;
void setup() {
  Serial.begin(115200);
  connectWifi();
}

void loop() {
  float temp;
  //char buffer[10];
  DS18B20.requestTemperatures(); 
  temp = DS18B20.getTempCByIndex(0)+5;
  //String tempC = dtostrf(temp, 4, 1, buffer);//handled in sendTemp()
  Serial.print(String(sent)+" Temperature: ");
  Serial.println(temp);

  //if (temp != prevTemp)
  //{
  //sendTeperatureTS(temp);
  //prevTemp = temp;
  //}

  sendTeperatureTS(temp);
  int count = myPeriodic;
  while(count--)
  delay(1000);
}

void connectWifi()
{
  Serial.print("Connecting to "+*MY_SSID);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  }

  Serial.println("");
  Serial.println("Connected");
  Serial.println("");  
}//end connect

void sendTeperatureTS(float temp)
{  
   WiFiClient client;

   if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
   Serial.println("WiFi Client connected ");

   String postStr = apiKey;
   postStr += "&field1=";
   postStr += String(temp);
   postStr += "\r\n\r\n";

   client.print("POST /update HTTP/1.1\n");
   client.print("Host: api.thingspeak.com\n");
   client.print("Connection: close\n");
   client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   client.print(postStr.length());
   client.print("\n\n");
   client.print(postStr);
   delay(1000);

   }//end if
   sent++;
 client.stop();
}//end send

thingspeak

  • measure several times ... ignore max and min readings – jsotola Nov 4 at 18:41
0

Discarding (potentially) bogus readings could help as a last resort, but something's going on to cause those bogus readings. You'd be better off finding and fixing that than finding a work-around.

These are pretty stable devices and you shouldn't see more than a couple of LSB (a few 1/4 degC). I'm inclined to suggest noise pickup on the one-wire bus but the bogus samples in your photo look identical. I have a >15' parasitic one-wire bus, just a twisted pair with no shield, and a DS18b20 close to the MCU and another out at the end. I do smooth the input but no de-spiking.

Have you checked the device's Scratchpad CRC between converting and reading the temperature? How is your device hooked up (diagram)? Is it in parasitic mode?

0

Have you checked the device's Scratchpad CRC

Idk how to.

How is your device hooked up (diagram)

Device is hooked up in normal mode, right like in this pic enter image description here

DS18b20 (waterproof) is located on top of the boiler in a special pit for measuring temperatures, there are definitely no any sort of microwaves here, and the temp is not higher than 80C. I'll try today to change the power supply, just in case, and later switch the sensor into parasite mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.