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/* ***************************************************************************/
1218SimpleTimer timer;
1319Adafruit_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)
241247BLYNK_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() {
362370void 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}
0 commit comments