logo elektroda
logo elektroda
X
logo elektroda

ESP8266 + 2xDS18B20: Irregular temperature readings from second sensor

crroo 4287 4
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16315833
    crroo
    Level 12  
    Hello.
    I didn't want to start a new topic.
    I am a beginner with Arduino and with ESP8266.
    On an arduino-mega with an ETH module I have built a 6xDS18b20 and a DHT21 from which the readings are sent to Thingspeak.com.
    I have Virtuino installed on my smartphone and can view 7 temp sensors and 1 humidity sensor.
    Now I wanted to do something similar on ESP8266 + 2xDS18b20 onewire on GIPO2.

    Below I paste the code I found on the web and reworked for my needs.

    Everything works ok but only the measurement from the first sensor, while from the second temperature is sent only once in a while (sometimes every 5 s sometimes every few minutes, and sometimes every 40 min, there is no rule).
    ESP8266 I am programming via Arduino IDE

    I am very much asking for help.

    Code: C / C++
    Log in, to see the code
    .

    After Coma the reading is from both sensors:

    0 Temperature: 19.44
    0 Temperature: 19.25
    WiFi Client connected
    WiFi Client connected
    0 Temperature: 19.44
    0 Temperature: 19.25
    WiFi client connected
    WiFi client connected

    Moderated By tmf:

    3.1.19. Do not post in archived topics if it is another question, especially one different from the person asking. Out of respect for the questioner, create your own topic. You may only add how to solve the problem.

    I have separated the topic into a separate thread.

    .



    ----
    Separated from topic: Temperature reading from ds18b20
    by tmf on 01 Mar 2017 19:48
  • ADVERTISEMENT
  • Helpful post
    #2 16316069
    krzbor
    Level 28  
    I cannot understand why you send these temperatures separately. Wouldn't it be better to:
    postStr += "&field1=";
    postStr += String(temp1);
    postStr += "&field2=";
    postStr += String(temp2);
    Of course, you have to pass both temperatures into the procedure.
  • ADVERTISEMENT
  • #3 16316160
    crroo
    Level 12  
    I tried to do it this way but it didn't work.
    For the ESP8266 the code is written a bit differently than the arduino, and so far I can't merge it so that I don't send temp1 and temp2 separately.
    Please help.

    P.S..
    Below I attach the code for Arduino Mega+ENC28j60+6x ds18b20+DHT21 sensor 1x temperature 1x humidity.
    Everything is working.
    Maybe it will be useful to someone.

    Code: C / C++
    Log in, to see the code
  • ADVERTISEMENT
  • Helpful post
    #4 16316235
    krzbor
    Level 28  
    I was thinking of something like this:
    void sendTeperature(float temp1, float temp2)
    {
    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(temp1);
    postStr += "&field2=";
    postStr += String(temp2);
    postStr += "&field2=";

    ....
  • #5 16316399
    crroo
    Level 12  
    Thank you for your help krzbor.
    Everything is working ok.

    I am pasting the corrected code:
    Code: C / C++
    Log in, to see the code
    .

    This is an image from Thingspeak
    ESP8266 + 2xDS18B20: Irregular temperature readings from second sensor

    What do the following lines of code do? (At the very end of it)
    sent++;
    client.stop();
ADVERTISEMENT