simple native ESP8266 Smartmeter

Measure the active time of a heater to analyze its behaviour with a ESP8266 without an additional controller.

Similar projects worth following
I modified the firmware of the ESP8266.
It now has 2 more AT Command, one to start the measurement and one to stop it.
Once the measurement has been started, the ESP8266 is waiting for a GPIO to go low (set to pullup) . The ESP8266 is connected to a relay which is on the other side connected to the oil pump of a heater. It then is measuring how long it had been down (how long the fuel pump was running). Once it is going high again the time is send to a webserver using the GET method (passing as URL). The webserver (server on the web) is saving this time. The webserver also hosts a page to visualize the data. I used the google visualisation and AJAX to connect to the DB. To analyze the dependency of of burned oil and the outside temperature, I get some weather information from

This is just one application but as (in my eyes) the main functionality had been implemented, this project easily can be used as a starting point for other data-logging apps.

This project also can be the starting point for other data-logger applications, for example measuring temperatures etc. I implemented a few functions that automatically open a connection and send data, kind of fire and forget approach. The AT-Commands are now a bit more designed to be readable by humans as this is a standalone solution (but of course it can be used in context with a µC or something) so for example if there is a typo or you called a command wrong, it will tell you what was wrong.

The conversion to a cyclic logging instead of an event based one is very simple. An external sensor or the ADC(not really accessible on the breakout I have, [Tout pin] can be used to measure the values.


Currently I am polling the pin... there are interupt available but I was not able to make them work

Safe config:
currently the config for the logger is lost after reset, need to be written to the flash

Temperature only measured on event. this will result in an average that is not really the average of the day. For me this is ok as I just want to see tendences but this can be improved.

  • 1 × ESP8266
  • 1 × 230V relay
  • 1 × webserver running PHP and mySQL

  • Added "wind"

    Thomas02/12/2015 at 20:49 0 comments

    Small update: now also the wind speed is logged and displayed as this also is a factor for high energy consumption if the windows, roof, doors etc are not good isolated. If the consumption goes up with the wind speed its an indicator that you need to improve sth.

    Other updates are planned...

  • Auto Config HACK

    Thomas11/20/2014 at 23:22 0 comments

    Since we are on HACKaday..

    A lot of people asked me about saving the config oto the device so that after you have set up the connection once, you can take it and put it wherever you need datalogging and it will automatically configure itself without the need of a initial AT-Chat.

    I haven't had the time to try more on writing flash (without causing the chip to reboot, MPU?). Therefore a workaround for those who really want to have it as a "plug in and forgett device"

View all 2 project logs

  • 1
    Step 1

    We start by setting up the database.

    First we need to create a table to store the measured values, you might want to use phpMyadmin or similar:

    CREATE TABLE `heating` (
        `moment`          DATETIME NOT NULL ,
        `duration`        DOUBLE   NOT NULL ,
        `outside_temp`    DOUBLE   NOT NULL ,
        `wind`            DOUBLE   NOT NULL
  • 2
    Step 2

    Get the content of the "www" folder of the GitHub repo. Open "new_value.php" and "ajax.php" and fill in your information wherever you find <YOUR_XXX>.
    You have to create an account at to get an APPID to be used there (for testing purposes you can remove the APP-ID part from the URL)

    My heater is consuming 3.6l of oil per hour. The time is measured in seconds, so within "ajax.php" I convert it from seconds to liters, you might want to change this parameter.

    $row['output_duration']*0.001 (the code highlighter refused to work here)

    After you have filled in your data, upload the files to your webserver.

    create a subfolder "js", download jquery-2.1.1 (or a version you prefer, just change the path) and put it in the folder, then upload "js" to the server

    You can test the system by calling:

    where "somelocation" is the city where you measure

    by visiting

    you can see the data you entered

  • 3
    Step 3

    Now we need to connect the ESP8266 to UART, I used a USB to UART converter, the only thing you need to check is that it is 3.3V! if it is 5 V on ANY pin (also TX/RX) you will kill the ESP8266!! So, no 5V Arduinos here! Connect GND and VDD TX and RX. Open a terminal and set it to 115200@8N1. There are different Versions of breakout boards around (~11 currently) Below you find a Pinout of the currently most common ESP8266 breakout. If you have another PSB, check the web for pinouts.

    There are also a few older Firmwares where it is 9600@8N1, if you bought it used it might be something different as the baudrate can be reconfigured.

    Now you need to connect CH_PD to VDD. This will activate the ESP8266. Some guys have soldered a bridge between the this pin and VDD. On the terminal you will see some... data... its actually the bootloader on another baudrate so you cant read it. The only thing you should be able to read is a "ready" at the end.

    You now can send commands (AT+Commands are on various sites on the web but as there is a lot of dynamic I dont want to post a absolute link: which are followed by a <CR><LF>. The firmware I wrote has a AT+HELP command to list all available commands.

    Does it work? Great, lets go to the next step

View all 9 instructions

Enjoy this project?



T_Boy wrote 11/02/2014 at 19:42 point
Hi Thomas,

I recently read through the esp8266 datasheet but there did not seem to be an indication of the MCU used. Please is there some reference material somewhere that gives useful information about the MCU and the SDK?

Thanks in advance.

  Are you sure? yes | no

Thomas wrote 11/02/2014 at 20:14 point
All you need to know can be found here:

There is no external CPU, its a SOC ( core is a 106micro Diamond Standard core (LX3) made by Tensilica) with some external flash:

  Are you sure? yes | no

T_Boy wrote 11/03/2014 at 00:08 point

  Are you sure? yes | no

Michael Haas wrote 10/29/2014 at 08:39 point
Very cool project. I love that you used the ESP8266 as the application controller. Cool stuff.

  Are you sure? yes | no

Thomas wrote 10/29/2014 at 12:13 point
Well, that's the spirit of that thing right?
Gruß aus Frankfurt

  Are you sure? yes | no

Michael Haas wrote 10/29/2014 at 12:23 point
Depends on your level of laziness. ;)

  Are you sure? yes | no

Thomas wrote 10/29/2014 at 12:30 point
I dont want to have different components in my basement, just a single breakout board and a relais. Thats it

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates