Conflict WiFi with dallas temperature library for ds18b20 ???

lepass7
Posts: 3
Joined: Mon Sep 11, 2017 7:54 pm

Conflict WiFi with dallas temperature library for ds18b20 ???

Postby lepass7 » Sun Apr 15, 2018 5:50 pm

Hi guys,
I am facing a very strange problem with my esp32 module and ds18b20. Please have a look at the following code:

Code: Select all

#if DEBUG
    //TOOD: remove is just for test
    sensors.requestTemperatures();
    Serial.print("Temperature: ");
    Serial.println(sensors.getTempCByIndex(0));
    delay(1000);
  #endif
  #if DEBUG
    Serial.println("** Scan Networks **");
  #endif
    byte numSsid = WiFi.scanNetworks();
    // print the list of networks seen:
   #if DEBUG
    Serial.print("SSID List:");
    Serial.println(numSsid);
    // print the network number and name for each network found:
    for (int thisNet = 0; thisNet<numSsid; thisNet++) {
      Serial.print(thisNet);
      Serial.print(") Network: ");
      Serial.println(WiFi.SSID(thisNet));
    }
    Serial.println("Wifi ssid: " + (String)wifiSSID);
    Serial.println("Wifi pass: " + (String)wifiPASS);
  #endif  
  #if DEBUG
    //TOOD: remove is just for test
    sensors.requestTemperatures();
    Serial.print("Temperature: ");
    Serial.println(sensors.getTempCByIndex(0));
    delay(1000);
  #endif
For some reason the first temperature reading which is before scanning for wifi networks is ok (I get correct results) but after the wifi scan networks the answer from my ds18b20 is always -127. It seems that it cannot find anymore the sensor on the wire.
This is what I have already try:
1. If I remove this line byte numSsid = WiFi.scanNetworks(); the second temperature reading is ok (I get correct results).
2. Add more delay during conversion (no success)
3. Try additional methods for reading temperature from ds18b20 (as shown in the github page) (no success)
4. Try different pins for the temperature sensor (no success)

I am out of ideas. Does anyone had the same problem?

Thank you in advance.

Cellie
Posts: 37
Joined: Sat Feb 27, 2016 9:47 pm

Re: Conflict WiFi with dallas temperature library for ds18b20 ???

Postby Cellie » Mon Apr 16, 2018 12:50 pm

No idea why the network scan would interfere.

I do have some code which should run.

https://github.com/CelliesProjects/dallas-webserver

https://github.com/CelliesProjects/esp3 ... 18B20-task

And check out stickbreakers OneWire repo.
This lib solves a lot of OneWire problems, and the solutions are now part of the 'official' Arduino OneWire lib.

lepass7
Posts: 3
Joined: Mon Sep 11, 2017 7:54 pm

Re: Conflict WiFi with dallas temperature library for ds18b20 ???

Postby lepass7 » Sat Apr 21, 2018 4:32 pm

@Cellie

Thank you for your respond. Following your suggestions I was able to resolve the issue using task on a different core.

Code: Select all

  //**************************************************************
  xTaskCreatePinnedToCore(
      readOutTemp,                       /* Function to implement the task */
      "readOutTemp ",                    /* Name of the task */
      4000,                           /* Stack size in words */
      NULL,                           /* Task input parameter */
      5,                              /* Priority of the task */
      NULL,                           /* Task handle. */
      1);                             /* Core where the task should run */
  //**************************************************************
  //**************************************************************

Code: Select all

static void readOutTemp( void * pvParameters )
{
  for(;;)
  {
    //loop forever 
    if (taskFlag == 1)
    {
      String extTemp = "";
      sensors.requestTemperatures();
      extTemp = (String)sensors.getTempCByIndex(0);
  
      #if DEBUG 
        Serial.print("Temperature: ");
        Serial.println(extTemp);
      #endif
      delay(1000);
      client.publish(MQTT_PUB_TOPIC, extTemp.c_str()); 
    }
    delay(1000);
    //Serial.println("In task");
  }
}

Cellie
Posts: 37
Joined: Sat Feb 27, 2016 9:47 pm

Re: Conflict WiFi with dallas temperature library for ds18b20 ???

Postby Cellie » Tue Apr 24, 2018 6:11 pm

Glad I could help.

Who is online

Users browsing this forum: No registered users and 7 guests