OpenRemote and ESP8266

1,106 views
Skip to first unread message

Igoris Binkis

unread,
Aug 28, 2016, 1:44:02 PM8/28/16
to OpenRemote

Hi everyone.

I'm trying to get some data from my ESP8266 weather station over Wi-Fi, but I'm confused. The ESP's page looks like this:


I need to get Temperature and Humidity readings. For that I'm using HTTP sensor, but I don't really know, what expression to use. Can anyone please help me? I've done well with XML and JSON expressions on Wunderground Weather data, but this one is a bit tricky.

Thank you



Stuart Hanlon

unread,
Aug 28, 2016, 2:20:55 PM8/28/16
to OpenRemote
It might help the really clever people if you can share the page source for that web page, so that they can suggest the correct coding.


One of the developer tools in Chrome should show you the page source.


Good luck

Igoris Binkis

unread,
Aug 28, 2016, 4:22:05 PM8/28/16
to OpenRemote
Didn't really think about it, good point. Thank you

This is the code from "View Source":


<!DOCTYPE HTML>
<html>
<head></head><body><h1>ESP8266 - Temperature and Humidity</h1><h3>Temperature in Celsius:
22.92
*C</h3><h3>Temperature in Fahrenheit:
73.25
*F</h3><h3>Humidity:
51.40
%</h3><h3>
</body></html>

I've tried to set HTTP command and use XPath expression which looks (from Chrome Inspection) like 

/html/body/h3[2]

but it didn't work either.

AutoFrank

unread,
Aug 29, 2016, 8:36:50 AM8/29/16
to OpenRemote
Do you have the api structure ..
Its generslly available as a webpage ..it might even be your url above followed by /api

Stuart Hanlon

unread,
Aug 29, 2016, 9:37:32 AM8/29/16
to OpenRemote
Hi

Pieter has been in touch to suggest that it looks like your HTML has an error in it, which might be causing a problem.

Apparently, the last <h3> shouldn't be there.


He said that with the <h3> tag removed, the XPath query you created works fine on this test site :-

http://www.freeformatter.com/xpath-tester.html

I also found a page the refers to an option to export XML from your ESP8266 device, is it any use to you?

http://www.esp8266.com/viewtopic.php?f=8&t=4307

Igoris Binkis

unread,
Aug 30, 2016, 3:34:25 PM8/30/16
to OpenRemote
Hi. Thank you for your response. The original code isn't mine, it's generated by ESP8266. I'll check the second link you gave to me, maybe I'll find something useful. I've some guy been talking about getting JSON response as well, I'll get in touch with him as well. As OR works fine with JSON and XML. It suppose to work with HTML as well, but I don't know how to make it work.
Cheers

Stuart Hanlon

unread,
Aug 30, 2016, 4:05:24 PM8/30/16
to OpenRemote
Purely going on what Pieter has observed, have you got a way of editing how your device offers up the HTML?

With the aim of removing the redundant <h3> tag?


Does your ESP8266 offer a template that you could edit?

Stuart Hanlon

unread,
Aug 30, 2016, 4:08:36 PM8/30/16
to OpenRemote
Just out of curiosity...


Is this your weather station?


https://www.hackster.io/13699/autonomous-weather-station-with-esp8266-90f8b3

Igoris Binkis

unread,
Aug 31, 2016, 5:08:01 PM8/31/16
to OpenRemote
It works!!! Thank you! Thank you! Thank you!

No, that one is mine:

Message has been deleted
Message has been deleted

Igoris Binkis

unread,
Aug 31, 2016, 5:19:34 PM8/31/16
to OpenRemote
If someone is interested, later will do a little guide, how to merge ESP8266+OR.

Stuart Hanlon

unread,
Sep 1, 2016, 3:51:30 AM9/1/16
to OpenRemote
Congratulations :-)


I'd be interested to know more about your weather station.


Thanks,
Stuart

Igoris Binkis

unread,
Sep 1, 2016, 4:02:25 PM9/1/16
to OpenRemote

I don't want to create another one post, so I will reply here. Sorry for my English, it is not my mother tongue.


I started to build my smart house about 3 months ago. It's made on RaZberry+Z-Way Server+OpenRemote. Main target is to create an automated climate control system. I've started with temperature and humidity control. For that I've got ESP8266 NodeMCU+DHT22 sensor:



I will not post pictures with connection instructions, you always can find them on Internet, as well as a sketch. I've just slightly modified the code, to get readings the way I need, thanks to you by the way ;) It looks like this (and it's not finished yet):


// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>
#include "DHT.h"

// Uncomment one of the lines below for whatever DHT sensor type you're using!
//#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

// Replace with your network details
const char* ssid = "yourWiFiname";
const char* password = "WiFipassword";

// Web Server on port 80
WiFiServer server(80);

// DHT Sensor
const int DHTPin = 2;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);

// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];

// only runs once on boot
void setup() {
  // Initializing serial port for debugging purposes
  Serial.begin(115200);
  delay(10);

  dht.begin();
  
  // Connecting to WiFi network
  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");
  
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
  
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
}

// runs over and over again
void loop() {
  // Listenning for new clients
  WiFiClient client = server.available();
  
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (c == '\n' && blank_line) {
            // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
            float h = dht.readHumidity();
            // Read temperature as Celsius (the default)
            float t = dht.readTemperature();
            // Read temperature as Fahrenheit (isFahrenheit = true)
            float f = dht.readTemperature(true);
            // Check if any reads failed and exit early (to try again).
            if (isnan(h) || isnan(t) || isnan(f)) {
              Serial.println("Failed to read from DHT sensor!");
              strcpy(celsiusTemp,"Failed");
              strcpy(fahrenheitTemp, "Failed");
              strcpy(humidityTemp, "Failed");         
            }
            else{
              // Computes temperature values in Celsius + Fahrenheit and Humidity
              float hic = dht.computeHeatIndex(t, h, false);       
              dtostrf(hic, 6, 2, celsiusTemp);             
              float hif = dht.computeHeatIndex(f, h);
              dtostrf(hif, 6, 2, fahrenheitTemp);         
              dtostrf(h, 6, 2, humidityTemp);
              // You can delete the following Serial.print's, it's just for debugging purposes
              Serial.print("Humidity: ");
              Serial.print(h);
              Serial.print(" %\t Temperature: ");
              Serial.print(t);
              Serial.print(" *C ");
              Serial.print(f);
              Serial.print(" *F\t Heat index: ");
              Serial.print(hic);
              Serial.print(" *C ");
              Serial.print(hif);
              Serial.print(" *F");
              Serial.print("Humidity: ");
              Serial.print(h);
              Serial.print(" %\t Temperature: ");
              Serial.print(t);
              Serial.print(" *C ");
              Serial.print(f);
              Serial.print(" *F\t Heat index: ");
              Serial.print(hic);
              Serial.print(" *C ");
              Serial.print(hif);
              Serial.println(" *F");
            }
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // your actual web page that displays temperature and humidity
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head></head><body><h1>ESP8266 - Temperature and Humidity</h1><h3> ");
            client.println(celsiusTemp);
            client.println("</h3><h3> ");
            client.println(fahrenheitTemp);
            client.println("</h3><h3> ");
            client.println(humidityTemp);
            client.println("</h3>");
            client.println("</body></html>");     
            break;
        }
        if (c == '\n') {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r') {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    }  
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }
}   


As you can see, client.printIn lines associated with sensor data are empty, I've done it on purpose, to get digits only, without any redundant symbols, it will be easier to put them into OR later. To get XPATH we need to Inspect the webpage and select [h3] tag we are looking for. The first one is temperature in Celsius, the second - in Fahrenheit and the third one - humidity:


Then in the Designer we create New Command, Select HTTP and fill the fields as shown below:



After that we create Sensor using this command. The type is "Custom". And finally just add this sensor to you OR Designer. Mine looks like this:



Later I'will write a rule, which reads humidity value and depending on it activates dehumidifier`s Z-Wave socket. Also I'm thinking to get a descent size and look enclosure to put my weather station in.

If you have any questions do not hesitate to ask

Cheers

Stuart Hanlon

unread,
Sep 1, 2016, 4:48:34 PM9/1/16
to OpenRemote
Beautifully done :-)


I'll definitely add that project to my wish list.


I've been thinking of adding a humidity sensor to my bathroom and linking it to an extraction fan.

bart groot

unread,
Sep 21, 2016, 5:00:17 PM9/21/16
to OpenRemote
Hello, i am very interested in how you get the data from the esp8266 in to openremote sensors. I have got an esp8266 for reading the power usage from my smart meter. (All Dutch household wil have this meter by the end of 2016).
The esp publishes a similar page with current and total power usage. I would like to read out this data and use it in OR.
This is the device I am talking about http://romix.macuser.nl/software.html
Message has been deleted

Stuart Hanlon

unread,
Sep 22, 2016, 5:31:43 PM9/22/16
to OpenRemote
Hi Bart,

If you read every part of this thread you should find exactly what you're looking for.


If you run into trouble, post the source from the webpage (as detailed in this thread) and I'm sure someone will come up with something that will help.


Cheers,
Stuart

Igoris Binkis

unread,
Oct 9, 2016, 4:46:59 PM10/9/16
to OpenRemote
Hi Stuart, 
don't know did you get my PM, just will reply eventually here :) you probably will be interested in this kind of stuff. It has ESP8266 and 10A relay on board, I've got one of this, but just don't know where I can use it :))

bart groot

unread,
Nov 5, 2016, 3:15:08 PM11/5/16
to OpenRemote

Hi Stuart,

I finally got my smart energy meter and experiment with the esp8266. The smart energy meter has a P1 port, this is a serial port. The ESP8266 is connected to the serial port and converts the serial output to TCPIP. Unfortunately the ESP does not have a fancy web page. The only thing it does is sending the serial outpu to IP every 10 seconds.
I tried the TCP IP option in openremote but it only reads the data once at startup!
I used a tcpip client to test if i can receive any data and this is the data i get;

Any suggestions on how to get the data in openremote?


Bart



Op donderdag 22 september 2016 23:31:43 UTC+2 schreef Stuart Hanlon:

Stuart Hanlon

unread,
Nov 5, 2016, 4:47:55 PM11/5/16
to OpenRemote
Hi Bart


I'll confess that I haven't used the TCP/IP commands yet....


However...


There is a polling interval option at the bottom :-)


So, I suggest you just put a value in there :-)


You'll have to double check the how-to, but I think the default measurement is seconds.

I saw 'polling interval' referred to in other protocols and I think you can define the interval in milliseconds, seconds, minutes or hours.


Give it a try and let us know how you get on.


Good luck,

Stuart

bart groot

unread,
Nov 6, 2016, 9:58:17 AM11/6/16
to OpenRemote
Well, i tried the polling interval with different times but nothing is happening. The strange thing is that if i set up a tcpip connection in openremote nothing happens until i use a separate TCPIP client test utility on my laptop to see if the espis sending data, the dat is received by the test program but in openremote as well.
 Every time i start the connection on my laptop with the test software the same data is received by openremote. As soon as i stop the test software openremote stops receiving data as well.

Igoris Binkis

unread,
Nov 9, 2016, 6:20:14 AM11/9/16
to OpenRemote
Hi Bart. I'm not sure if that will help, but can you please show me your esp8266 sketch and openremote sensor settings includung command window
Reply all
Reply to author
Forward
0 new messages