Temperature sensor on ESP8266



  • Just finished a setup with a dallas DS18b20 sensor connected directly to an ESP8266 module, connected to Domoticz using the MySensor LAN Gateway. It actually works!

    Nice to be able to use MySensors without an Arduino Pro mini and without a NRF24L01 module. Just one single ESP. Opens up new possibilities...



  • @martinus said:

    Nice to be able to use MySensors without an Arduino Pro mini and without a NRF24L01 module. Just one single ESP. Opens up new possibilities...

    Cann you share your setup please?



  • Yes please share. I have bunch of 8266 left over from previous project


  • Mod

    @martinus said:

    It actually works!

    Great to hear man!
    Always nice to read succes stories 👍



  • I could share stuff, but it's actually not much more than a trial sketch to see if it really works.

    The whole thing started by some user "hek" on our esp8266.nu forum stating that we do not need a dedicated gateway if we want to connect a sensor to some Home Automation controller.

    This is the topic where I also posted the demo sketch. It's just a simple combination of the GatewayESP8266 sketch and the DallasTemperatureSensor sketch.
    http://www.esp8266.nu/forum/viewtopic.php?f=6&t=427#p2144

    I'm new to MySensors. I've certainly heard about it, but never used it. All my NRF modules used with the Nodo project have been replaced with ESP modules by now. I'm using the ESP Easy firmware, but it could be interesting to see if I can migrate to MySensors if it has support for ESP modules.


  • Admin

    @martinus
    Glad to hear that if worked for you.

    @Didi
    You can taken any example sketch from the dev-branch and run it on the ESP8266.

    If you want it to run as a standalone ESP8266 sensor (without any NRF/RF69 radio attached) just remove the radio define at the top (MY_RADIO_NRF24) and as a minimum add the following defines from the GaterwayESP8266.ino:

    #define MY_ESP8266_SSID "MySSID"
    #define MY_ESP8266_PASSWORD "MyVerySecretPassword"
    #include <ESP8266WiFi.h>
    

    This will assign the node a dynamic IP from your DHCP server. You can of course set it statically as well (see GaterwayESP8266.ino for detailed configuration).

    The ESP node will run the MySensors protocol as default. If you instead want the example-sketch communicate using MQTT, you can add the following defines instead:

    #define MY_GATEWAY_MQTT_CLIENT
    
    // Set this nodes subscripe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-1"
    
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    
    // Set WIFI SSID and password
    #define MY_ESP8266_SSID "MySSID"
    #define MY_ESP8266_PASSWORD "MyVerySecretPassword"
    #include <ESP8266WiFi.h>
    

    See GatewayESP8266MQTTClient.ino for more detailed configuration options.

    Just note that I haven't verified all the external support libraries on the ESP8266, so there might be examples that won't work out of the box.



  • @hek said:

    @Didi
    You can taken any example sketch from the dev-branch and run it on the ESP8266.

    Thank you hek i will try it



  • Just added another ESP node in the network. But the only way I could think of connecting to Domoticz was by adding another MySensors LAN gateway to the hardware section. Was this supposed to be used that way? I don't know if there's a limit on the number of gateways I can add to the system.

    Is this the way to go with using a bunch of ESP units working as a sensor?

    Or should I move over to MQTT? Does this work with the "Domoticz MQTT Client gateway with LAN interface"?



  • @martinus
    Hi
    I have been using esp8266 for temp/hum sensors that sends the data to a php webpage.
    I will try I later but I just reed that it seems to be possible to use same thing for Domoticz.

    http://www.domoticz.com/wiki/Domoticz_API/JSON_URL's



  • It works.

    i have now tried it with a browser.

    http://192.168.1.112:8080/json.htm?type=command&param=udevice&idx=2&nvalue=0&svalue=12

    this is what I got from the server

    {
    "status" : "OK",
    "title" : "Update Device"
    }



  • This is my code. Tested and working fine on a ESP-01, powered from PC USB.

    Question, shall I include the license text below?
    "This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation."

    License text copied from an example from MySensors.org

    /*
     * Created by Daniel Nilsson
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     * REVISION HISTORY
     * Version 1.0 - Daniel Nilsson
     * 
     * DESCRIPTION
     * This sketch provides an example how to implement a Dallas OneWire temperature sensor (DS18B20 or equal) to send data to Domoticz-server (www.domoticz.com)
     * Sleep function is disable as default
     * Temperature value will be -555 as an indication that the sensor is not working properly, value will be -555 if one of the following criteria are met; above 80; below -100; exakt 0.00
     */
    
    /* remove this line to activate
    // ***sleep function starts here***
    // you must connect a cable from pin 8 on ESP8266 IC to Reset pin otherwise sleep doesn't work
    
    extern "C" {
    #include "user_interface.h" //for sleep
    }
    
    // ***sleep function ends here***
    */ //remove this line to activate
    
    #include <ESP8266WiFi.h>
    
    const char* ssid = "SSID"; // ***your WiFi name***
    const char* password = "password"; // ***your WiFi password***
    const char* server = "123.123.123.123"; // ***IP adress for Domoticz***
    int port = 8080; // ***port for Domoticz***
    String idx = "1"; // ***id for your sensor***
    
    WiFiClient client;
    
    #include <OneWire.h> //OneWire library
    #include <DallasTemperature.h> // Dallas library
    
    #define ONE_WIRE_BUS 2 // Data wire is plugged into port 2 on the ESP
    
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    
    DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. 
    
    void setup() {
      Serial.begin(115200);
      delay(10);
      sensors.begin(); //start Dallas sensor
     
      WiFi.begin(ssid, password); // connect to WiFi
     
      Serial.println();
      Serial.println();
      Serial.print("Connecting to ");
      Serial.println(ssid);
     
      WiFi.begin(ssid, password);
     
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("WiFi connected");
     
    }
     
    void loop() {
      
      float temp;
      // call sensors.requestTemperatures() to issue a global temperature 
      // request to all devices on the bus
      Serial.print("Requesting temperatures...");
      sensors.requestTemperatures(); // Send the command to get temperatures
      Serial.println("DONE");
      
      Serial.print("Temperature for the device 1 (index 0) is: ");
      Serial.println(sensors.getTempCByIndex(0));  
      temp=sensors.getTempCByIndex(0);
     
      if (client.connect(server,port)) {
    
      client.print("GET /json.htm?type=command&param=udevice&idx="+idx+"&nvalue=0&svalue=");
        if(temp>80 || temp<-100 || temp==0.00) { // limits if sensor is broken or not connected
          client.print( "-555" ); //Bad value indication
          }
        else{
          client.print( temp );
          }
      
      client.println( " HTTP/1.1");
      client.print( "Host: " );
      client.println(server);
      client.println( "Connection: close" );
      client.println();
      client.println();
      client.stop();
    
      Serial.print("Temperature: ");
      Serial.print(temp);
      Serial.println(" degrees Celcius");
      
      }
      
      Serial.println("Waiting...");
      delay(60000); // 60 seconds
    }
    


  • Hello,

    Sorry for my question on this old post...

    On Domoticz, should you create a virtual device or something else?
    Or when the client sends the GET command, this add and update a device automatically?

    Thank you for your answer.



  • @bagou91
    Sorry for late answer.
    I don't remember but after I look at the code it seems to be that you need define what IDX your device have.

    String idx = "1"; // ***id for your sensor***
    

    So, yes, you need to create a virtual temperature and then put in the IDX in your sketch



  • @flopp thanks you.


Log in to reply
 

Suggested Topics

  • 87
  • 1
  • 7
  • 2
  • 7
  • 5

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts