Skip to content

Commit 496a13a

Browse files
committed
more options
added OTA optional settings
1 parent fc3454a commit 496a13a

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

ESP8266-Power-Monitor.ino

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
#ifdef DEBUG
2+
#define BLYNK_PRINT Serial
3+
#endif
14
#define BLYNK_MAX_READBYTES 512
25
/****************************************************************************/
3-
#include <ArduinoOTA.h>
6+
47
#include <ESP8266WiFi.h>
58
#include <BlynkSimpleEsp8266.h>
69
#include <Wire.h>
710
#include <Adafruit_INA219.h>
811
#include <SimpleTimer.h>
912
#include "wifi_credentials.h"
1013
#include "settings.h"
14+
#ifdef OTA_UPDATES
15+
#include <ArduinoOTA.h>
16+
#endif
1117
/****************************************************************************/
1218
SimpleTimer timer;
1319
Adafruit_INA219 ina219;
@@ -237,7 +243,7 @@ void countdownResetConCallback() {
237243
energyPrevious = 0;
238244
}
239245

240-
// RESET PEAKS (short) & RESET CONSUMTION (long)
246+
// RESET PEAKS (short) & RESET CONSUMTION (long)
241247
BLYNK_WRITE(vPIN_BUTTON_RESET_MAX) {
242248
if (param.asInt()) {
243249
Blynk.virtualWrite(vPIN_VOLTAGE_PEAK, "--- V");
@@ -287,6 +293,7 @@ void stopwatchCounter() {
287293
Blynk.virtualWrite(vPIN_ENERGY_TIME, days + hours_o + hours + mins_o + mins + secs_o + secs);
288294
}
289295

296+
#ifdef FIXED_ENERGY_PRICE
290297
// This section is for setting the kWh price from your electric company.
291298
// I use a SPOT rate which means I need to update it all the time.
292299
// If you know your set price per kWh (in cents), then enter the price in settings: FIXED_ENERGY_PRICE
@@ -297,6 +304,7 @@ BLYNK_WRITE(vPIN_ENERGY_API) {
297304
energyPrice = param.asFloat();
298305
Blynk.virtualWrite(vPIN_ENERGY_PRICE, String(energyPrice, 4) + String('c') );
299306
}
307+
#endif
300308

301309
// the functions for the split-task timers.
302310
// required to keep the little ESP8266 from disconnections
@@ -317,17 +325,17 @@ void setup() {
317325
Serial.begin(115200);
318326
WiFi.mode(WIFI_STA);
319327
// CONNECT TO BLYNK
320-
#if defined(USE_LOCAL_SERVER)
328+
#ifdef USE_LOCAL_SERVER
321329
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS, SERVER);
322330
#else
323331
Blynk.begin(AUTH, WIFI_SSID, WIFI_PASS, );
324332
#endif
325333
while (Blynk.connect() == false) {}
326-
334+
#ifdef OTA_UPDATES
327335
// SETUP OVER THE AIR UPDATES
328336
ArduinoOTA.setHostname(OTA_HOSTNAME);
329337
ArduinoOTA.begin();
330-
338+
#endif
331339
// START INA219
332340
ina219.begin();
333341

@@ -348,7 +356,7 @@ void setup() {
348356
Blynk.virtualWrite(vPIN_BUTTON_AUTORANGE, 1);
349357

350358
// Check for fixed energy price and update global 'energyPrice'
351-
#if defined(FIXED_ENERGY_PRICE)
359+
#ifdef FIXED_ENERGY_PRICE
352360
// else set fixed price with configured price
353361
energyPrice = FIXED_ENERGY_PRICE;
354362
Blynk.virtualWrite(vPIN_ENERGY_PRICE, String(FIXED_ENERGY_PRICE, 4) + String('c') );
@@ -362,6 +370,8 @@ void setup() {
362370
void loop() {
363371
// the loop... dont touch or add to this!
364372
Blynk.run();
373+
#ifdef OTA_UPDATES
365374
ArduinoOTA.handle();
375+
#endif
366376
timer.run();
367377
}

settings.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/**************************************************************
2-
*
3-
* Settings
4-
*
2+
3+
Settings
4+
55
**************************************************************/
66
/*
77
Blynk Auth Code
88
*/
9-
#define AUTH "9739e5f9d95941c99ca2b96526e70d5e"
9+
#define AUTH "9739e5f9d95941c99ca2b96526e70d5e"
1010
/*
1111
Over The Air Hostname
1212
*/
13-
#define OTA_HOSTNAME "POWER-MONITOR"
13+
#define OTA_UPDATES
14+
#define OTA_HOSTNAME "POWER-MONITOR"
1415
/*
1516
Local Server Settings (uncomment to use local server)
1617
*/
@@ -19,11 +20,11 @@
1920
/*
2021
Energy Cost per kWh in cents. (comment out to use API method)
2122
*/
22-
//#define FIXED_ENERGY_PRICE 9.934
23+
//#define FIXED_ENERGY_PRICE 9.934
2324
#define ENERGY_API "http://192.168.1.2:3000/"
2425
/*
25-
Value Average Settings.
26-
Set the number of samples to take for the average values.
26+
Value Average Settings.
27+
Set the number of samples to take for the average values.
2728
Value = Seconds (default 5 seconds)
2829
*/
2930
#define AVG_DEPTH_VOLTAGE 5
@@ -32,22 +33,22 @@
3233
/*
3334
Virtual Pins - Base
3435
*/
35-
#define vPIN_VOLTAGE_REAL V1
36-
#define vPIN_VOLTAGE_AVG V2
37-
#define vPIN_VOLTAGE_PEAK V3
36+
#define vPIN_VOLTAGE_REAL V1
37+
#define vPIN_VOLTAGE_AVG V2
38+
#define vPIN_VOLTAGE_PEAK V3
3839

3940
#define vPIN_CURRENT_REAL V4
40-
#define vPIN_CURRENT_AVG V5
41+
#define vPIN_CURRENT_AVG V5
4142
#define vPIN_CURRENT_PEAK V6
4243

4344
#define vPIN_GRAPH V7
4445

4546
#define vPIN_POWER_REAL V8
46-
#define vPIN_POWER_AVG V9
47+
#define vPIN_POWER_AVG V9
4748
#define vPIN_POWER_PEAK V10
4849

4950
#define vPIN_ENERGY_USED V11
50-
#define vPIN_ENERGY_COST V12
51+
#define vPIN_ENERGY_COST V12
5152
#define vPIN_ENERGY_PRICE V13
5253
#define vPIN_ENERGY_API V14
5354
#define vPIN_ENERGY_TIME V15
@@ -56,5 +57,8 @@
5657
#define vPIN_BUTTON_HOLD V17
5758
#define vPIN_BUTTON_RESET_AVG V18
5859
#define vPIN_BUTTON_RESET_MAX V19
59-
60+
/*
61+
Debugging
62+
*/
63+
#define DEBUG
6064

0 commit comments

Comments
 (0)