ArduinoOTA with blynk

Hello! i am currently using blynk for a couple of relays some temperature and what not.But my NodeMCU board stays in the basement and in order to upload some new code i need to go to the basement with my laptop which is a pain in the ass.So i was wondering if i could implement ArduinoOTA into my code in order to upload over WiFi.
Heres my code:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define Temp_Kotel D3
#define Temp_Trapezaria D4

#define COLOR_RED    "#ff0000"
#define COLOR_YELLOW "#ffff00"
#define COLOR_GREEN  "#00ff00"
OneWire Kotel(Temp_Kotel);
OneWire Trapezaria(Temp_Trapezaria);

DallasTemperature KotelS(&Kotel);
DallasTemperature TrapezariaS(&Trapezaria);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "top secret";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "notgonnatellya";
char pass[] = "notgonnatellya";

// Select your pin with physical button
const int garageLED1 = D1;
const int garageLED2 = D2;

WidgetLED LED1(V1);
WidgetLED LED2(V2);
const int kotel = D7;
const int garage = D6;
SimpleTimer timer;

// V3 LED Widget represents the physical button state
void buttonLedWidget()
{
  // Read button
  if ((digitalRead(garageLED1) == 0) && (digitalRead(garageLED2) == 1)) {
    LED1.on();
    LED1.setColor(COLOR_RED);
  }
  if ((digitalRead(garageLED1) == 1) && (digitalRead(garageLED2) == 1)) {
    LED1.on();
    LED1.setColor(COLOR_YELLOW);
  }
  if ((digitalRead(garageLED1) == 1) && (digitalRead(garageLED2) == 0)) {
    LED1.on();
    LED1.setColor(COLOR_GREEN);
  }
  
  KotelS.requestTemperatures();
  TrapezariaS.requestTemperatures();
  float K = KotelS.getTempCByIndex(0);
  float S = TrapezariaS.getTempCByIndex(0);
  Blynk.virtualWrite(V3, K);
  Blynk.virtualWrite(V4, S);
}

void setup()
{
  pinMode(kotel, OUTPUT);
  pinMode(garage, OUTPUT);
  digitalWrite(kotel, HIGH);
  digitalWrite(garage, HIGH);
  // Debug console
  Serial.begin(9600);
  KotelS.begin();
  TrapezariaS.begin();
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  // Setup physical button pin (active low)
  pinMode(garageLED1, INPUT_PULLUP);
  pinMode(garageLED2, INPUT_PULLUP);

  timer.setInterval(500L, buttonLedWidget);
}

void loop()
{
  Blynk.run();
  timer.run();
}

(Basically i’m asking if you can do the work for me and add the ArduinoOTA)

1 Like

@levaka5459 yes your MCU can use OTA.

My car needs servicing, my trees need pruning, my lounge needs redecorating, …, my freezer is almost empty. Can you oblige?

You are more fortunate than me as your solution is on this site :slight_smile:

3 Likes

I tried and this is “my answer”:
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define Temp_Kotel D3
#define Temp_Trapezaria D4

#define COLOR_RED    "#ff0000"
#define COLOR_YELLOW "#ffff00"
#define COLOR_GREEN  "#00ff00"
OneWire Kotel(Temp_Kotel);
OneWire Trapezaria(Temp_Trapezaria);

DallasTemperature KotelS(&Kotel);
DallasTemperature TrapezariaS(&Trapezaria);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dwadaw";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "dwadwad";
char pass[] = "dwadwa";
const char* ssid1 = "dwadaw";
const char* password1 = "dwadwa";

// Select your pin with physical button
const int garageLED1 = D1;
const int garageLED2 = D2;

WidgetLED LED1(V1);
WidgetLED LED2(V2);
const int kotel = D7;
const int garage = D6;
SimpleTimer timer;

// V3 LED Widget represents the physical button state
void buttonLedWidget()
{
  // Read button
  if ((digitalRead(garageLED1) == 0) && (digitalRead(garageLED2) == 1)) {
    LED1.on();
    LED1.setColor(COLOR_RED);
  }
  if ((digitalRead(garageLED1) == 1) && (digitalRead(garageLED2) == 1)) {
    LED1.on();
    LED1.setColor(COLOR_YELLOW);
  }
  if ((digitalRead(garageLED1) == 1) && (digitalRead(garageLED2) == 0)) {
    LED1.on();
    LED1.setColor(COLOR_GREEN);
  }
  
  KotelS.requestTemperatures();
  TrapezariaS.requestTemperatures();
  float K = KotelS.getTempCByIndex(0);
  float S = TrapezariaS.getTempCByIndex(0);
  Blynk.virtualWrite(V3, K);
  Blynk.virtualWrite(V4, S);
}

void setup()
{
  pinMode(kotel, OUTPUT);
  pinMode(garage, OUTPUT);
  digitalWrite(kotel, HIGH);
  digitalWrite(garage, HIGH);
  // Debug console
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid1, password1);
    while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    delay(5000);
    ESP.restart();
  }
  ArduinoOTA.begin();
  KotelS.begin();
  TrapezariaS.begin();
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  // Setup physical button pin (active low)
  pinMode(garageLED1, INPUT_PULLUP);
  pinMode(garageLED2, INPUT_PULLUP);

  timer.setInterval(500L, buttonLedWidget);
}

void loop()
{
  ArduinoOTA.handle();
  Blynk.run();
  timer.run();
}

But nor Blynk nor uploading over OTA works.

At least you have a basement :wink:

This might help - Remember GOOGLE is your friend.

https://github.com/esp8266/Arduino/blob/master/doc/ota_updates/readme.md