Dear friends: I’m working on my project, that consist in 9 DS18B20 sensors connected to a Lolin32 board. I need to read 9 temperatures at same time.
The problem is that many times it appears the 85 value. I tried everything to avoid bad wiring connections or similar problems, but 85 is still there.
I would prefer to filter the value. I need the 85 value not to be sent to MQTT server (cayenne) but I don’t know how to do it.
I tried lines similar to
while (temp == 85.0 || temp == (-127.0))
but I can’t write it in the correct syntax. Is there any way to filter these values?
How can I do it?
Many thanks in advance
best regards
D
Can you post your current code?
Hi Adam, here is the code:
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP32.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DNSServer.h>
#include <WebServer.h>
#include <WiFiManager.h>
#include <WiFi.h> //https://github.com/esp8266/Arduino
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "xxx";
char password[] = "xxx";
char clientID[] = "xxx";
#define ONE_WIRE_BUS 22
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempSensorA = { 0x28, 0xD6, 0x81, 0x37, 0x38, 0x19, 0x01, 0x5B };
DeviceAddress tempSensorB = { 0x28, 0xCB, 0x18, 0x3B, 0x38, 0x19, 0x01, 0x1C };
DeviceAddress tempSensorC = { 0x28, 0x93, 0xF4, 0x28, 0x38, 0x19, 0x01, 0xD8 };
DeviceAddress tempSensorD = { 0x28, 0xFF, 0xB6, 0xA3, 0x01, 0x17, 0x03, 0x71 };
DeviceAddress tempSensorE = { 0x28, 0xFF, 0x91, 0x6F, 0x81, 0x14, 0x02, 0x9A };
DeviceAddress tempSensorF = { 0x28, 0xD3, 0xBC, 0x31, 0x38, 0x19, 0x01, 0xD1 };
DeviceAddress tempSensorG = { 0x28, 0xFF, 0x29, 0xC7, 0x24, 0x17, 0x03, 0x96 };
DeviceAddress tempSensorH = { 0x28, 0x2A, 0x82, 0x00, 0x38, 0x19, 0x01, 0xD4 };
DeviceAddress tempSensorI = { 0x28, 0x6D, 0xE2, 0x1D, 0x38, 0x19, 0x01, 0x90 };
#define DATA_CHANNEL1 6 //Virtual channel for publishing sensor data.
#define DATA_CHANNEL2 7 //Virtual channel for publishing sensor data.
#define DATA_CHANNEL3 8 //Virtual channel for publishing sensor data.
#define DATA_CHANNEL4 9 //Virtual channel for publishing sensor data.
#define DATA_CHANNEL5 10 //Virtual channel for publishing sensor data.
#define DATA_CHANNEL6 11 //Virtual channel for publishing sensor data.
#define DATA_CHANNEL7 12 //Virtual channel for publishing sensor data.
#define DATA_CHANNEL8 13 //Virtual channel for publishing sensor data.
#define DATA_CHANNEL9 14 //Virtual channel for publishing sensor data.
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
Serial.print("Calificador DL ver.2.2");
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//reset saved settings
//wifiManager.resetSettings();
//set custom ip for portal
//wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
//fetches ssid and pass from eeprom and tries to connect
//if it does not connect it starts an access point with the specified name
//here "ARD-TALLER-DLORENZO"
//and goes into a blocking loop awaiting configuration
wifiManager.autoConnect("ARD-TALLER-DLORENZO");
//or use this for auto generated name ESP + ChipID
//wifiManager.autoConnect();
//if you get here you have connected to the WiFi
Serial.println("connectadoooo :)");
Cayenne.begin(username, password, clientID);
// sensor_t sensor;
sensors.begin();
//set the resolution to 10 bit
//sensors.setResolution(tempSensorA, 10);
//sensors.setResolution(tempSensorB, 10);
//sensors.setResolution(tempSensorC, 10);
}
void loop() {
Cayenne.loop();
}
CAYENNE_OUT(1)
{
sensors.requestTemperatures();
Cayenne.virtualWrite(0, millis());
delay(1000);
Cayenne.celsiusWrite(DATA_CHANNEL1, sensors.getTempC(tempSensorA));
Cayenne.celsiusWrite(DATA_CHANNEL2, sensors.getTempC(tempSensorB));
Cayenne.celsiusWrite(DATA_CHANNEL3, sensors.getTempC(tempSensorC));
Cayenne.celsiusWrite(DATA_CHANNEL4, sensors.getTempC(tempSensorD));
Cayenne.celsiusWrite(DATA_CHANNEL5, sensors.getTempC(tempSensorE));
Cayenne.celsiusWrite(DATA_CHANNEL6, sensors.getTempC(tempSensorF));
Cayenne.celsiusWrite(DATA_CHANNEL7, sensors.getTempC(tempSensorG));
Cayenne.celsiusWrite(DATA_CHANNEL8, sensors.getTempC(tempSensorH));
Cayenne.celsiusWrite(DATA_CHANNEL9, sensors.getTempC(tempSensorI));
delay(2000);
}
thank you!
You can put an if statement around each of the values you are sending. Ex:
if (tempSensorA != 80 || tempSensorA != (-127.0)){
Cayenne.celsiusWrite(DATA_CHANNEL1, sensors.getTempC(tempSensorA));
}
Many thanks, Adam.
I tried that code but didn´t pass verification
calibrador_ver3.0:117:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
if (tempSensorA != 80 || tempSensorA != (-127.0)){
^
calibrador_ver3.0:117:51: error: invalid operands of types ‘DeviceAddress {aka unsigned char [8]}’ and ‘double’ to binary ‘operator!=’
if (tempSensorA != 80 || tempSensorA != (-127.0)){
Any idea?
Thanks in advance. Regards
I’m not sure if I understand the problem, but if you are having inconsistent readings with that many sensors it will help to reduce the 4.7k resistor in value. I needed a 2.2k with 5 sensors. Especially if the leads are shielded or longer.
John
I’ll try it. Many thanks for your help John
Well, tried but didn’t work. I connected a 1.2 k, 1.5k and 1.8 k ohm and the problem remains the same. Any other idea?
Since the resistor didn’t work, try the software again.
if (sensors.getTempC(tempSensorA) != 80 || sensors.getTempC(tempSensorA) != (-127.0)){
Cayenne.celsiusWrite(DATA_CHANNEL1, sensors.getTempC(tempSensorA));
}
many thanks, Adam. It seems to be working!
anche io ho avuto gli stessi problemi,cavi lunghi e anche con schermature buone se ci sono vicino strumenti che emettono armoniche , tipo inverter o roba simile, avrai sempre questi problemi, prova ad accorciare i cavi.
altro problema che riscontro spesso è l 'alimentazione. io ad arduino ne ho messe anche 12 di sonde onewire e se non lo alimento a 9v mi danno errori come stai descrivendo tu, non conosco il lolin32 ma prova come ti ho suggerito magari è l uovo di colombo