# MQTT String from ESP8266 for Optical Sensor

**URL:** <https://community.openenergymonitor.org/t/mqtt-string-from-esp8266-for-optical-sensor/19948>\
**Category:** Hardware\
**Created:** [8 March 2022 16:31 UTC](https://community.openenergymonitor.org/t/mqtt-string-from-esp8266-for-optical-sensor/19948 "2022-03-08T16:31:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Robert.Wall](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/robert.wall/32/38246_2.png) [@Robert.Wall](https://community.openenergymonitor.org/u/Robert.Wall)\
**Post date:** [8 March 2022 17:34 UTC](https://community.openenergymonitor.org/t/mqtt-string-from-esp8266-for-optical-sensor/19948/2 "2022-03-08T17:34:44Z")

</div>

Welcome, James, to the OEM forum.

> [@shoei600](#):
>
> I could do this in the ESP and send the new value each time but that would seem a significant weakness in the lifetime of the system should it be rebooted and revert back to zero.

That in fact is how the emonTx handles it. But the “reset to zero” is recognised and handled correctly by the “Wh accumulator” (also the kWh accumulator) in the emonCMS Input process which you’re bypassing by sending via MQTT, I believe. In fact you’re not bypassing that when you use MQTT, it’s only emonHub that you bypass.

The very latest emonTx software _does_ store its energy values in EEPROM - not every reading every 10 s, but only when there’s a significant change in one of the values. We calculated that on the trade-off between lost energy and EEPROM life, it ended up at a projected life of 60 years.

> [@Wh accumulator lost watts](https://community.openenergymonitor.org/t/wh-accumulator-lost-watts/17368/13):
>
> @Bill.Thomson discovered, and I’ve integrated into our EProm library, EEWL. It’s a wear-levelling library for EEPROM. As I’ve got it at present - and we’re still testing - it receives the accumulated energy and pulse values from the sketch each time the data is sent to emonCMS, but it only stores them in the EEPROM when any one goes above 200 units (i.e 200 Wh or 200 pulses) from the last time the values were saved. I chose 200 as that represents a relatively insignificant value, both in terms …

---

_[View the full topic](https://community.openenergymonitor.org/t/mqtt-string-from-esp8266-for-optical-sensor/19948)._
