I managed the ESP8266 example from one of the videos to work but now I need to insert it in my main code. Since I'm not very much into coding I need some help. This is the OTA example:
#include <Arduino.h>
#include <ESP8266httpUpdate.h>
String version = "1.0.0.3";
void doUpdate();
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
WiFi.begin("xxx", "xxx");
while (WiFi.status() != WL_CONNECTED)
{
Serial.println(".");
delay(150);
}
Serial.print("Wifi IP:");
Serial.println(WiFi.localIP());
// Setup LED GPIO
pinMode(16,OUTPUT);
}
int updateCheckTimer = 0;
void loop()
{
// Lets blink
digitalWrite(16, 1);
delay(800);
digitalWrite(16, 0);
delay(800);
updateCheckTimer++;
if(updateCheckTimer > 30)
{
updateCheckTimer = 0;
doUpdate();
}
}
void doUpdate()
{
String url = "http://otadrive.com/DeviceApi/GetEsp8266Update?k=a08e3454-45cc-448f-b415-4f7a1b206619";
url += "&s=" + String(CHIPID);
url += "&v=" + version;
t_httpUpdate_return ret = ESPhttpUpdate.update(url, version);
switch (ret)
{
case HTTP_UPDATE_FAILED:
Serial.println("Update faild!");
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("No new update available");
break;
// We can't see this, because of reset chip after update OK
case HTTP_UPDATE_OK:
Serial.println("Update OK");
break;
default:
break;
}
}
This is my main code:
#define SW_VERSION " SW Ver. 3.3" // SW version will appears at innitial LCD Display
#include "stationDefines.h" // Project definitions
#include "stationCredentials.h"
/* ESP & Blynk */
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetLED PUMPs(V0); // Echo signal to Sensors Tab at Blynk App
WidgetLED PUMPa(V5); // Echo signal to Actuators Tab at Blynk App
WidgetLED LAMPs(V1); // Echo signal to Sensors Tab at Blynk App
WidgetLED LAMPa(V6); // Echo signal to Actuators Tab at Blynk App
/* TIMER */
#include "SimpleTimer.h"
SimpleTimer timer;
/* OLED */
#include <ACROBOTIC_SSD1306.h> // library for OLED: SCL ==> D1; SDA ==> D2
#include <Wire.h>
/* DHT22*/
#include "DHT.h"
DHT dht(DHTPIN, DHTTYPE);
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("ArduFarmBot 2");
Serial.println(".... Starting Setup");
Serial.println(" ");
pinMode(PUMP_PIN, OUTPUT);
pinMode(LAMP_PIN, OUTPUT);
pinMode(PUMP_ON_BUTTON, INPUT_PULLUP);
pinMode(LAMP_ON_BUTTON, INPUT_PULLUP);
pinMode(SENSORS_READ_BUTTON, INPUT_PULLUP);
pinMode(soilMoisterVcc, OUTPUT);
Blynk.begin(auth, ssid, pass);
oledStart();
dht.begin();
DS18B20.begin();
PUMPs.off();
LAMPs.off();
PUMPa.off();
LAMPa.off();
digitalWrite(PUMP_PIN, LOW);
digitalWrite(LAMP_PIN, LOW);
digitalWrite (soilMoisterVcc, LOW);
waitButtonPress (SHOW_SET_UP); // Wait for Sensor Button to be pressed
oled.clearDisplay();
startTimers();
}
void loop()
{
timer.run(); // Initiates SimpleTimer
Blynk.run();
}
/****************************************************************
* Read remote commands
****************************************************************/
BLYNK_WRITE(3) // Pump remote control
{
int i=param.asInt();
if (i==1)
{
pumpStatus = !pumpStatus;
aplyCmd();
}
}
BLYNK_WRITE(4) // Lamp remote control
{
int i=param.asInt();
if (i==1)
{
lampStatus = !lampStatus;
aplyCmd();
}
}
/****************************************************************
* Read local commands (Pump and Lamp buttons are normally "HIGH"):
****************************************************************/
void readLocalCmd()
{
boolean digiValue = debounce(PUMP_ON_BUTTON);
if (!digiValue)
{
pumpStatus = !pumpStatus;
aplyCmd();
}
digiValue = debounce(LAMP_ON_BUTTON);
if (!digiValue)
{
lampStatus = !lampStatus;
aplyCmd();
}
digiValue = debounce(SENSORS_READ_BUTTON);
if (!digiValue)
{
turnOffOLED = !turnOffOLED;
if (!turnOffOLED)
{
oled.setTextXY(0,0); oled.putString("UPDATING SENSORS");
getDhtData();
getSoilMoisterData();
getSoilTempData();
oledStart();
displayData();
}else oled.clearDisplay();
}
}
/***************************************************
* Receive Commands and act on actuators
****************************************************/
void aplyCmd()
{
if (pumpStatus == 1)
{
Blynk.notify("ArduFarmBot2: Warning ==>> Pump ON");
digitalWrite(PUMP_PIN, HIGH);
if (!turnOffOLED) displayData();
PUMPs.on();
PUMPa.on();
}
else
{
digitalWrite(PUMP_PIN, LOW);
if (!turnOffOLED) displayData();
PUMPs.off();
PUMPa.off();
}
if (lampStatus == 1)
{
Blynk.notify("ArduFarmBot2: Warning ==>> Lamp ON");
digitalWrite(LAMP_PIN, HIGH);
if (!turnOffOLED) displayData();
LAMPs.on();
LAMPa.on();
}
else
{
digitalWrite(LAMP_PIN, LOW);
if (!turnOffOLED) displayData();
LAMPs.off();
LAMPa.off();
}
}
/***************************************************
* Automatically Control the Plantation based on sensors reading
****************************************************/
void autoControlPlantation(void)
{
if (soilMoister < DRY_SOIL)
{
pumpStatus = 1;
aplyCmd();
}
if (soilMoister >= WET_SOIL)
{
pumpStatus = 0;
aplyCmd();
}
if (airTemp >= HOT_TEMP)
{
lampStatus = 1;
aplyCmd();
}
if (airTemp < COLD_TEMP)
{
lampStatus = 0;
aplyCmd();
}
}
/***************************************************
* Send data to Blynk
**************************************************/
void sendUptime()
{
Blynk.virtualWrite(10, airTemp); //virtual pin V10
Blynk.virtualWrite(11, airHum); // virtual pin V11
Blynk.virtualWrite(12, soilMoister); // virtual pin V12
Blynk.virtualWrite(13, soilTemp); //virtual pin V13
}
Hi,
I managed the ESP8266 example from one of the videos to work but now I need to insert it in my main code. Since I'm not very much into coding I need some help. This is the OTA example:
This is my main code: