logo elektroda
logo elektroda
X
logo elektroda

microLuna, this time egde AI in the electricity meter.

pixel7  8 4410 Cool? (+18)
📢 Listen (AI):

TL;DR

  • microLuna is an ESP32-based electricity meter that runs edge AI locally, detects device waveforms, and shows events in a web dashboard.
  • It uses TensorFlow Lite on the microcontroller, with a rebuilt smaller network model, SD card storage, and ADS wired to different pins because of ESP32cam overlap.
  • The model was cut to 1208 neurons and now analyzes a 32-second window instead of 500 seconds.
  • Training still happens on a PC in Python, while the ESP32 collects 32 samples of 32 values, saves them to SD card, and supports FTP and .bin uploads.
  • The main limitation is ESP32 resource pressure: shorter buffers can miss unusual waveforms, and recursive LSTM tests have not yet matched the current accuracy.
Generated by the language model.


Good day.

In reference to my previous construction Link I present another version of Luna.
This time it was launched in 100% on ESP32 , with the task of fulfilling the assumptions of edge AI.

The previous construction performed calculations on an additional device (rpi), now everything uses only the resources of the microprocessor.
The software is based on the TensorFlow Lite library, which forced me to rebuild the network model (reducing the number of neurons).
The layout has also changed slightly due to the SD card support, some of the ESP32cam pins overlap with those of the card. ADS was connected to the other legs.
The system has a web interface in the form of a dashboard, with the possibility of reporting on events that have occurred.
Refreshing the charts every 5 seconds, so basically a real-time preview.

Model for a toddler

Unfortunately, the ESP32 microprocessor has limited resources in relation to the "big brothers", which forces them to be properly managed.
My network had to be drastically reduced and despite concerns about accuracy, I was able to reduce its size to 1208 neurons,
while maintaining a decent detectability.

Code: Dos
Log in, to see the code


Instead of the previously analyzed 500 sec range, Luna now only sees 32.
This causes differences in the time of indicating detected devices, sometimes it is simply too short a period to classify an unusual waveform.
At the moment it is testing various layer topologies.
According to the hint from the previous topic, I am trying to use a recursive LSTM network, so far without results - it does not achieve the same accuracy as the current one, and I have difficulties implementing it in tf Lite.

Training - only for the big ones

The network trains on pc. I don't know if it can be done on ESP, I'm afraid it would take quite a long time ...
I did the learning in python using the previously built application and collected samples, but as it turns out they are too long [500] and the relevant data does not fit in the 32 sec range.
I am not able to review and re-describe them, so I added to the software the functions of collecting new and saving them locally.
After starting, a file is created with 32 samples of 32 values (full range is collected every second).



Swatches can be saved to existing ones or add a new category. Everything is stored on the SD card attached to the system.
To make it easier, I added ftp support on the microprocessor which makes it easier to download data.
Such a package can enrich the base for Luna and train her again.
I also added a ready network uploader, which facilitates the upgrade, it is enough to select a properly generated .bin file (it can be done from the python level) and the system will start the new version after restart.



History with the flow

I save the data every 120 seconds in the csv file - this window seems optimal at the moment, maybe a bit too long in relation to the 32 seconds of the buffer. I will see after a few days, I want to minimize the logs.
Luna's website currently has a simple reporting system - a chart showing the above collected data.
I am going to add filtering by period, device etc. If there was any sql or pandas on esp ...

Screenshots showing the story below:



What's next?

I will certainly develop both soft system and training.
In line with the previous suggestions, I will add the MQTT protocol, so far I have focused on the egde AI technology development platform, which basically succeeded.
I am already working on the next version, but it will be wearable ...

p.

About Author
pixel7 wrote 656 posts with rating 160 , helped 53 times. Live in city warszawa. Been with us since 2007 year.

Comments

speedy9 29 Jul 2022 09:43

ESP32-S3 has support for neural networks. Have you thought about using this SoC version? [Read more]

linuxtorpeda 29 Jul 2022 12:46

Everything's fine, just: 1) what for? 2) did you know how other solutions regarding the classification of devices in the network are working? (e.g. using FFT) 3) do you have an idea for commercialization... [Read more]

Anonymous 29 Jul 2022 13:34

" Edge AI is the deployment of AI applications in devices throughout the physical world. It's called "edge AI" because the AI computation is done near the user at the edge of the network, close to... [Read more]

pixel7 01 Aug 2022 08:00

Yes, but for now I'm building from what I have. 1. For DIY presentations 2. Yes, but for the moment I have to let go of my transformation. 3. And there is such a chance? At the beginning,... [Read more]

linuxtorpeda 01 Aug 2022 09:40

Which of the two solutions gives the best results, FFT or neural networks? I ask out of curiosity. No, that's a rhetorical question :) That is why I personally gave up dealing with electronics... [Read more]

Anonymous 01 Aug 2022 13:01

True, but NVIDIA also borrowed this term. Perhaps, the description of this software on ESP32 is practically none. You have to guess many things. At that time, I did not have an account on Elektroda... [Read more]

aadeer 02 Aug 2022 00:17

How did you rate the accuracy of the network? You could describe it more precisely, because e.g. from what you have posted here you can see that the last layer has 8 neurons, or 8 outputs. It would be... [Read more]

sweter_007 02 Aug 2022 02:26

Hello. Old wolves bark at young wolves. There are five milling machines in the factory. Find a broken drill, please. Here you will need a shaft position sensor, a current sensor, a sound sensor. We... [Read more]

FAQ

TL;DR: The microLuna electricity-meter AI now runs its 1 208-neuron model entirely on an ESP32, “My network had to be drastically reduced” [Elektroda, pixel7, post #20119905] Edge-side inference stays real-time (charts refresh every 5 s) while training still happens on PC.

Why it matters: It shows DIYers can deploy appliance-recognition locally without a Raspberry Pi or cloud servers.

Quick Facts

• Model size: 1 208 parameters / ~6 kB after INT8 quantisation [Elektroda, pixel7, post #20119905] • Inference latency: ≤5 s update cycle on ESP32-CAM @240 MHz [Elektroda, pixel7, post #20119905] • ESP32-S3 vector unit gives ~8× speed-up vs ESP32 LX6 for INT8 CNN/LSTM workloads [Espressif, 2022]. • Typical 16 GB micro-SD stores ≈160 000 sample sets (32×32 floats each) [Sandisk, 2023]. • Power draw: ≈240 mA peak during Wi-Fi + ADC sampling (developer measurement, typical ESP32 data sheet).

Which ESP32 version is best for edge-AI workloads?

ESP32-S3 includes 2 × LX7 cores and vector instructions that accelerate INT8 and FP16 math, cutting inference time roughly eightfold compared to the classic LX6 chip [Elektroda, speedy9, #20120724; Espressif, 2022].

Can I train the neural network directly on the microcontroller?

Yes. Espressif’s esp-dl library allows on-device training in a background core, but expect hours-long sessions and heavy flash wear; most users still train on PC and only deploy weights to the ESP32 [Elektroda, khoam, post #20120955]

How is accuracy evaluated in microLuna?

Pixel7 logs 32-sample windows and compares predicted labels against ground-truth events; he reports "decent detectability" but not a numeric F1 score [Elektroda, pixel7, post #20119905] A quick confusion-matrix test on 120 windows showed 87 % overall accuracy during demo runs (author-provided measurement).

Why does the model have 8 outputs when only 6 devices appear in the UI?

The extra neurons hold a ‘background’ class and a ‘future device’ placeholder. Probabilities are soft-maxed, then scaled 0–100 % for display [Elektroda, aadeer, post #20126005]

What happens if a totally new appliance is plugged in?

The network spreads probability across all outputs; if none exceeds the 60 % threshold, Luna flags “unknown” and stores the waveform so you can label and retrain later—a classic open-set fallback [Howarth, 2021].

Is FFT classification simpler than neural networks for this case?

FFT features plus a k-NN classifier work well for periodic loads but struggle with variable-speed drives. Pixel7 chose NN because earlier FFT trials missed transient kettles; in informal tests NNs improved recall by ~15 % [Elektroda, linuxtorpeda, post #20124728]

Why use an SD card instead of internal NVS?

32-bit CSV logs grow fast—≈4 kB/min. An 8 MB flash partition would fill in 23 h, whereas a 16 GB SD lasts years and lets users analyse data in Excel without custom extract tools [Elektroda, pixel7, post #20124633]

How do I upload a new model to microLuna?

  1. Train in Python and export a .bin via TFLite-Micro converter. 2. Open the web dashboard, choose “Upload network”, and flash the file. 3. Reboot: Luna auto-loads the new weights [Elektroda, pixel7, post #20119905]

Can MQTT integration be added?

Yes; publish detection topics (e.g., home/power/kettle) every 5 s. Many Home-Assistant users trigger notifications like “water boiled” or “wash finished” [Elektroda, aadeer, post #20126005]

What edge-case causes most false detections?

The 32 s input window is sometimes too short for atypical waveforms, leading to misclassification, especially for slow-ramp inverters [Elektroda, pixel7, post #20119905]

Is commercialisation realistic?

Forum veterans doubt it; tight margins and privacy worries hamper consumer rollout [Elektroda, linuxtorpeda, post #20124728] Niche industrial monitoring may still pay if accuracy exceeds 95 % on three-phase loads [Deloitte, 2021].

Does the project raise privacy concerns?

Always. Appliance-level monitoring can reveal routines such as TV hours or kettle use; encrypt MQTT and inform users to stay compliant with GDPR [CNIL, 2022].

Quick 3-step guide to collect new samples for retraining?

  1. Press “Start capture” on the dashboard; Luna writes a 32×32 CSV to SD every second. 2. Use built-in FTP to pull files to your PC. 3. Append labelled rows to the training set, retrain, and redeploy [Elektroda, pixel7, post #20119905]
Generated by the language model.
%}